Skip to content

Commit 8d20a2e

Browse files
committed
Disable build of tests, examples, documentation etc if the project is being included as a subdirectory
Added tools for inclusion in other packages Cache version string determined from git tags Update header for next release
1 parent 9f6aae9 commit 8d20a2e

3 files changed

Lines changed: 137 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ endif()
1717
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules)
1818
include(${CMAKE_CURRENT_SOURCE_DIR}/YggdrasilRapidJSONMacros.cmake)
1919

20-
set(YGGDRASIL_RAPIDJSON_VERSION "" CACHE STRING "Version to use instead of the git tag version")
20+
yggdrasil_rapidjson_gitversion(DEFAULT_YGGDRASIL_RAPIDJSON_VERSION "1.1.0.2")
21+
set(YGGDRASIL_RAPIDJSON_VERSION "${DEFAULT_YGGDRASIL_RAPIDJSON_VERSION}" CACHE STRING "Version to use instead of the git tag version")
2122

22-
if(NOT YGGDRASIL_RAPIDJSON_VERSION)
23-
yggdrasil_rapidjson_gitversion(YGGDRASIL_RAPIDJSON_VERSION "1.1.0.2")
24-
endif()
2523
message(STATUS "YGGDRASIL_RAPIDJSON_VERSION = ${YGGDRASIL_RAPIDJSON_VERSION}")
2624

2725
PROJECT(YggdrasilRapidJSON VERSION "${YGGDRASIL_RAPIDJSON_VERSION}" LANGUAGES C CXX)
@@ -38,15 +36,21 @@ SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules)
3836
include(${CMAKE_CURRENT_SOURCE_DIR}/YggdrasilRapidJSONMacros.cmake)
3937
yggdrasil_rapidjson_options_create()
4038

39+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
40+
set(IS_TOP_LEVEL_BUILD ON)
41+
else()
42+
set(IS_TOP_LEVEL_BUILD OFF)
43+
endif()
44+
4145
option(YGGDRASIL_RAPIDJSON_NEST_HEADERS "Nest the headers during install under the package name (in addition to the directly containing the headers)" OFF)
4246
option(YGGDRASIL_RAPIDJSON_CREATE_METASCHEMA "Re-create the metaschema" OFF)
4347
option(YGGDRASIL_RAPIDJSON_CREATE_METASCHEMA_FULL "Re-create the metaschema and the full_schema.yaml file" OFF)
4448
option(YGGDRASIL_RAPIDJSON_SCHEMA_TESTS "Build tests using the yggdrasil schema" OFF)
45-
option(YGGDRASIL_RAPIDJSON_BUILD_DOC "Build yggdrasil_rapidjson documentation." ON)
46-
option(YGGDRASIL_RAPIDJSON_BUILD_EXAMPLES "Build yggdrasil_rapidjson examples." ON)
47-
option(YGGDRASIL_RAPIDJSON_BUILD_TESTS "Build yggdrasil_rapidjson perftests and unittests." ON)
48-
option(YGGDRASIL_RAPIDJSON_BUILD_UNITTESTS "Build yggdrasil_rapidjson unittests." ON)
49-
option(YGGDRASIL_RAPIDJSON_BUILD_PERFTESTS "Build yggdrasil_rapidjson perftests." ON)
49+
option(YGGDRASIL_RAPIDJSON_BUILD_DOC "Build yggdrasil_rapidjson documentation." ${IS_TOP_LEVEL_BUILD})
50+
option(YGGDRASIL_RAPIDJSON_BUILD_EXAMPLES "Build yggdrasil_rapidjson examples." ${IS_TOP_LEVEL_BUILD})
51+
option(YGGDRASIL_RAPIDJSON_BUILD_TESTS "Build yggdrasil_rapidjson perftests and unittests." ${IS_TOP_LEVEL_BUILD})
52+
option(YGGDRASIL_RAPIDJSON_BUILD_UNITTESTS "Build yggdrasil_rapidjson unittests." ${IS_TOP_LEVEL_BUILD})
53+
option(YGGDRASIL_RAPIDJSON_BUILD_PERFTESTS "Build yggdrasil_rapidjson perftests." ${IS_TOP_LEVEL_BUILD})
5054
option(YGGDRASIL_RAPIDJSON_BUILD_THIRDPARTY_GTEST
5155
"Use gtest installation in `thirdparty/gtest` by default if available" OFF)
5256

@@ -265,6 +269,9 @@ else()
265269
endif()
266270

