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.

54 lines
2.0 KiB

2 months ago
  1. cmake_minimum_required(VERSION 3.0)
  2. # define the project
  3. project(nlohmann_json VERSION 2.0.5 LANGUAGES CXX)
  4. enable_testing()
  5. option(BuildTests "Build the unit tests" ON)
  6. # define project variables
  7. set(JSON_TARGET_NAME ${PROJECT_NAME})
  8. set(JSON_PACKAGE_NAME ${JSON_TARGET_NAME})
  9. set(JSON_TARGETS_FILENAME "${JSON_PACKAGE_NAME}Targets.cmake")
  10. set(JSON_CONFIG_FILENAME "${JSON_PACKAGE_NAME}Config.cmake")
  11. set(JSON_CONFIGVERSION_FILENAME "${JSON_PACKAGE_NAME}ConfigVersion.cmake")
  12. set(JSON_CONFIG_DESTINATION "cmake")
  13. set(JSON_INCLUDE_DESTINATION "include/nlohmann")
  14. # create and configure the library target
  15. add_library(${JSON_TARGET_NAME} INTERFACE)
  16. target_include_directories(${JSON_TARGET_NAME} INTERFACE
  17. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
  18. $<INSTALL_INTERFACE:${JSON_INCLUDE_DESTINATION}>)
  19. # create and configure the unit test target
  20. if (BuildTests)
  21. add_subdirectory(test)
  22. endif()
  23. # generate a config and config version file for the package
  24. include(CMakePackageConfigHelpers)
  25. configure_package_config_file("cmake/config.cmake.in"
  26. "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
  27. INSTALL_DESTINATION ${JSON_CONFIG_DESTINATION})
  28. write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
  29. VERSION ${PROJECT_VERSION}
  30. COMPATIBILITY SameMajorVersion)
  31. # export the library target and store build directory in package registry
  32. export(TARGETS ${JSON_TARGET_NAME}
  33. FILE "${CMAKE_CURRENT_BINARY_DIR}/${JSON_TARGETS_FILENAME}")
  34. export(PACKAGE ${JSON_PACKAGE_NAME})
  35. # install library target and config files
  36. install(TARGETS ${JSON_TARGET_NAME}
  37. EXPORT ${JSON_PACKAGE_NAME})
  38. install(FILES "src/json.hpp"
  39. DESTINATION ${JSON_INCLUDE_DESTINATION})
  40. install(EXPORT ${JSON_PACKAGE_NAME}
  41. FILE ${JSON_TARGETS_FILENAME}
  42. DESTINATION ${JSON_CONFIG_DESTINATION})
  43. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIG_FILENAME}"
  44. "${CMAKE_CURRENT_BINARY_DIR}/${JSON_CONFIGVERSION_FILENAME}"
  45. DESTINATION ${JSON_CONFIG_DESTINATION})