SelectLibraryConfigurations.cmake 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. .. code-block:: cmake
  7. select_library_configurations(basename)
  8. This macro takes a library base name as an argument, and will choose
  9. good values for the variables
  10. ::
  11. basename_LIBRARY
  12. basename_LIBRARIES
  13. basename_LIBRARY_DEBUG
  14. basename_LIBRARY_RELEASE
  15. depending on what has been found and set.
  16. If only ``basename_LIBRARY_RELEASE`` is defined, ``basename_LIBRARY`` will
  17. be set to the release value, and ``basename_LIBRARY_DEBUG`` will be set
  18. to ``basename_LIBRARY_DEBUG-NOTFOUND``. If only ``basename_LIBRARY_DEBUG``
  19. is defined, then ``basename_LIBRARY`` will take the debug value, and
  20. ``basename_LIBRARY_RELEASE`` will be set to ``basename_LIBRARY_RELEASE-NOTFOUND``.
  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``
  26. will take only the release value, or the debug value if the release one
  27. is not set.
  28. #]=======================================================================]
  29. # This macro was adapted from the FindQt4 CMake module and is maintained by Will
  30. # Dicharry <wdicharry@stellarscience.com>.
  31. macro(select_library_configurations basename)
  32. if(NOT ${basename}_LIBRARY_RELEASE)
  33. set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.")
  34. endif()
  35. if(NOT ${basename}_LIBRARY_DEBUG)
  36. set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.")
  37. endif()
  38. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  39. if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND
  40. NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND
  41. ( _isMultiConfig OR CMAKE_BUILD_TYPE ) )
  42. # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
  43. # single-config generators, set optimized and debug libraries
  44. set( ${basename}_LIBRARY "" )
  45. foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE )
  46. list( APPEND ${basename}_LIBRARY optimized "${_libname}" )
  47. endforeach()
  48. foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG )
  49. list( APPEND ${basename}_LIBRARY debug "${_libname}" )
  50. endforeach()
  51. elseif( ${basename}_LIBRARY_RELEASE )
  52. set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
  53. elseif( ${basename}_LIBRARY_DEBUG )
  54. set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} )
  55. else()
  56. set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND")
  57. endif()
  58. set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" )
  59. if( ${basename}_LIBRARY )
  60. set( ${basename}_FOUND TRUE )
  61. endif()
  62. mark_as_advanced( ${basename}_LIBRARY_RELEASE
  63. ${basename}_LIBRARY_DEBUG
  64. )
  65. endmacro()