bernedom / SI

A header only C++ library that provides type safety and user defined literals for physical units
https://si.dominikberner.ch/doc/
MIT License
488 stars 40 forks source link

CMAKE option to prevent installing #49

Closed bladan closed 4 years ago

bladan commented 4 years ago

When including SI with CMAKEs add_subdirectory() all SI files are installed on make install.

Sometimes this is not desired, especially when when add_subdirectory() is called from an application CMAKE project that is using the SI:SI alias. The SI library will directly be compiled into the application and there is no need to install the whole library into the destination directory.

A CMAKE option to prevent installing the SI files in such a case could be useful, such as:

set(SI_INSTALL_LIBRARY OFF)
add_subdirectory(extern/SI)

The workaround below shows possible modifications of the CMakeLists.txt when using commenting instead of the proposed CMAKE options:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6fe812c..c34fa4a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,18 +46,18 @@ configure_package_config_file(
   "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION
   ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

-install(
-  EXPORT ${PROJECT_NAME}_Targets
-  FILE ${PROJECT_NAME}Targets.cmake
-  NAMESPACE ${PROJECT_NAME}::
-  DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
+#install(
+#  EXPORT ${PROJECT_NAME}_Targets
+#  FILE ${PROJECT_NAME}Targets.cmake
+#  NAMESPACE ${PROJECT_NAME}::
+#  DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

-install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
-              "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
-        DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
+#install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
+#              "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
+#        DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

-install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/SI
-        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+#install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/SI
+#        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

 set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")