1 # select_library_configurations( basename )
3 # This macro takes a library base name as an argument, and will choose good
4 # values for basename_LIBRARY, basename_LIBRARIES, basename_LIBRARY_DEBUG, and
5 # basename_LIBRARY_RELEASE depending on what has been found and set. If only
6 # basename_LIBRARY_RELEASE is defined, basename_LIBRARY, basename_LIBRARY_DEBUG,
7 # and basename_LIBRARY_RELEASE will be set to the release value. If only
8 # basename_LIBRARY_DEBUG is defined, then basename_LIBRARY,
9 # basename_LIBRARY_DEBUG and basename_LIBRARY_RELEASE will take the debug value.
11 # If the generator supports configuration types, then basename_LIBRARY and
12 # basename_LIBRARIES will be set with debug and optimized flags specifying the
13 # library to be used for the given configuration. If no build type has been set
14 # or the generator in use does not support configuration types, then
15 # basename_LIBRARY and basename_LIBRARIES will take only the release values.
17 # This macro was adapted from the FindQt4 CMake module and is maintained by Will
18 # Dicharry <wdicharry@stellarscience.com>.
20 # Utility macro to check if one variable exists while another doesn't, and set
21 # one that doesn't exist to the one that exists.
22 macro( _set_library_name basename GOOD BAD )
23 if( ${basename}_LIBRARY_${GOOD} AND NOT ${basename}_LIBRARY_${BAD} )
24 set( ${basename}_LIBRARY_${BAD} ${${basename}_LIBRARY_${GOOD}} )
25 set( ${basename}_LIBRARY ${${basename}_LIBRARY_${GOOD}} )
26 set( ${basename}_LIBRARIES ${${basename}_LIBRARY_${GOOD}} )
27 endif( ${basename}_LIBRARY_${GOOD} AND NOT ${basename}_LIBRARY_${BAD} )
28 endmacro( _set_library_name )
30 macro( select_library_configurations basename )
31 # if only the release version was found, set the debug to be the release
33 _set_library_name( ${basename} RELEASE DEBUG )
34 # if only the debug version was found, set the release value to be the
36 _set_library_name( ${basename} DEBUG RELEASE )
37 if (${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE )
38 # if the generator supports configuration types or CMAKE_BUILD_TYPE
39 # is set, then set optimized and debug options.
40 if( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
41 set( ${basename}_LIBRARY
42 optimized ${${basename}_LIBRARY_RELEASE}
43 debug ${${basename}_LIBRARY_DEBUG} )
44 set( ${basename}_LIBRARIES
45 optimized ${${basename}_LIBRARY_RELEASE}
46 debug ${${basename}_LIBRARY_DEBUG} )
47 else( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
48 # If there are no configuration types or build type, just use
50 set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
51 set( ${basename}_LIBRARIES ${${basename}_LIBRARY_RELEASE} )
52 endif( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
53 endif( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE )
55 set( ${basename}_LIBRARY ${${basename}_LIBRARY} CACHE FILEPATH
56 "The ${basename} library" )
58 if( ${basename}_LIBRARY )
59 set( ${basename}_FOUND TRUE )
60 endif( ${basename}_LIBRARY )
62 mark_as_advanced( ${basename}_LIBRARY
63 ${basename}_LIBRARY_RELEASE
64 ${basename}_LIBRARY_DEBUG
66 endmacro( select_library_configurations )