Skip to content

Commit

Permalink
build: add MUSEN_ENABLE_INSTALL option
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Jul 31, 2024
1 parent 2cb2e55 commit 182a6bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
31 changes: 17 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
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}")

set(CMAKE_C_STANDARD 99)
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 @@ -28,12 +26,6 @@ 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")

if(MUSEN_BUILD_TESTS)
enable_testing()
add_subdirectory("test/gtest")
Expand All @@ -43,7 +35,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()
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()

0 comments on commit 182a6bf

Please sign in to comment.