2

I'm trying to write a CMakeLists.txt file so that it generates a Visual Studio solution. I have several external libraries, and some libraries have different import libraries for Debug & Release mode.

In Visual Studio, I'd manually select each mode, and change the name of the library and the required directory. I think I need to play with target_link_libraries and set(CMAKE_BUILD_TYPE Release) but I haven't had any luck so far.

Jacob
  • 34,255
  • 14
  • 110
  • 165
  • 1
    Possible duplicate of [Linking different libraries for Debug and Release builds in Cmake on windows?](http://stackoverflow.com/questions/2209929/linking-different-libraries-for-debug-and-release-builds-in-cmake-on-windows) – Julien Guertault Nov 21 '15 at 11:39

1 Answers1

4

The target_link_libraries command supports "debug" and "optimized" keywords, which indicate that the library immediately following it is to be used only for the corresponding build configuration:

target_link_libraries(MyTarget debug externalLib_d optimized externalLib)

If the debug and release libraries reside in different directories, specify the full path, i.e.:

target_link_libraries(MyTarget debug "debug_dir/externalLib_d" optimized "release_dir/externalLib")

Also see the target_link_libraries command documentation.

sakra
  • 62,199
  • 16
  • 168
  • 151
  • Thanks! That works. But is it possible to ensure that the link directories for the Release & Debug mode are different as well? It's not mandatory, but it would be nice. – Jacob Apr 07 '11 at 20:34
  • @Jacob: I hope I understood your question correctly, see updated answer. – sakra Apr 07 '11 at 20:57