You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
4.1 KiB

  1. # select_library_configurations( basename )
  2. #
  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.
  10. #
  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.
  16. #=============================================================================
  17. # Copyright 2009 Will Dicharry <wdicharry@stellarscience.com>
  18. # Copyright 2005-2009 Kitware, Inc.
  19. #
  20. # Distributed under the OSI-approved BSD License (the "License");
  21. # see accompanying file Copyright.txt for details.
  22. #
  23. # This software is distributed WITHOUT ANY WARRANTY; without even the
  24. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. # See the License for more information.
  26. #=============================================================================
  27. # (To distribute this file outside of CMake, substitute the full
  28. # License text for the above reference.)
  29. # This macro was adapted from the FindQt4 CMake module and is maintained by Will
  30. # Dicharry <wdicharry@stellarscience.com>.
  31. # Utility macro to check if one variable exists while another doesn't, and set
  32. # one that doesn't exist to the one that exists.
  33. macro( _set_library_name basename GOOD BAD )
  34. if( ${basename}_LIBRARY_${GOOD} AND NOT ${basename}_LIBRARY_${BAD} )
  35. set( ${basename}_LIBRARY_${BAD} ${${basename}_LIBRARY_${GOOD}} )
  36. set( ${basename}_LIBRARY ${${basename}_LIBRARY_${GOOD}} )
  37. set( ${basename}_LIBRARIES ${${basename}_LIBRARY_${GOOD}} )
  38. endif()
  39. endmacro()
  40. macro( select_library_configurations basename )
  41. # if only the release version was found, set the debug to be the release
  42. # version.
  43. _set_library_name( ${basename} RELEASE DEBUG )
  44. # if only the debug version was found, set the release value to be the
  45. # debug value.
  46. _set_library_name( ${basename} DEBUG RELEASE )
  47. # Set a default case, which will come into effect if
  48. # -no build type is set and the generator only supports one build type
  49. # at a time (i.e. CMAKE_CONFIGURATION_TYPES is false)
  50. # -${basename}_LIBRARY_DEBUG and ${basename}_LIBRARY_RELEASE are the same
  51. # -${basename}_LIBRARY_DEBUG and ${basename}_LIBRARY_RELEASE are both empty
  52. set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} )
  53. set( ${basename}_LIBRARIES ${${basename}_LIBRARY_RELEASE} )
  54. if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND
  55. NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE )
  56. # if the generator supports configuration types or CMAKE_BUILD_TYPE
  57. # is set, then set optimized and debug options.
  58. if( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
  59. set( ${basename}_LIBRARY "" )
  60. foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE )
  61. list( APPEND ${basename}_LIBRARY optimized "${_libname}" )
  62. endforeach()
  63. foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG )
  64. list( APPEND ${basename}_LIBRARY debug "${_libname}" )
  65. endforeach()
  66. set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" )
  67. endif()
  68. endif()
  69. set( ${basename}_LIBRARY ${${basename}_LIBRARY} CACHE FILEPATH
  70. "The ${basename} library" )
  71. if( ${basename}_LIBRARY )
  72. set( ${basename}_FOUND TRUE )
  73. endif()
  74. mark_as_advanced( ${basename}_LIBRARY
  75. ${basename}_LIBRARY_RELEASE
  76. ${basename}_LIBRARY_DEBUG
  77. )
  78. endmacro()