Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake Options #74

Merged
merged 3 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Build project
uses: threeal/[email protected]
with:
options: BUILD_TESTING=ON
options: MUSEN_BUILD_TESTS=ON MUSEN_BUILD_EXAMPLES=ON
run-build: true

- name: Test project
Expand Down
42 changes: 25 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -34,20 +35,27 @@ target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

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()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()