Commit 6e31c227e2fd0677236e1fdf5d6306d9cef256fa
Committed by
jarro2783
1 parent
531c00b9
Add CMake option CXXOPTS_ENABLE_INSTALL (#195)
Install targets will not be generated if this option is set to OFF, which is useful when including it as a bundled dependency of another project.
Showing
1 changed file
with
32 additions
and
29 deletions
CMakeLists.txt
| ... | ... | @@ -36,6 +36,7 @@ enable_testing() |
| 36 | 36 | |
| 37 | 37 | option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON) |
| 38 | 38 | option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ON) |
| 39 | +option(CXXOPTS_ENABLE_INSTALL "Generate the install target" ON) | |
| 39 | 40 | |
| 40 | 41 | # request c++11 without gnu extension for the whole project and enable more warnings |
| 41 | 42 | if (CXXOPTS_CXX_STANDARD) |
| ... | ... | @@ -71,35 +72,37 @@ target_include_directories(cxxopts INTERFACE |
| 71 | 72 | $<INSTALL_INTERFACE:include> |
| 72 | 73 | ) |
| 73 | 74 | |
| 74 | -include(CMakePackageConfigHelpers) | |
| 75 | -set(CXXOPTS_CMAKE_DIR "lib/cmake/cxxopts" CACHE STRING | |
| 76 | - "Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.") | |
| 77 | -set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake") | |
| 78 | -set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake") | |
| 79 | -set(targets_export_name cxxopts-targets) | |
| 80 | - | |
| 81 | -# Generate the version, config and target files into the build directory. | |
| 82 | -write_basic_package_version_file( | |
| 83 | - ${version_config} | |
| 84 | - VERSION ${VERSION} | |
| 85 | - COMPATIBILITY AnyNewerVersion) | |
| 86 | -configure_package_config_file( | |
| 87 | - ${PROJECT_SOURCE_DIR}/cxxopts-config.cmake.in | |
| 88 | - ${project_config} | |
| 89 | - INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR}) | |
| 90 | -export(TARGETS cxxopts NAMESPACE cxxopts:: | |
| 91 | - FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake) | |
| 92 | - | |
| 93 | -# Install version, config and target files. | |
| 94 | -install( | |
| 95 | - FILES ${project_config} ${version_config} | |
| 96 | - DESTINATION ${CXXOPTS_CMAKE_DIR}) | |
| 97 | -install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR} | |
| 98 | - NAMESPACE cxxopts::) | |
| 99 | - | |
| 100 | -# Install the header file and export the target | |
| 101 | -install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION lib) | |
| 102 | -install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION include) | |
| 75 | +if(CXXOPTS_ENABLE_INSTALL) | |
| 76 | + include(CMakePackageConfigHelpers) | |
| 77 | + set(CXXOPTS_CMAKE_DIR "lib/cmake/cxxopts" CACHE STRING | |
| 78 | + "Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.") | |
| 79 | + set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake") | |
| 80 | + set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake") | |
| 81 | + set(targets_export_name cxxopts-targets) | |
| 82 | + | |
| 83 | + # Generate the version, config and target files into the build directory. | |
| 84 | + write_basic_package_version_file( | |
| 85 | + ${version_config} | |
| 86 | + VERSION ${VERSION} | |
| 87 | + COMPATIBILITY AnyNewerVersion) | |
| 88 | + configure_package_config_file( | |
| 89 | + ${PROJECT_SOURCE_DIR}/cxxopts-config.cmake.in | |
| 90 | + ${project_config} | |
| 91 | + INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR}) | |
| 92 | + export(TARGETS cxxopts NAMESPACE cxxopts:: | |
| 93 | + FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake) | |
| 94 | + | |
| 95 | + # Install version, config and target files. | |
| 96 | + install( | |
| 97 | + FILES ${project_config} ${version_config} | |
| 98 | + DESTINATION ${CXXOPTS_CMAKE_DIR}) | |
| 99 | + install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR} | |
| 100 | + NAMESPACE cxxopts::) | |
| 101 | + | |
| 102 | + # Install the header file and export the target | |
| 103 | + install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION lib) | |
| 104 | + install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION include) | |
| 105 | +endif() | |
| 103 | 106 | |
| 104 | 107 | add_subdirectory(src) |
| 105 | 108 | add_subdirectory(test) | ... | ... |