-
Notifications
You must be signed in to change notification settings - Fork 86
/
CMakeLists.txt
111 lines (91 loc) · 4.01 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
cmake_minimum_required(VERSION 3.8...3.19)
project(taocpp-json VERSION 1.0.0 LANGUAGES CXX)
set(TAOCPP_JSON_IS_MAIN_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(TAOCPP_JSON_IS_MAIN_PROJECT ON)
endif()
# installation directories
include(GNUInstallDirs)
set(TAOCPP_JSON_INSTALL_DOC_DIR "${CMAKE_INSTALL_DOCDIR}/tao/json" CACHE STRING "The installation doc directory")
set(TAOCPP_JSON_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake" CACHE STRING "The installation cmake directory")
set(TAOCPP_JSON_INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" CACHE STRING "The installation pkgconfig directory")
# define a header-only library
add_library(taocpp-json INTERFACE)
add_library(taocpp::json ALIAS taocpp-json)
target_include_directories(taocpp-json INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# require C++17
target_compile_features(taocpp-json INTERFACE cxx_std_17)
# find a suitable PEGTL
set(TAOCPP_JSON_PEGTL_MIN_VERSION 3.1.0)
find_package(pegtl ${TAOCPP_JSON_PEGTL_MIN_VERSION} QUIET CONFIG)
if(NOT pegtl_FOUND)
# if a compatible version of PEGTL is not already installed, build and install it from the submodule directory
message(STATUS "Adding PEGTL as submodule from external/PEGTL")
set(PEGTL_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE STRING "Override PEGTL include install directory")
set(PEGTL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_DATAROOTDIR}/pegtl/cmake CACHE STRING "Override PEGTL cmake install directory")
add_subdirectory(external/PEGTL)
endif()
# add pegtl as a dependency
target_link_libraries(taocpp-json INTERFACE taocpp::pegtl)
# testing
option(TAOCPP_JSON_BUILD_TESTS "Build test programs" ${TAOCPP_JSON_IS_MAIN_PROJECT})
if(TAOCPP_JSON_BUILD_TESTS)
enable_testing()
add_subdirectory(src/test/json)
endif()
# examples
option(TAOCPP_JSON_BUILD_EXAMPLES "Build example programs" ${TAOCPP_JSON_IS_MAIN_PROJECT})
if(TAOCPP_JSON_BUILD_EXAMPLES)
add_subdirectory(src/example/json)
endif()
# performance
option(TAOCPP_JSON_BUILD_PERFORMANCE "Build performance programs" ${TAOCPP_JSON_IS_MAIN_PROJECT})
if(TAOCPP_JSON_BUILD_PERFORMANCE)
add_subdirectory(src/perf/json)
endif()
option(TAOCPP_JSON_INSTALL "Generate the install target" ${TAOCPP_JSON_IS_MAIN_PROJECT})
if(TAOCPP_JSON_INSTALL)
include(CMakePackageConfigHelpers)
# Make package findable by CMake
configure_package_config_file(.cmake/taocpp-json-config.cmake.in ${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION ${TAOCPP_JSON_INSTALL_CMAKE_DIR}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
NO_SET_AND_CHECK_MACRO
)
# Make package findable by pkg-config
configure_package_config_file(.pkg-config/taocpp-json.pc.in ${PROJECT_NAME}.pc
INSTALL_DESTINATION ${TAOCPP_JSON_INSTALL_PKGCONFIG_DIR}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
NO_SET_AND_CHECK_MACRO
)
# Ignore pointer width differences since this is a header-only library
unset(CMAKE_SIZEOF_VOID_P)
# Enable version checks in find_package
write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake COMPATIBILITY SameMajorVersion)
# keep taocpp::json target compatibility
set_target_properties(taocpp-json PROPERTIES EXPORT_NAME json)
# install and export target
install(TARGETS taocpp-json EXPORT ${PROJECT_NAME}-targets)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION ${TAOCPP_JSON_INSTALL_CMAKE_DIR}
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION ${TAOCPP_JSON_INSTALL_PKGCONFIG_DIR}
)
install(EXPORT ${PROJECT_NAME}-targets
NAMESPACE taocpp::
DESTINATION ${TAOCPP_JSON_INSTALL_CMAKE_DIR}
)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES LICENSE DESTINATION ${TAOCPP_JSON_INSTALL_DOC_DIR})
export(EXPORT ${PROJECT_NAME}-targets
FILE ${taocpp-json_BINARY_DIR}/${PROJECT_NAME}-targets.cmake
NAMESPACE taocpp::
)
endif()