Clean up installation and inline variables

This commit is contained in:
Florian Albrechtskirchinger 2022-09-23 13:57:44 +02:00
parent 3efc881192
commit 4ece73cd76
No known key found for this signature in database
GPG Key ID: 19618CE9B2D4BE6D
5 changed files with 68 additions and 62 deletions

View File

@ -32,16 +32,16 @@ include(json_opts)
# add library targets # add library targets
############################################################################# #############################################################################
add_library(${JSON_TARGET_NAME} INTERFACE) add_library(nlohmann_json INTERFACE)
add_library(${PROJECT_NAME}::${JSON_TARGET_NAME} ALIAS ${JSON_TARGET_NAME}) add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
if (${CMAKE_VERSION} VERSION_LESS "3.8.0") if (${CMAKE_VERSION} VERSION_LESS "3.8.0")
target_compile_features(${JSON_TARGET_NAME} INTERFACE cxx_range_for) target_compile_features(nlohmann_json INTERFACE cxx_range_for)
else() else()
target_compile_features(${JSON_TARGET_NAME} INTERFACE cxx_std_11) target_compile_features(nlohmann_json INTERFACE cxx_std_11)
endif() endif()
target_compile_definitions( target_compile_definitions(
${JSON_TARGET_NAME} nlohmann_json
INTERFACE INTERFACE
$<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0> $<$<NOT:$<BOOL:${JSON_GlobalUDLs}>>:JSON_USE_GLOBAL_UDLS=0>
$<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0> $<$<NOT:$<BOOL:${JSON_ImplicitConversions}>>:JSON_USE_IMPLICIT_CONVERSIONS=0>
@ -51,21 +51,19 @@ target_compile_definitions(
) )
target_include_directories( target_include_directories(
${JSON_TARGET_NAME} nlohmann_json
${JSON_SYSTEM_INCLUDE} INTERFACE ${JSON_SYSTEM_INCLUDE} INTERFACE
$<BUILD_INTERFACE:${JSON_INCLUDE_BUILD_DIR}> $<BUILD_INTERFACE:${JSON_BUILD_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:${JSON_INSTALL_INCLUDE_DIR}>
) )
## add debug view definition file for msvc (natvis) # add Natvis debug view definition file for MSVC
if (MSVC) if (MSVC)
set(NLOHMANN_ADD_NATVIS TRUE)
set(NLOHMANN_NATVIS_FILE "nlohmann_json.natvis")
target_sources( target_sources(
${JSON_TARGET_NAME} nlohmann_json
INTERFACE INTERFACE
$<INSTALL_INTERFACE:${NLOHMANN_NATVIS_FILE}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/nlohmann_json.natvis>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${NLOHMANN_NATVIS_FILE}> $<INSTALL_INTERFACE:nlohmann_json.natvis>
) )
endif() endif()
@ -91,23 +89,23 @@ endif()
# generate pkg-config file # generate pkg-config file
configure_file( configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_json.pc"
) )
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
# generate CMake module configuration file # generate CMake module configuration file
configure_package_config_file( configure_package_config_file(
${JSON_CMAKE_CONFIG_TEMPLATE} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/nlohmann_jsonConfig.cmake.in"
${JSON_CMAKE_PROJECT_CONFIG_FILE} "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_jsonConfig.cmake"
INSTALL_DESTINATION ${JSON_CONFIG_INSTALL_DIR} INSTALL_DESTINATION "${JSON_INSTALL_CONFIG_DIR}/cmake/nlohmann_json"
NO_SET_AND_CHECK_MACRO NO_SET_AND_CHECK_MACRO
) )
# generate CMake module version file # generate CMake module version file
if(CMAKE_VERSION VERSION_EQUAL "3.14" OR CMAKE_VERSION VERSION_GREATER "3.14") if(CMAKE_VERSION VERSION_EQUAL "3.14" OR CMAKE_VERSION VERSION_GREATER "3.14")
write_basic_package_version_file( write_basic_package_version_file(
${JSON_CMAKE_VERSION_CONFIG_FILE} "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_jsonConfigVersion.cmake"
COMPATIBILITY SameMajorVersion COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT ARCH_INDEPENDENT
) )
@ -116,50 +114,64 @@ else()
# write_basic_package_version_file to ensure that it's architecture-independent # write_basic_package_version_file to ensure that it's architecture-independent
# https://github.com/nlohmann/json/issues/1697 # https://github.com/nlohmann/json/issues/1697
configure_file( configure_file(
"cmake/nlohmann_jsonConfigVersion.cmake.in" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/nlohmann_jsonConfigVersion.cmake.in"
${JSON_CMAKE_VERSION_CONFIG_FILE} "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_jsonConfigVersion.cmake"
@ONLY @ONLY
) )
endif() endif()
# generate CMake module targets file for use without installation
export(
TARGETS nlohmann_json
NAMESPACE nlohmann_json::
FILE "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_jsonTargets.cmake"
)
############################################################################# #############################################################################
# install files and targets # install files and targets
############################################################################# #############################################################################
if(JSON_Install) if(JSON_Install)
# install pkg-config file
install( install(
DIRECTORY ${JSON_INCLUDE_BUILD_DIR} FILES "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_json.pc"
DESTINATION ${JSON_INCLUDE_INSTALL_DIR} DESTINATION "${JSON_INSTALL_CONFIG_DIR}/pkgconfig"
) )
# install CMake module configuration and version files
install( install(
FILES ${JSON_CMAKE_PROJECT_CONFIG_FILE} ${JSON_CMAKE_VERSION_CONFIG_FILE} FILES "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_jsonConfig.cmake"
DESTINATION ${JSON_CONFIG_INSTALL_DIR} "${CMAKE_CURRENT_BINARY_DIR}/nlohmann_jsonConfigVersion.cmake"
DESTINATION "${JSON_INSTALL_CONFIG_DIR}/cmake/nlohmann_json"
) )
if (NLOHMANN_ADD_NATVIS)
# install targets
install(
TARGETS nlohmann_json
EXPORT nlohmann_jsonTargets
INCLUDES DESTINATION "${JSON_INSTALL_INCLUDE_DIR}"
)
# generate and install CMake module targets file(s)
install(
EXPORT nlohmann_jsonTargets
NAMESPACE nlohmann_json::
DESTINATION "${JSON_INSTALL_CONFIG_DIR}/cmake/nlohmann_json"
)
# install header files
install(
DIRECTORY "${JSON_BUILD_INCLUDE_DIR}"
DESTINATION "${JSON_INSTALL_INCLUDE_DIR}"
)
# install Natvis debug view definition file for MSVC
if (MSVC)
install( install(
FILES ${NLOHMANN_NATVIS_FILE} FILES "nlohmann_json.natvis"
DESTINATION . DESTINATION .
) )
endif() endif()
export(
TARGETS ${JSON_TARGET_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE ${JSON_CMAKE_PROJECT_TARGETS_FILE}
)
install(
TARGETS ${JSON_TARGET_NAME}
EXPORT ${JSON_TARGETS_EXPORT_NAME}
INCLUDES DESTINATION ${JSON_INCLUDE_INSTALL_DIR}
)
install(
EXPORT ${JSON_TARGETS_EXPORT_NAME}
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${JSON_CONFIG_INSTALL_DIR}
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION ${JSON_PKGCONFIG_INSTALL_DIR}
)
endif() endif()
############################################################################# #############################################################################

View File

@ -43,21 +43,15 @@ option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF
# configuration # configuration
############################################################################# #############################################################################
set(JSON_TARGET_NAME ${PROJECT_NAME}) # package configuration install base directory
set(JSON_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "") set(JSON_INSTALL_CONFIG_DIR "${CMAKE_INSTALL_DATADIR}")
set(JSON_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(JSON_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(JSON_CMAKE_CONFIG_TEMPLATE "cmake/nlohmann_jsonConfig.cmake.in")
set(JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(JSON_CMAKE_VERSION_CONFIG_FILE "${JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(JSON_CMAKE_PROJECT_CONFIG_FILE "${JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
set(JSON_CMAKE_PROJECT_TARGETS_FILE "${JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
set(JSON_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/pkgconfig")
# include directories
set(JSON_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
if (JSON_MultipleHeaders) if (JSON_MultipleHeaders)
set(JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/") set(JSON_BUILD_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include/")
else() else()
set(JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/single_include/") set(JSON_BUILD_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/single_include/")
endif() endif()
if (JSON_SystemInclude) if (JSON_SystemInclude)

View File

@ -88,5 +88,5 @@ json_feature(JSON_LegacyDiscardedValueComparison "Legacy discarded value compari
message("") message("")
json_feature(JSON_MultipleHeaders "Use the multi-header code?") json_feature(JSON_MultipleHeaders "Use the multi-header code?")
message(" Include directory: ${JSON_INCLUDE_BUILD_DIR}") message(" Include directory: ${JSON_BUILD_INCLUDE_DIR}")
json_feature(JSON_SystemInclude "Include as system headers?") json_feature(JSON_SystemInclude "Include as system headers?")

View File

@ -54,7 +54,7 @@ target_include_directories(test_main PUBLIC
thirdparty/doctest thirdparty/doctest
thirdparty/fifo_map thirdparty/fifo_map
${PROJECT_BINARY_DIR}/include) ${PROJECT_BINARY_DIR}/include)
target_link_libraries(test_main PUBLIC ${JSON_TARGET_NAME}) target_link_libraries(test_main PUBLIC nlohmann_json)
############################################################################# #############################################################################
# define test- and standard-specific build settings # define test- and standard-specific build settings

View File

@ -18,7 +18,7 @@ target_compile_options(abi_compat_common INTERFACE
target_include_directories(abi_compat_common SYSTEM INTERFACE target_include_directories(abi_compat_common SYSTEM INTERFACE
../thirdparty/doctest ../thirdparty/doctest
include) include)
target_link_libraries(abi_compat_common INTERFACE ${JSON_TARGET_NAME}) target_link_libraries(abi_compat_common INTERFACE nlohmann_json)
# shared main() # shared main()
add_library(abi_compat_main STATIC main.cpp) add_library(abi_compat_main STATIC main.cpp)