diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 93cfa98..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: BUILD_TESTING=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 f5da426..508b53b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,11 @@ -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( DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.1/CPM.cmake @@ -16,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" @@ -34,20 +35,27 @@ target_include_directories(${PROJECT_NAME} PUBLIC "$" "$") -install(TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME}_export - ARCHIVE DESTINATION "lib" - LIBRARY DESTINATION "lib" - RUNTIME DESTINATION "bin") - -add_subdirectory("examples") - -if(BUILD_TESTING) +if(MUSEN_BUILD_TESTS) enable_testing() add_subdirectory("test/gtest") endif() -install(EXPORT ${PROJECT_NAME}_export - FILE ${PROJECT_NAME}-config.cmake - NAMESPACE ${PROJECT_NAME}:: - DESTINATION "lib/cmake/${PROJECT_NAME}") +if(MUSEN_BUILD_EXAMPLES) + add_subdirectory("examples") +endif() + +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/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 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()