Skip to content

Commit 6e9812f

Browse files
themarpepboettch
authored andcommitted
Added Hunter, install and MSVC fix
1 parent 43acedc commit 6e9812f

File tree

3 files changed

+560
-3
lines changed

3 files changed

+560
-3
lines changed

CMakeLists.txt

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ cmake_minimum_required(VERSION 3.2)
88
option(BUILD_TESTS "Build tests" ON)
99
option(BUILD_EXAMPLES "Build examples" ON)
1010

11+
option(HUNTER_ENABLED "Enable Hunter package manager support" OFF)
12+
if(HUNTER_ENABLED)
13+
include(cmake/HunterGate.cmake)
14+
HunterGate(URL https://github.com/cpp-pm/hunter/archive/v0.23.253.tar.gz
15+
SHA1 88ea6d37c897a81a080eb9ae0f69d7807bbb3c73)
16+
17+
# Add nlohmann_json::nlohmann_json (if HUNTER_ENABLED=ON, otherwise command is ignored)
18+
hunter_add_package(nlohmann_json)
19+
endif()
20+
1121
# the library
1222
add_library(nlohmann_json_schema_validator
1323
src/json-schema-draft7.json.cpp
@@ -158,8 +168,8 @@ endif()
158168
if(JSON_VALIDATOR_INSTALL)
159169
# Set Up the Project Targets and Config Files for CMake
160170

161-
# Set the install path to the cmake config files
162-
set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME})
171+
# Set the install path to the cmake config files (Relative, so install works correctly under Hunter as well)
172+
set(INSTALL_CMAKE_DIR "lib/cmake/${PROJECT_NAME}")
163173

164174
# Create the ConfigVersion file
165175
include(CMakePackageConfigHelpers) # write_basic_package_version_file
@@ -168,7 +178,7 @@ if(JSON_VALIDATOR_INSTALL)
168178
COMPATIBILITY SameMajorVersion)
169179

170180
# Get the relative path from the INSTALL_CMAKE_DIR to the include directory
171-
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${CMAKE_INSTALL_PREFIX}/include")
181+
file(RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}" "${CMAKE_INSTALL_PREFIX}/include")
172182

173183

174184
# Configure the Config.cmake file with the proper include directory

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ access nlohmann-json:
106106
a sub-directory (via `add_subdirectory()`), 2 and 3 can be
107107
assisted by setting the `nlohmann_json_DIR`-variable.
108108

109+
### Building with Hunter package manager
110+
111+
To enable access to nlohmann json library, Hunter can be used. Just run with HUNTER_ENABLED=ON option. No further dependencies needed
112+
113+
```bash
114+
cmake [..] -DHUNTER_ENABLED=ON [..]
115+
```
116+
109117
### Building as a CMake-subdirectory from within another project
110118

111119
Adding this library as a subdirectory to a parent project is one way of

0 commit comments

Comments
 (0)