Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
152 lines (134 loc) · 4.95 KB
/
Copy pathCMakeLists.txt
File metadata and controls
152 lines (134 loc) · 4.95 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
cmake_minimum_required(VERSION 3.14...4.4)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS VERSION.txt)
file(READ "${CMAKE_CURRENT_LIST_DIR}/VERSION.txt" tomlplusplus_VERSION)
string(STRIP "${tomlplusplus_VERSION}" tomlplusplus_VERSION)
project(
tomlplusplus
VERSION "${tomlplusplus_VERSION}"
DESCRIPTION "Header-only TOML config file parser and serializer for C++17"
HOMEPAGE_URL "https://marzer.github.io/tomlplusplus/"
LANGUAGES CXX
)
include(cmake/project-is-top-level.cmake)
include(cmake/variables.cmake)
include(cmake/compile-options.cmake)
# ---- Generated files ----
set(tomlplusplus_regenerate_default OFF)
if(PROJECT_IS_TOP_LEVEL AND EXISTS "${PROJECT_SOURCE_DIR}/.git" AND NOT BUILD_FUZZER)
set(tomlplusplus_regenerate_default ON)
endif()
option(
tomlplusplus_REGENERATE
"Keep toml.hpp and other derived files up to date when building from a git checkout"
${tomlplusplus_regenerate_default}
)
if(tomlplusplus_REGENERATE)
find_package(Python3 COMPONENTS Interpreter)
if(Python3_Interpreter_FOUND)
execute_process(
COMMAND "${Python3_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/tools/regenerate.py"
RESULT_VARIABLE tomlplusplus_regenerate_result
)
if(tomlplusplus_regenerate_result)
message(FATAL_ERROR "tools/regenerate.py failed: ${tomlplusplus_regenerate_result}")
endif()
file(GLOB_RECURSE tomlplusplus_regenerate_inputs "${PROJECT_SOURCE_DIR}/include/*")
set_property(
DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
${tomlplusplus_regenerate_inputs} tools/regenerate.py toml.hpp LICENSE
)
else()
message(STATUS "Python 3 not found; toml.hpp and other derived files won't be kept up to date")
endif()
endif()
# ---- Declare library ----
if(tomlplusplus_BUILD_LIB)
if(BUILD_SHARED_LIBS)
add_library(tomlplusplus_tomlplusplus SHARED src/toml.cpp)
target_compile_definitions(tomlplusplus_tomlplusplus PUBLIC TOML_SHARED_LIB=1)
set_target_properties(
tomlplusplus_tomlplusplus PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON
)
target_compile_options(
tomlplusplus_tomlplusplus PRIVATE $<$<CXX_COMPILER_ID:GNU>:-fno-semantic-interposition>
)
else()
add_library(tomlplusplus_tomlplusplus STATIC src/toml.cpp)
if(NOT MSVC)
target_compile_options(tomlplusplus_tomlplusplus PRIVATE -ffunction-sections -fdata-sections)
endif()
endif()
set_target_properties(
tomlplusplus_tomlplusplus PROPERTIES
OUTPUT_NAME tomlplusplus
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}"
POSITION_INDEPENDENT_CODE ON
)
target_compile_definitions(tomlplusplus_tomlplusplus PUBLIC TOML_HEADER_ONLY=0)
if(tomlplusplus_UNRELEASED_FEATURES)
target_compile_definitions(tomlplusplus_tomlplusplus PUBLIC TOML_ENABLE_UNRELEASED_FEATURES=1)
endif()
target_include_directories(tomlplusplus_tomlplusplus PRIVATE include)
tomlplusplus_set_compile_options(tomlplusplus_tomlplusplus)
if(tomlplusplus_PEDANTIC AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(
tomlplusplus_tomlplusplus PRIVATE
"$<$<NOT:$<CONFIG:Debug>>:-Wsuggest-attribute=const;-Wsuggest-attribute=pure>"
)
endif()
else()
add_library(tomlplusplus_tomlplusplus INTERFACE)
if(tomlplusplus_UNRELEASED_FEATURES)
target_compile_definitions(tomlplusplus_tomlplusplus INTERFACE TOML_ENABLE_UNRELEASED_FEATURES=1)
endif()
endif()
add_library(tomlplusplus::tomlplusplus ALIAS tomlplusplus_tomlplusplus)
set_property(
TARGET tomlplusplus_tomlplusplus PROPERTY
EXPORT_NAME tomlplusplus
)
target_include_directories(
tomlplusplus_tomlplusplus
${tomlplusplus_warning_guard} # unquoted for list expansion
INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
)
target_compile_features(tomlplusplus_tomlplusplus INTERFACE cxx_std_17)
# ---- Install rules ----
if (tomlplusplus_INSTALL)
include(cmake/install-rules.cmake)
endif()
# ---- C++ Modules Support (optional) ----
if(TOMLPLUSPLUS_BUILD_MODULES)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
message(STATUS "Building C++ modules (CMake ${CMAKE_VERSION} supports modules)")
add_subdirectory(src/modules)
else()
message(WARNING "Skipping C++ modules (requires CMake 3.28+, found ${CMAKE_VERSION})")
endif()
else()
message(STATUS "C++ modules support is disabled. Enable with -DTOMLPLUSPLUS_BUILD_MODULES=ON")
endif()
# ---- Tests ----
if(tomlplusplus_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
if(tomlplusplus_BUILD_TOML_TEST AND tomlplusplus_EXCEPTIONS)
add_subdirectory(toml-test)
endif()
if(tomlplusplus_BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
# ---- Examples and fuzzing ----
if(PROJECT_IS_TOP_LEVEL)
option(BUILD_EXAMPLES "Build examples tree." OFF)
option(BUILD_FUZZER "Build fuzzer." OFF)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(BUILD_FUZZER AND DEFINED ENV{LIB_FUZZING_ENGINE})
add_subdirectory(fuzzing)
endif()
endif()