CMakeLists.txt 1.3 KB

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