mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Add CMake option to disable installation
Rationale: since sol2 is a header-only library, some projects might
use it as a private dependency instead of exposing it through their API.
Thus, it is useful to have an option to not install sol2, in order to
reduce the installation size as well as to avoid accidentally exposing
internal dependencies in the top-level project.
The project I work on is a demonstration of how the feature might be
used:
f4a20ec39e/external/CMakeLists.txt (L84)
(mind the different name of the CMake variable, I renamed it to fit the rest
of the sol options convention)
We have an install-check script script which verifies that only expected
headers, libs, targets and docs are exported (the one which are interesting
from users PoV). I wouldn't mind contributing the script as github workflows
if you want to use it as well - please provide feedback if that's desired.
Here is a link to our script for preview:
https://github.com/GENIVI/ramses-logic/blob/master/ci/scripts/installation-check/check-installation.py
While modifying the CMake code, I noticed a 4-space instead of TAB in one
place and fixed it to be consistent with the rest of the CMake code.
This commit is contained in:
parent
4adc453419
commit
ca3d30d8e9
|
@ -53,6 +53,7 @@ option(SOL2_DYNAMIC_LOADING_EXAMPLES "Enable build of interop examples" OFF)
|
||||||
option(SOL2_GENERATE_SINGLE "Enable generation and build of single header files" OFF)
|
option(SOL2_GENERATE_SINGLE "Enable generation and build of single header files" OFF)
|
||||||
option(SOL2_SINGLE "Enable use of prepackaged single header files" OFF)
|
option(SOL2_SINGLE "Enable use of prepackaged single header files" OFF)
|
||||||
option(SOL2_DOCS "Enable build of documentation" OFF)
|
option(SOL2_DOCS "Enable build of documentation" OFF)
|
||||||
|
option(SOL2_ENABLE_INSTALL "Enable installation of Sol2" ON)
|
||||||
# Single tests and examples tests will only be turned on if both SINGLE and TESTS are defined
|
# Single tests and examples tests will only be turned on if both SINGLE and TESTS are defined
|
||||||
CMAKE_DEPENDENT_OPTION(SOL2_TESTS_SINGLE "Enable build of tests using the premade single headers" ON
|
CMAKE_DEPENDENT_OPTION(SOL2_TESTS_SINGLE "Enable build of tests using the premade single headers" ON
|
||||||
"SOL2_SINGLE;SOL2_TESTS" OFF)
|
"SOL2_SINGLE;SOL2_TESTS" OFF)
|
||||||
|
@ -132,20 +133,22 @@ write_basic_package_version_file(
|
||||||
|
|
||||||
export(TARGETS sol2 FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-targets.cmake")
|
export(TARGETS sol2 FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-targets.cmake")
|
||||||
|
|
||||||
install(TARGETS sol2
|
if(SOL2_ENABLE_INSTALL)
|
||||||
EXPORT sol2)
|
install(TARGETS sol2
|
||||||
|
EXPORT sol2)
|
||||||
|
|
||||||
install(EXPORT sol2
|
install(EXPORT sol2
|
||||||
FILE sol2-targets.cmake
|
FILE sol2-targets.cmake
|
||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sol2")
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sol2")
|
||||||
|
|
||||||
install(DIRECTORY include/sol
|
install(DIRECTORY include/sol
|
||||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||||
|
|
||||||
install(FILES
|
install(FILES
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-config.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-config.cmake"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-config-version.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-config-version.cmake"
|
||||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sol2")
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sol2")
|
||||||
|
endif()
|
||||||
|
|
||||||
# # # Single header target
|
# # # Single header target
|
||||||
# Find Python3 for single header / forward header generation
|
# Find Python3 for single header / forward header generation
|
||||||
|
@ -161,14 +164,16 @@ if (SOL2_DOCS)
|
||||||
add_subdirectory(docs)
|
add_subdirectory(docs)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# pkg-config support, except on Windows
|
if(SOL2_ENABLE_INSTALL)
|
||||||
if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
|
# pkg-config support, except on Windows
|
||||||
set(PKGCONFIG_INSTALL_DIR
|
if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
|
||||||
"${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
|
set(PKGCONFIG_INSTALL_DIR
|
||||||
CACHE PATH "Path where sol2.pc is installed")
|
"${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
|
||||||
|
CACHE PATH "Path where sol2.pc is installed")
|
||||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sol2.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" @ONLY)
|
|
||||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" DESTINATION "${PKGCONFIG_INSTALL_DIR}")
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sol2.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" @ONLY)
|
||||||
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" DESTINATION "${PKGCONFIG_INSTALL_DIR}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (SOL2_CI)
|
if (SOL2_CI)
|
||||||
|
|
|
@ -32,7 +32,7 @@ endif()
|
||||||
|
|
||||||
find_program(sol2_make_executable make make.exe mingw32-make mingw32-make.exe)
|
find_program(sol2_make_executable make make.exe mingw32-make mingw32-make.exe)
|
||||||
if(NOT sol2_make_executable)
|
if(NOT sol2_make_executable)
|
||||||
message(FATAL_ERROR "could not find a suitable make executable to build Sphinx documentation")
|
message(FATAL_ERROR "could not find a suitable make executable to build Sphinx documentation")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_custom_command(OUTPUT docs_invisible_file_always_generate
|
add_custom_command(OUTPUT docs_invisible_file_always_generate
|
||||||
|
@ -40,4 +40,7 @@ add_custom_command(OUTPUT docs_invisible_file_always_generate
|
||||||
COMMAND "${sol2_make_executable}" -C "${CMAKE_CURRENT_SOURCE_DIR}" html "BUILDDIR=${CMAKE_CURRENT_BINARY_DIR}")
|
COMMAND "${sol2_make_executable}" -C "${CMAKE_CURRENT_SOURCE_DIR}" html "BUILDDIR=${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
add_custom_target(docs
|
add_custom_target(docs
|
||||||
DEPENDS docs_invisible_file_always_generate)
|
DEPENDS docs_invisible_file_always_generate)
|
||||||
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docs/html" DESTINATION "${CMAKE_INSTALL_DOCDIR}")
|
|
||||||
|
if(SOL2_ENABLE_INSTALL)
|
||||||
|
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docs/html" DESTINATION "${CMAKE_INSTALL_DOCDIR}")
|
||||||
|
endif()
|
||||||
|
|
|
@ -109,7 +109,9 @@ function (MAKE_EXAMPLE example_source_file example_suffix target_sol)
|
||||||
if (SOL2_TESTS_EXAMPLES)
|
if (SOL2_TESTS_EXAMPLES)
|
||||||
add_test(NAME ${example_output_name} COMMAND ${example_name})
|
add_test(NAME ${example_output_name} COMMAND ${example_name})
|
||||||
endif()
|
endif()
|
||||||
install(TARGETS ${example_name} RUNTIME DESTINATION bin)
|
if(SOL2_ENABLE_INSTALL)
|
||||||
|
install(TARGETS ${example_name} RUNTIME DESTINATION bin)
|
||||||
|
endif()
|
||||||
endfunction(MAKE_EXAMPLE)
|
endfunction(MAKE_EXAMPLE)
|
||||||
|
|
||||||
if (SOL2_EXAMPLES)
|
if (SOL2_EXAMPLES)
|
||||||
|
|
|
@ -70,6 +70,8 @@ if (SOL2_GENERATE_SINGLE)
|
||||||
EXPORT_NAME sol2::sol2_single_generated
|
EXPORT_NAME sol2::sol2_single_generated
|
||||||
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/include")
|
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/include")
|
||||||
add_dependencies(sol2_single_generated sol2_single_header_generator)
|
add_dependencies(sol2_single_generated sol2_single_header_generator)
|
||||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/sol/sol.hpp" "${CMAKE_CURRENT_BINARY_DIR}/include/sol/forward.hpp"
|
if(SOL2_ENABLE_INSTALL)
|
||||||
DESTINATION include/sol/single/sol)
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/sol/sol.hpp" "${CMAKE_CURRENT_BINARY_DIR}/include/sol/forward.hpp"
|
||||||
|
DESTINATION include/sol/single/sol)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -87,7 +87,9 @@ function(CREATE_TEST test_target_name test_name target_sol)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
||||||
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
if(SOL2_ENABLE_INSTALL)
|
||||||
|
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
||||||
|
endif()
|
||||||
endfunction(CREATE_TEST)
|
endfunction(CREATE_TEST)
|
||||||
|
|
||||||
if (SOL2_TESTS)
|
if (SOL2_TESTS)
|
||||||
|
|
|
@ -89,7 +89,9 @@ function(CREATE_TEST test_target_name test_name target_sol)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
||||||
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
if(SOL2_ENABLE_INSTALL)
|
||||||
|
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
||||||
|
endif()
|
||||||
endfunction(CREATE_TEST)
|
endfunction(CREATE_TEST)
|
||||||
|
|
||||||
if (SOL2_TESTS)
|
if (SOL2_TESTS)
|
||||||
|
|
|
@ -85,7 +85,9 @@ function(CREATE_TEST test_target_name test_name target_sol)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
||||||
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
if(SOL2_ENABLE_INSTALL)
|
||||||
|
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
||||||
|
endif()
|
||||||
endfunction(CREATE_TEST)
|
endfunction(CREATE_TEST)
|
||||||
|
|
||||||
if (SOL2_TESTS)
|
if (SOL2_TESTS)
|
||||||
|
|
|
@ -57,7 +57,9 @@ function(CREATE_TEST test_target_name test_name target_sol)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
||||||
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
if(SOL2_ENABLE_INSTALL)
|
||||||
|
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
||||||
|
endif()
|
||||||
endfunction(CREATE_TEST)
|
endfunction(CREATE_TEST)
|
||||||
|
|
||||||
if (SOL2_TESTS)
|
if (SOL2_TESTS)
|
||||||
|
|
|
@ -91,7 +91,9 @@ function(CREATE_TEST test_target_name test_name target_sol)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
add_test(NAME ${test_name} COMMAND ${test_target_name})
|
||||||
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
if(SOL2_ENABLE_INSTALL)
|
||||||
|
install(TARGETS ${test_target_name} RUNTIME DESTINATION bin)
|
||||||
|
endif()
|
||||||
endfunction(CREATE_TEST)
|
endfunction(CREATE_TEST)
|
||||||
|
|
||||||
if (SOL2_TESTS)
|
if (SOL2_TESTS)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user