267271
yggdrasil_rapidjson_target_config(${PROJECT_NAME} INTERFACE INTERFACE)
272+
if(NOT IS_TOP_LEVEL_BUILD)
273+
yggdrasil_rapidjson_target_config(${PROJECT_NAME} INTERFACE LOCAL)
274+
endif()
268275

269276
link_libraries(${PROJECT_NAME})
270277
yggdrasil_rapidjson_global_config(CXX LOCAL)

YggdrasilRapidJSONTools.cmake

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# This file contains some useful macros for use by packages using
2+
# yggdrasil-rapidjson as a dependency via find_package
3+
4+
macro(include_yggdrasil_rapidjson_macros)
5+
if(NOT COMMAND yggdrasil_rapidjson_options)
6+
set(YGGDRASIL_RAPIDJSON_REPO_DIR "" CACHE PATH "Existing directory containing the yggdrasil-rapidjson repository")
7+
set(YGGDRASIL_RAPIDJSON_REPO_BUILD_DIR "")
8+
set(YGGDRASIL_RAPIDJSON_MACROS_FILE "")
9+
10+
if(YggdrasilRapidJSON_FOUND)
11+
message(FATAL_ERROR "YggdrasilRapidJSON_FOUND, but yggdrasil_rapidjson_options not defined")
12+
elseif(NOT YGGDRASIL_RAPIDJSON_REPO_DIR)
13+
find_file(
14+
YGGDRASIL_RAPIDJSON_CONFIG_FILE
15+
YggdrasilRapidJSONConfig.cmake
16+
PATHS "${YggdrasilRapidJSON_DIR}"
17+
)
18+
if(YGGDRASIL_RAPIDJSON_CONFIG_FILE)
19+
message(DEBUG "Located YggdrasilRapidJSON config file at ${YGGDRASIL_RAPIDJSON_CONFIG_FILE}")
20+
cmake_path(
21+
GET YGGDRASIL_RAPIDJSON_CONFIG_FILE
22+
PARENT_PATH YGGDRASIL_RAPIDJSON_MACROS_FILE
23+
)
24+
cmake_path(
25+
APPEND YGGDRASIL_RAPIDJSON_MACROS_FILE
26+
YggdrasilRapidJSONMacros.cmake
27+
)
28+
else()
29+
find_file(
30+
YGGDRASIL_RAPIDJSON_CONFIG_FILE
31+
YggdrasilRapidJSONConfig.cmake.in
32+
PATHS "${YggdrasilRapidJSON_DIR}"
33+
)
34+
if(YGGDRASIL_RAPIDJSON_CONFIG_FILE)
35+
message(DEBUG "Located YggdrasilRapidJSON config template file at ${YGGDRASIL_RAPIDJSON_CONFIG_FILE}")
36+
cmake_path(
37+
GET YGGDRASIL_RAPIDJSON_CONFIG_FILE
38+
PARENT_PATH YGGDRASIL_RAPIDJSON_REPO_DIR
39+
)
40+
endif()
41+
endif()
42+
unset(YGGDRASIL_RAPIDJSON_CONFIG_FILE)
43+
endif()
44+
if(YGGDRASIL_RAPIDJSON_REPO_DIR)
45+
if(NOT EXISTS "${YGGDRASIL_RAPIDJSON_REPO_DIR}")
46+
message(FATAL_ERROR "Directory specified by option YGGDRASIL_RAPIDJSON_REPO_DIR=\"${YGGDRASIL_RAPIDJSON_REPO_DIR}\" does not exist")
47+
endif()
48+
if(NOT IS_ABSOLUTE "${YGGDRASIL_RAPIDJSON_REPO_DIR}")
49+
cmake_path(
50+
ABSOLUTE_PATH YGGDRASIL_RAPIDJSON_REPO_DIR
51+
NORMALIZE
52+
)
53+
endif()
54+
include(FetchContent)
55+
FetchContent_Declare(
56+
YggdrasilRapidJSON
57+
SOURCE_DIR "${YGGDRASIL_RAPIDJSON_REPO_DIR}"
58+
EXCLUDE_FROM_ALL
59+
OVERRIDE_FIND_PACKAGE
60+
)
61+
FetchContent_Populate(YggdrasilRapidJSON)
62+
cmake_path(
63+
APPEND YGGDRASIL_RAPIDJSON_REPO_DIR "_build_for_${PROJECT_NAME}"
64+
OUTPUT_VARIABLE YGGDRASIL_RAPIDJSON_REPO_BUILD_DIR
65+
)
66+
elseif(NOT YGGDRASIL_RAPIDJSON_MACROS_FILE)
67+
message(WARNING "Could not locate the YggdrasilRapidJSON package via find_file (YggdrasilRapidJSON_DIR=${YggdrasilRapidJSON_DIR}), importing it from github as an external project...")
68+
include(FetchContent)
69+
FetchContent_Declare(
70+
YggdrasilRapidJSON
71+
GIT_REPOSITORY https://github.com/cropsinsilico/yggdrasil-rapidjson.git
72+
GIT_TAG origin/yggdrasil
73+
EXCLUDE_FROM_ALL
74+
OVERRIDE_FIND_PACKAGE
75+
)
76+
FetchContent_Populate(YggdrasilRapidJSON)
77+
set(YGGDRASIL_RAPIDJSON_REPO_DIR "${yggdrasilrapidjson_SOURCE_DIR}")
78+
set(YGGDRASIL_RAPIDJSON_REPO_BUILD_DIR "${yggdrasilrapidjson_BUILD_DIR}")
79+
endif()
80+
if(NOT YGGDRASIL_RAPIDJSON_MACROS_FILE)
81+
cmake_path(
82+
APPEND YGGDRASIL_RAPIDJSON_REPO_DIR
83+
YggdrasilRapidJSONMacros.cmake
84+
OUTPUT_VARIABLE YGGDRASIL_RAPIDJSON_MACROS_FILE
85+
)
86+
endif()
87+
message(STATUS "Including YggdrasilRapidJSON macros from \"${YGGDRASIL_RAPIDJSON_MACROS_FILE}\" (REPO_DIR=${YGGDRASIL_RAPIDJSON_REPO_DIR})")
88+
include("${YGGDRASIL_RAPIDJSON_MACROS_FILE}")
89+
endif()
90+
endmacro()
91+
92+
macro(find_yggdrasil_rapidjson)
93+
include_yggdrasil_rapidjson_macros()
94+
if(YGGDRASIL_RAPIDJSON_REPO_DIR)
95+
foreach(suffix BUILD_EXAMPLES BUILD_TESTS BUILD_DOC)
96+
if(NOT YGGDRASIL_RAPIDJSON_${suffix})
97+
set(YGGDRASIL_RAPIDJSON_${suffix} OFF)
98+
endif()
99+
endforeach()
100+
add_subdirectory(
101+
"${YGGDRASIL_RAPIDJSON_REPO_DIR}"
102+
"${YGGDRASIL_RAPIDJSON_REPO_BUILD_DIR}"
103+
EXCLUDE_FROM_ALL
104+
)
105+
# Required for cmake <3.28 when EXCLUDE_FROM_ALL was added to
106+
# FetchContent_Declare
107+
set_property(
108+
DIRECTORY "${YGGDRASIL_RAPIDJSON_REPO_DIR}"
109+
PROPERTY EXCLUDE_FROM_ALL ON
110+
)
111+
set(YggdrasilRapidJSON_VERSION "${YGGDRASIL_RAPIDJSON_VERSION}")
112+
else()
113+
find_package(YggdrasilRapidJSON REQUIRED)
114+
endif()
115+
if(YggdrasilRapidJSON_VERSION VERSION_LESS "1.1.0.6")
116+
yggdrasil_rapidjson_options_config(LOCAL)
117+
yggdrasil_rapidjson_target_config(YggdrasilRapidJSON INTERFACE LOCAL)
118+
endif()
119+
120+
endmacro()

include/yggdrasil_rapidjson/yggdrasil_rapidjson_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define YGGDRASIL_RAPIDJSON_MAJOR_VERSION 1
3737
#define YGGDRASIL_RAPIDJSON_MINOR_VERSION 1
3838
#define YGGDRASIL_RAPIDJSON_PATCH_VERSION 0
39-
#define YGGDRASIL_RAPIDJSON_EXTEN_VERSION 5
39+
#define YGGDRASIL_RAPIDJSON_EXTEN_VERSION 6
4040
#define YGGDRASIL_RAPIDJSON_VERSION_STRING \
4141
YGGDRASIL_RAPIDJSON_STRINGIFY(YGGDRASIL_RAPIDJSON_MAJOR_VERSION.YGGDRASIL_RAPIDJSON_MINOR_VERSION.YGGDRASIL_RAPIDJSON_PATCH_VERSION.YGGDRASIL_RAPIDJSON_EXTEN_VERSION)
4242

0 commit comments

Comments
 (0)