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.

52 lines
1.9 KiB

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