SelectLibraryConfigurations.cmake 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #.rst:
  4. # SelectLibraryConfigurations
  5. # ---------------------------
  6. #
  7. #
  8. #
  9. # select_library_configurations( basename )
  10. #
  11. # This macro takes a library base name as an argument, and will choose
  12. # good values for basename_LIBRARY, basename_LIBRARIES,
  13. # basename_LIBRARY_DEBUG, and basename_LIBRARY_RELEASE depending on what
  14. # has been found and set. If only basename_LIBRARY_RELEASE is defined,
  15. # basename_LIBRARY will be set to the release value, and
  16. # basename_LIBRARY_DEBUG will be set to basename_LIBRARY_DEBUG-NOTFOUND.
  17. # If only basename_LIBRARY_DEBUG is defined, then basename_LIBRARY will
  18. # take the debug value, and basename_LIBRARY_RELEASE will be set to
  19. # basename_LIBRARY_RELEASE-NOTFOUND.
  20. #
  21. # If the generator supports configuration types, then basename_LIBRARY
  22. # and basename_LIBRARIES will be set with debug and optimized flags
  23. # specifying the library to be used for the given configuration. If no
  24. # build type has been set or the generator in use does not support
  25. # configuration types, then basename_LIBRARY and basename_LIBRARIES will
  26. # take only the release value, or the debug value if the release one is
  27. # not set.
  28. # This macro was adapted from the FindQt4 CMake module and is maintained by Will
  29. # Dicharry <wdicharry@stellarscience.com>.
  30. macro( select_library_configurations basename )
  31. if(NOT ${basename}_LIBRARY_RELEASE)
  32. set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.")
  33. endif()
  34. if(NOT ${basename}_LIBRARY_DEBUG)
  35. set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.")
  36. endif()
  37. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  38. if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND
  39. NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND
  40. ( _isMultiConfig OR CMAKE_BUILD_TYPE ) )
  41. # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
  42. # single-config generators, set optimized and debug libraries
  43. set( ${basename}_LIBRARY "" )
  44. foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE )
  45. list( APPEND ${basename}_LIBRARY optimized "${_libname}" )
  46. endforeach()
  47. foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG )
  48. list( APPEND ${basename}_LIBRARY debug "${_libname}" )
  49. endforeach()
  50. elseif( ${basename}_LIBRARY_RELEASE )
  51. set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
  52. elseif( ${basename}_LIBRARY_DEBUG )
  53. set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} )
  54. else()
  55. set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND")
  56. endif()
  57. set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" )
  58. if( ${basename}_LIBRARY )
  59. set( ${basename}_FOUND TRUE )
  60. endif()
  61. mark_as_advanced( ${basename}_LIBRARY_RELEASE
  62. ${basename}_LIBRARY_DEBUG
  63. )
  64. endmacro()