1
0

CMakeLists.txt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. cmake_minimum_required(VERSION 3.10)
  2. if(NOT DEFINED CMAKE_CXX_STANDARD)
  3. set(CMAKE_CXX_STANDARD 11)
  4. set(CMAKE_CXX_STANDARD_REQUIRED True)
  5. endif()
  6. function(find_external_dependency name)
  7. set(${name}_ROOT "" CACHE PATH "Root directory to find ${name}")
  8. mark_as_advanced(${name}_DIR)
  9. find_package(${name} PATHS ${${name}_ROOT} REQUIRED)
  10. endfunction()
  11. project(Consumer)
  12. find_external_dependency(MathFunctions)
  13. add_library(consumer consumer.cxx)
  14. target_link_libraries(consumer PUBLIC MathFunctions)
  15. # install the consumer library
  16. install(TARGETS consumer DESTINATION bin EXPORT ConsumerTargets)
  17. # install the configuration targets
  18. install(EXPORT ConsumerTargets
  19. FILE ConsumerTargets.cmake
  20. DESTINATION lib/cmake/Consumer
  21. )
  22. include(CMakePackageConfigHelpers)
  23. # generate the config file that is includes the exports
  24. configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
  25. "${CMAKE_CURRENT_BINARY_DIR}/ConsumerConfig.cmake"
  26. INSTALL_DESTINATION "lib/cmake/example"
  27. NO_SET_AND_CHECK_MACRO
  28. NO_CHECK_REQUIRED_COMPONENTS_MACRO
  29. )
  30. # install the configuration file
  31. install(FILES
  32. ${CMAKE_CURRENT_BINARY_DIR}/ConsumerConfig.cmake
  33. DESTINATION lib/cmake/Consumer
  34. )
  35. # generate the export targets for the build tree
  36. # needs to be after the install(TARGETS ) command
  37. export(EXPORT ConsumerTargets
  38. FILE "${CMAKE_CURRENT_BINARY_DIR}/ConsumerTargets.cmake"
  39. )