Skip to content

Commit 5ec1961

Browse files
res0nancepboettch
authored andcommitted
cmake: add option to disable installing targets
1 parent c7325ae commit 5ec1961

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

CMakeLists.txt

+37-32
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.2)
22

33
option(JSON_VALIDATOR_BUILD_TESTS "Build tests" ON)
44
option(JSON_VALIDATOR_BUILD_EXAMPLES "Build examples" ON)
5+
option(JSON_VALIDATOR_INSTALL "Install target" ON)
56
option(JSON_VALIDATOR_HUNTER "Enable Hunter package manager support" OFF)
67

78
if(JSON_VALIDATOR_HUNTER)
@@ -95,14 +96,16 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
9596
endif()
9697
endif()
9798

98-
install(TARGETS nlohmann_json_schema_validator
99-
EXPORT ${PROJECT_NAME}Targets
100-
LIBRARY DESTINATION lib
101-
ARCHIVE DESTINATION lib
102-
RUNTIME DESTINATION bin)
99+
if(JSON_VALIDATOR_INSTALL)
100+
install(TARGETS nlohmann_json_schema_validator
101+
EXPORT ${PROJECT_NAME}Targets
102+
LIBRARY DESTINATION lib
103+
ARCHIVE DESTINATION lib
104+
RUNTIME DESTINATION bin)
103105

104-
install(FILES src/nlohmann/json-schema.hpp
105-
DESTINATION include/nlohmann)
106+
install(FILES src/nlohmann/json-schema.hpp
107+
DESTINATION include/nlohmann)
108+
endif()
106109

107110
if (JSON_VALIDATOR_BUILD_EXAMPLES)
108111
# simple nlohmann_json_schema_validator-executable
@@ -127,32 +130,34 @@ endif()
127130

128131
# Set Up the Project Targets and Config Files for CMake
129132

130-
# Set the install path to the cmake config files (Relative, so install works correctly under Hunter as well)
131-
set(INSTALL_CMAKE_DIR "lib/cmake/${PROJECT_NAME}")
132-
set(INSTALL_CMAKEDIR_ROOT share/cmake)
133-
134-
# Install Targets
135-
install(EXPORT ${PROJECT_NAME}Targets
136-
FILE ${PROJECT_NAME}Targets.cmake
137-
DESTINATION "${INSTALL_CMAKE_DIR}")
133+
if(JSON_VALIDATOR_INSTALL)
134+
# Set the install path to the cmake config files (Relative, so install works correctly under Hunter as well)
135+
set(INSTALL_CMAKE_DIR "lib/cmake/${PROJECT_NAME}")
136+
set(INSTALL_CMAKEDIR_ROOT share/cmake)
138137

139-
include(CMakePackageConfigHelpers)
140-
write_basic_package_version_file(
141-
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
142-
VERSION ${PROJECT_VERSION}
143-
COMPATIBILITY SameMajorVersion
144-
)
138+
# Install Targets
139+
install(EXPORT ${PROJECT_NAME}Targets
140+
FILE ${PROJECT_NAME}Targets.cmake
141+
DESTINATION "${INSTALL_CMAKE_DIR}")
145142

146-
configure_package_config_file(
147-
${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
148-
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
149-
INSTALL_DESTINATION ${INSTALL_CMAKEDIR_ROOT}/${PROJECT_NAME}
150-
)
143+
include(CMakePackageConfigHelpers)
144+
write_basic_package_version_file(
145+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
146+
VERSION ${PROJECT_VERSION}
147+
COMPATIBILITY SameMajorVersion
148+
)
151149

152-
install(
153-
FILES
150+
configure_package_config_file(
151+
${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
154152
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
155-
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
156-
DESTINATION
157-
${INSTALL_CMAKE_DIR}
158-
)
153+
INSTALL_DESTINATION ${INSTALL_CMAKEDIR_ROOT}/${PROJECT_NAME}
154+
)
155+
156+
install(
157+
FILES
158+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
159+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
160+
DESTINATION
161+
${INSTALL_CMAKE_DIR}
162+
)
163+
endif()

0 commit comments

Comments
 (0)