[CMake] How do I select a different lib based on the configuration of the consuming project?

Sergiu Dotenco sergiu.dotenco at gmail.com
Fri Jul 8 18:37:08 EDT 2011


Am 08.07.2011 23:57, schrieb Benjamin Lindley:
> I made a library named Zik.  I compiled it in both release and debug
> mode in Visual Studio, then installed it like this:
> 
> Zik
> |--source
> |--build
> +--distribution
>    |--include
>    +--bin
>       +--Visual Studio 10
>          |--Zik.lib      (release version)
>          +--Zik_d.lib    (debug version)
> 
> My question is, how do I edit my Find script so that it selects the
> right version of the library based on the configuration of the project
> that wants to use the library?
> 
> Here is my find script so far:
> 
> #################################################################
>   # - Find Zik
>   # Find the Zik includes and library.
>   # Once done this will define
>   #
>   #  Zik_INCLUDE_DIRS    - where to Zik include directory
>   #  Zik_LIBRARIES       - List of libraries when using Zik.
>   #  Zik_FOUND           - True if Zik found.
> 
>   FIND_PATH(Zik_INCLUDE_DIR Zik/Window.h
>       HINTS
>           C:/Users/Cold/Dev/C++/Library/Zik/distribution/include
>   )
> 
>   FIND_LIBRARY(Zik_LIBRARY
>       NAMES
>           ${Zik_NAMES}
>       HINTS
> 
> C:/Users/Cold/Dev/C++/Library/Zik/distribution/bin/${CMAKE_GENERATOR}
>       )
> 
>   SET(Zik_INCLUDE_DIRS ${Zik_INCLUDE_DIR})
>   SET(Zik_LIBRARIES ${Zik_LIBRARY})
> 
>   INCLUDE(FindPackageHandleStandardArgs)
>   FIND_PACKAGE_HANDLE_STANDARD_ARGS(Zik DEFAULT_MESSAGE
>                                     Zik_INCLUDE_DIR Zik_LIBRARY)
> 
>   MARK_AS_ADVANCED(Zik_LIBRARY Zik_INCLUDE_DIR)
> #################################################################

set(Zik_LIBRARIES optimized ${Zik_LIBRARY_RELEASE} debug
${Zik_LIBRARY_DEBUG})

where Zik_LIBRARY_RELEASE corresponds to Zik.lib and Zik_LIBRARY_DEBUG
to Zik_d.lib. See cmake --help-command target_link_libraries for more
details.


More information about the CMake mailing list