SelectLibraryConfigurations.cmake 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <[email protected]>.
  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. if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND
  38. NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND
  39. ( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) )
  40. # if the generator supports configuration types or CMAKE_BUILD_TYPE
  41. # is set, then set optimized and debug options.
  42. set( ${basename}_LIBRARY "" )
  43. foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE )
  44. list( APPEND ${basename}_LIBRARY optimized "${_libname}" )
  45. endforeach()
  46. foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG )
  47. list( APPEND ${basename}_LIBRARY debug "${_libname}" )
  48. endforeach()
  49. elseif( ${basename}_LIBRARY_RELEASE )
  50. set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
  51. elseif( ${basename}_LIBRARY_DEBUG )
  52. set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} )
  53. else()
  54. set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND")
  55. endif()
  56. set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" )
  57. if( ${basename}_LIBRARY )
  58. set( ${basename}_FOUND TRUE )
  59. endif()
  60. mark_as_advanced( ${basename}_LIBRARY_RELEASE
  61. ${basename}_LIBRARY_DEBUG
  62. )
  63. endmacro()