SelectLibraryConfigurations.cmake 4.0 KB

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