1- cmake_minimum_required (VERSION 3.8 ...3.19)
1+ cmake_minimum_required (VERSION 3.11 ...3.19)
22
33project (taocpp-config VERSION 1.0.0 LANGUAGES CXX)
44
@@ -24,19 +24,42 @@ target_include_directories(taocpp-config INTERFACE
2424# require C++17
2525target_compile_features (taocpp-config INTERFACE cxx_std_17)
2626
27+ option (TAOCPP_CONFIG_INSTALL "Generate the install target" ${TAOCPP_CONFIG_IS_MAIN_PROJECT} )
28+
2729# find a suitable taoJSON
2830set (TAOCPP_CONFIG_JSON_MIN_VERSION 1.0.0)
2931find_package (taocpp-json ${TAOCPP_CONFIG_JSON_MIN_VERSION} QUIET CONFIG)
3032if (NOT taocpp-json_FOUND)
31- # if a compatible version of taoJSON is not already installed, build and install it from the submodule directory
32- message (STATUS "Adding taoJSON as submodule from external/json" )
33- set (TAOCPP_JSON_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE STRING "Override taoJSON include install directory" )
34- set (TAOCPP_JSON_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_DATAROOTDIR} /json/cmake CACHE STRING "Override taoJSON cmake install directory" )
35- add_subdirectory (external/json)
33+ if (EXISTS external/json/CMakeLists.txt)
34+ # if a compatible version of taoJSON is not already installed, build and install it from the submodule directory
35+ message (STATUS "Adding taoJSON as submodule from external/json" )
36+ set (TAOCPP_JSON_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE STRING "Override taoJSON include install directory" )
37+ set (TAOCPP_JSON_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_DATAROOTDIR} /json/cmake CACHE STRING "Override taoJSON cmake install directory" )
38+ add_subdirectory (external/json)
39+ else ()
40+ include (FetchContent)
41+ FetchContent_Declare(
42+ taocpp-json
43+ GIT_REPOSITORY https://github.com/taocpp/json.git
44+ GIT_TAG master
45+ )
46+ FetchContent_MakeAvailable(taocpp-json)
47+ endif ()
48+ if (TAOCPP_CONFIG_INSTALL)
49+ # install and export target
50+ install (TARGETS taocpp-config taocpp-json EXPORT ${PROJECT_NAME} -targets)
51+ endif ()
52+ # add taoJSON as a dependency
53+ target_link_libraries (taocpp-config INTERFACE taocpp::json)
54+ else ()
55+ if (TAOCPP_CONFIG_INSTALL)
56+ # install and export target
57+ install (TARGETS taocpp-config EXPORT ${PROJECT_NAME} -targets)
58+ endif ()
59+ # add taoJSON as a dependency
60+ target_link_libraries (taocpp-config INTERFACE taocpp::taocpp-json)
3661endif ()
3762
38- # add taoJSON as a dependency
39- target_link_libraries (taocpp-config INTERFACE taocpp::json)
4063
4164# testing
4265option (TAOCPP_CONFIG_BUILD_TESTS "Build test programs" ${TAOCPP_CONFIG_IS_MAIN_PROJECT} )
@@ -51,7 +74,6 @@ if(TAOCPP_CONFIG_BUILD_EXAMPLES)
5174 add_subdirectory (src/example/config)
5275endif ()
5376
54- option (TAOCPP_CONFIG_INSTALL "Generate the install target" ${TAOCPP_CONFIG_IS_MAIN_PROJECT} )
5577if (TAOCPP_CONFIG_INSTALL)
5678 include (CMakePackageConfigHelpers)
5779
@@ -68,8 +90,6 @@ if(TAOCPP_CONFIG_INSTALL)
6890 # Enable version checks in find_package
6991 write_basic_package_version_file(${PROJECT_NAME} -config-version .cmake COMPATIBILITY SameMajorVersion)
7092
71- # install and export target
72- install (TARGETS taocpp-config taocpp-json EXPORT ${PROJECT_NAME} -targets)
7393 install (FILES
7494 ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} -config.cmake
7595 ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} -config-version .cmake
0 commit comments