From b121cbb457bdd12a3f81aeae008b8c92df57410a Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 4 Aug 2024 22:10:53 +0700 Subject: [PATCH] build: add `MUSEN_ENABLE_INSTALL` option --- CMakeLists.txt | 31 +++++++++++++++++-------------- examples/CMakeLists.txt | 5 +++-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0795b80..508b53b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,10 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.21) project(musen) option(MUSEN_BUILD_TESTS "Build test targets.") option(MUSEN_BUILD_EXAMPLES "Build example targets.") +option(MUSEN_ENABLE_INSTALL "Enable targets installation." "${PROJECT_IS_TOP_LEVEL}") function(cpmaddpackage) file( @@ -19,9 +20,6 @@ set(CMAKE_CXX_STANDARD 17) add_compile_options(-Wall -Wextra -Wpedantic -fPIC) -install(DIRECTORY "include/musen" - DESTINATION "include") - add_library(${PROJECT_NAME} SHARED "src/tcp/client.cpp" "src/tcp/server.cpp" @@ -37,12 +35,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC "$" "$") -install(TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME}_export - ARCHIVE DESTINATION "lib" - LIBRARY DESTINATION "lib" - RUNTIME DESTINATION "bin") - if(MUSEN_BUILD_TESTS) enable_testing() add_subdirectory("test/gtest") @@ -52,7 +44,18 @@ if(MUSEN_BUILD_EXAMPLES) add_subdirectory("examples") endif() -install(EXPORT ${PROJECT_NAME}_export - FILE ${PROJECT_NAME}-config.cmake - NAMESPACE ${PROJECT_NAME}:: - DESTINATION "lib/cmake/${PROJECT_NAME}") +if(MUSEN_ENABLE_INSTALL) + install(DIRECTORY "include/musen" + DESTINATION "include") + + install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}_export + ARCHIVE DESTINATION "lib" + LIBRARY DESTINATION "lib" + RUNTIME DESTINATION "bin") + + install(EXPORT ${PROJECT_NAME}_export + FILE ${PROJECT_NAME}-config.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION "lib/cmake/${PROJECT_NAME}") +endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c314d2b..af23a14 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -14,6 +14,7 @@ foreach(EXAMPLE ${EXAMPLES}) add_executable(${TARGET} "${EXAMPLE}") target_link_libraries(${TARGET} ${PROJECT_NAME}) - install(TARGETS ${TARGET} - DESTINATION "bin") + if(MUSEN_ENABLE_INSTALL) + install(TARGETS ${TARGET} DESTINATION "bin") + endif() endforeach()