CMakeGen.cmake 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. set(_selfdir_CMakeGen
  2. "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  3. if((WIN32) AND (NOT CYGWIN))
  4. set(DEF_INSTALL_CMAKE_DIR CMake)
  5. else()
  6. set(DEF_INSTALL_CMAKE_DIR usr/lib/cmake/${PROJECT_NAME})
  7. endif()
  8. set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
  9. "Installation directory for CMake files")
  10. # Make relative paths absolute (needed later on)
  11. foreach(p LIB BIN INCLUDE CMAKE)
  12. set(var INSTALL_${p}_DIR)
  13. if((DEFINED ${var}) AND (NOT IS_ABSOLUTE "${${var}}"))
  14. set(${var} "${SYSROOT}/${${var}}")
  15. endif()
  16. endforeach()
  17. # Add all targets to the build-tree export set
  18. export(TARGETS ${PROJECT_TARGETS}
  19. FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
  20. # Export the package for use from the build-tree
  21. # (this registers the build-tree with a global CMake-registry)
  22. export(PACKAGE ${PROJECT_NAME})
  23. # Create the ${PROJECT_NAME}Config.cmake and ${PROJECT_NAME}ConfigVersion files
  24. file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
  25. "${INSTALL_INCLUDE_DIR}")
  26. # ... for the build tree
  27. set(CONF_INCLUDE_DIRS "${INSTALL_INCLUDE_DIR}")
  28. configure_file(${_selfdir_CMakeGen}/Config.cmake.in
  29. "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY)
  30. # ... for the install tree
  31. string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
  32. set(CONF_INCLUDE_DIRS "\${${PROJECT_NAME_UPPER}_CMAKE_DIR}/${REL_INCLUDE_DIR}")
  33. configure_file(${_selfdir_CMakeGen}/Config.cmake.in
  34. "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" @ONLY)
  35. # ... for both
  36. configure_file(${_selfdir_CMakeGen}/ConfigVersion.cmake.in
  37. "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" @ONLY)
  38. # Install the <PROJECT_NAME>.cmake and <PROJECT_NAME>.cmake
  39. install(FILES
  40. "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
  41. "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
  42. DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
  43. # Install the export set for use with the install-tree
  44. install(EXPORT ${PROJECT_NAME}Targets DESTINATION
  45. "${INSTALL_CMAKE_DIR}" COMPONENT dev)