Skip to content

Commit

Permalink
Update installation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhao-shihan committed Jun 4, 2024
1 parent 948dc2d commit ec4adea
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
45 changes: 40 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.14)

project(muc)
project(muc VERSION 0.0.1 LANGUAGES CXX)

add_library(muc INTERFACE)
add_library(muc::muc ALIAS muc)

include(CMakeDependentOption)

cmake_dependent_option(MUC_ENABLE_UBSAN_IN_DEBUG_BUILD "Enable UndefinedBehaviorSanitizer in debug build" ON BUILD_TESTING OFF)
# https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} PROJECT_IS_TOP_LEVEL)

option(MUC_INSTALL "Generate and install muc target" ${PROJECT_IS_TOP_LEVEL})
option(MUC_TEST "Build and perform muc tests" ${PROJECT_IS_TOP_LEVEL})
cmake_dependent_option(MUC_ENABLE_UBSAN_IN_DEBUG_BUILD "Enable UndefinedBehaviorSanitizer in debug build" ON MUC_TEST OFF)

# The implementation generally assumes a platform that implements at least C++17 support
target_compile_features(muc INTERFACE "cxx_std_17")

include(CTest)
if(BUILD_TESTING)
# Setup include directory
add_subdirectory(include)

if (MUC_TEST)
enable_testing()
add_subdirectory(test)
endif()

if (MUC_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/muc" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

set(export_name "mucConfig")
set(namespace "muc::")
set(cmake_files_install_dir ${CMAKE_INSTALL_DATADIR}/cmake/muc)

install(TARGETS muc EXPORT ${export_name} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT ${export_name} NAMESPACE ${namespace} DESTINATION ${cmake_files_install_dir})
export(TARGETS muc NAMESPACE ${namespace} FILE ${export_name}.cmake)

set(muc_config_version "${CMAKE_CURRENT_BINARY_DIR}/mucConfigVersion.cmake")

write_basic_package_version_file(${muc_config_version} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)

install(FILES ${muc_config_version} DESTINATION ${cmake_files_install_dir})
endif()
13 changes: 13 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Add include folders to the library and targets that consume it
# the SYSTEM keyword suppresses warnings for users of the library
#
# By adding this directory as an include directory the user gets a
# namespace effect.
#
# IE:
# #include "muc/type_traits"
if(PROJECT_IS_TOP_LEVEL)
target_include_directories(muc INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
else()
target_include_directories(muc SYSTEM INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
endif()

0 comments on commit ec4adea

Please sign in to comment.