From ade2dd9bfc0921cda5c08c158d87cacbadc738b3 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 4 Aug 2024 22:06:14 +0700 Subject: [PATCH 1/3] build: add `MUSEN_BUILD_TESTS` option --- .github/workflows/build-and-test.yml | 2 +- CMakeLists.txt | 4 +++- README.md | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 93cfa98..87cfbea 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -15,7 +15,7 @@ jobs: - name: Build project uses: threeal/cmake-action@v1.3.0 with: - options: BUILD_TESTING=ON + options: MUSEN_BUILD_TESTS=ON run-build: true - name: Test project diff --git a/CMakeLists.txt b/CMakeLists.txt index f5da426..76219dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.5) project(musen) +option(MUSEN_BUILD_TESTS "Build test targets.") + function(cpmaddpackage) file( DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.1/CPM.cmake @@ -42,7 +44,7 @@ install(TARGETS ${PROJECT_NAME} add_subdirectory("examples") -if(BUILD_TESTING) +if(MUSEN_BUILD_TESTS) enable_testing() add_subdirectory("test/gtest") endif() diff --git a/README.md b/README.md index 0d71c0f..66089e6 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ See [releases](https://github.com/ichiro-its/musen/releases) for the latest vers ``` - (Optional) reconfigure CMake to run the unit tests. ```sh - $ cmake -DBUILD_TESTING=ON .. && make && ctest --verbose + $ cmake -DMUSEN_BUILD_TESTS=ON .. && make && ctest --verbose ``` ## Usages From 9ed62fd42431cb99077454593f1a8eb4bddc3962 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 4 Aug 2024 22:10:52 +0700 Subject: [PATCH 2/3] build: add `MUSEN_BUILD_EXAMPLES` option --- .github/workflows/build-and-test.yml | 2 +- CMakeLists.txt | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 87cfbea..a0cbad2 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -15,7 +15,7 @@ jobs: - name: Build project uses: threeal/cmake-action@v1.3.0 with: - options: MUSEN_BUILD_TESTS=ON + options: MUSEN_BUILD_TESTS=ON MUSEN_BUILD_EXAMPLES=ON run-build: true - name: Test project diff --git a/CMakeLists.txt b/CMakeLists.txt index 76219dd..0795b80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.5) project(musen) option(MUSEN_BUILD_TESTS "Build test targets.") +option(MUSEN_BUILD_EXAMPLES "Build example targets.") function(cpmaddpackage) file( @@ -42,13 +43,15 @@ install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION "lib" RUNTIME DESTINATION "bin") -add_subdirectory("examples") - if(MUSEN_BUILD_TESTS) enable_testing() add_subdirectory("test/gtest") endif() +if(MUSEN_BUILD_EXAMPLES) + add_subdirectory("examples") +endif() + install(EXPORT ${PROJECT_NAME}_export FILE ${PROJECT_NAME}-config.cmake NAMESPACE ${PROJECT_NAME}:: From b121cbb457bdd12a3f81aeae008b8c92df57410a Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 4 Aug 2024 22:10:53 +0700 Subject: [PATCH 3/3] 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()