Reorganize main CMake list file

This commit is contained in:
Florian Albrechtskirchinger 2022-09-22 19:52:27 +02:00
parent 67826ba648
commit 601b5913ed
No known key found for this signature in database
GPG Key ID: 19618CE9B2D4BE6D

View File

@ -1,51 +1,42 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.1)
## #############################################################################
## POLICIES # set up
## #############################################################################
# set policies
if (POLICY CMP0077) if (POLICY CMP0077)
# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory. # Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory.
cmake_policy(SET CMP0077 NEW) cmake_policy(SET CMP0077 NEW)
endif () endif ()
## # set the CMake module path
## PROJECT set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
## name and version
##
project(nlohmann_json VERSION 3.11.2 LANGUAGES CXX)
## # determine if nlohmann_json is the main project or built as a subproject (using add_subdirectory)
## JSON_MAIN_PROJECT CHECK
## determine if nlohmann_json is built as a subproject (using add_subdirectory) or if it is the main project
##
set(JSON_MAIN_PROJECT OFF) set(JSON_MAIN_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(JSON_MAIN_PROJECT ON) set(JSON_MAIN_PROJECT ON)
endif() endif()
## # set project name and version
## INCLUDE project(nlohmann_json VERSION 3.11.2 LANGUAGES CXX)
##
##
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
include(ExternalProject)
# print CMake, system, and compiler information
include(json_info) include(json_info)
## # handle options and configuration
## OPTIONS include(json_opts)
##
include (json_opts)
if (JSON_CI) # add CI targets
if(JSON_CI)
include(ci) include(ci)
endif () endif()
#############################################################################
# add library targets
#############################################################################
##
## TARGET
## create target and add include path
##
add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE) add_library(${NLOHMANN_JSON_TARGET_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME}) add_library(${PROJECT_NAME}::${NLOHMANN_JSON_TARGET_NAME} ALIAS ${NLOHMANN_JSON_TARGET_NAME})
if (${CMAKE_VERSION} VERSION_LESS "3.8.0") if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
@ -89,20 +80,20 @@ CONFIGURE_FILE(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
) )
## #############################################################################
## TESTS # add tests
## create and configure the unit test target #############################################################################
##
if (JSON_BuildTests) if (JSON_BuildTests)
include(CTest) include(CTest)
enable_testing() enable_testing()
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()
## #############################################################################
## INSTALL # install files and targets
## install header files, generate and install cmake config files for find_package() #############################################################################
##
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
# use a custom package version config file instead of # use a custom package version config file instead of
# write_basic_package_version_file to ensure that it's architecture-independent # write_basic_package_version_file to ensure that it's architecture-independent
@ -154,4 +145,8 @@ if(JSON_Install)
) )
endif() endif()
#############################################################################
# print feature summary
#############################################################################
include(json_summary) include(json_summary)