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.
This commit is contained in:
parent
531c00b96f
commit
6e31c227e2
@ -36,6 +36,7 @@ enable_testing()
|
|||||||
|
|
||||||
option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)
|
option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)
|
||||||
option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ON)
|
option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ON)
|
||||||
|
option(CXXOPTS_ENABLE_INSTALL "Generate the install target" ON)
|
||||||
|
|
||||||
# request c++11 without gnu extension for the whole project and enable more warnings
|
# request c++11 without gnu extension for the whole project and enable more warnings
|
||||||
if (CXXOPTS_CXX_STANDARD)
|
if (CXXOPTS_CXX_STANDARD)
|
||||||
@ -71,35 +72,37 @@ target_include_directories(cxxopts INTERFACE
|
|||||||
$<INSTALL_INTERFACE:include>
|
$<INSTALL_INTERFACE:include>
|
||||||
)
|
)
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
if(CXXOPTS_ENABLE_INSTALL)
|
||||||
set(CXXOPTS_CMAKE_DIR "lib/cmake/cxxopts" CACHE STRING
|
include(CMakePackageConfigHelpers)
|
||||||
|
set(CXXOPTS_CMAKE_DIR "lib/cmake/cxxopts" CACHE STRING
|
||||||
"Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")
|
"Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")
|
||||||
set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")
|
set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")
|
||||||
set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")
|
set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")
|
||||||
set(targets_export_name cxxopts-targets)
|
set(targets_export_name cxxopts-targets)
|
||||||
|
|
||||||
# Generate the version, config and target files into the build directory.
|
# Generate the version, config and target files into the build directory.
|
||||||
write_basic_package_version_file(
|
write_basic_package_version_file(
|
||||||
${version_config}
|
${version_config}
|
||||||
VERSION ${VERSION}
|
VERSION ${VERSION}
|
||||||
COMPATIBILITY AnyNewerVersion)
|
COMPATIBILITY AnyNewerVersion)
|
||||||
configure_package_config_file(
|
configure_package_config_file(
|
||||||
${PROJECT_SOURCE_DIR}/cxxopts-config.cmake.in
|
${PROJECT_SOURCE_DIR}/cxxopts-config.cmake.in
|
||||||
${project_config}
|
${project_config}
|
||||||
INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR})
|
INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR})
|
||||||
export(TARGETS cxxopts NAMESPACE cxxopts::
|
export(TARGETS cxxopts NAMESPACE cxxopts::
|
||||||
FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
|
FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
|
||||||
|
|
||||||
# Install version, config and target files.
|
# Install version, config and target files.
|
||||||
install(
|
install(
|
||||||
FILES ${project_config} ${version_config}
|
FILES ${project_config} ${version_config}
|
||||||
DESTINATION ${CXXOPTS_CMAKE_DIR})
|
DESTINATION ${CXXOPTS_CMAKE_DIR})
|
||||||
install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}
|
install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}
|
||||||
NAMESPACE cxxopts::)
|
NAMESPACE cxxopts::)
|
||||||
|
|
||||||
# Install the header file and export the target
|
# Install the header file and export the target
|
||||||
install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION lib)
|
install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION lib)
|
||||||
install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION include)
|
install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION include)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user