Skip to content

Commit

Permalink
Update CMakeLists.txt to enable building the documentation separately
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryAWE committed Jun 17, 2024
1 parent 305db33 commit 164a5b7
Showing 1 changed file with 76 additions and 70 deletions.
146 changes: 76 additions & 70 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(papilio_build_unit_test "build unit tests" OFF)
mark_as_advanced(papilio_build_unit_test)

# If you only want to build the documentation, you can disable building the library
option(papilio_build_lib "build the library" ON)
mark_as_advanced(papilio_build_lib)

option(papilio_build_example "build examples" OFF)
option(papilio_build_module "build module (experimental)" OFF)
option(papilio_build_doc "build documents" OFF)
Expand All @@ -29,87 +33,89 @@ message("Papilio Charontis v${papilio_version_major}.${papilio_version_minor}.${
project(
"Papilio Charontis"
VERSION ${papilio_version_major}.${papilio_version_minor}.${papilio_version_patch}
LANGUAGES CXX
)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
option(papilio_use_libcpp "Use libc++ for Clang" OFF)
if(${papilio_use_libcpp})
add_compile_options("-stdlib=libc++")
add_link_options("-stdlib=libc++")
if(${papilio_build_lib})
enable_language(CXX)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
option(papilio_use_libcpp "Use libc++ for Clang" OFF)
if(${papilio_use_libcpp})
add_compile_options("-stdlib=libc++")
add_link_options("-stdlib=libc++")
endif()
endif()
endif()

set(glob_expr "src/*.cpp" "include/*.hpp" "include/*.inl")
file(GLOB_RECURSE papilio_src ${glob_expr})
set(glob_expr "src/*.cpp" "include/*.hpp" "include/*.inl")
file(GLOB_RECURSE papilio_src ${glob_expr})

if(${papilio_build_module})
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
endif()
if(${papilio_build_module})
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
endif()

include(GNUInstallDirs)
include(GNUInstallDirs)

add_library(papilio ${papilio_src})
target_sources(papilio PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/natvis/papilio.natvis>")
target_sources(papilio PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/cpp.hint>")
target_include_directories(papilio PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
add_library(papilio ${papilio_src})
target_sources(papilio PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/natvis/papilio.natvis>")
target_sources(papilio PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/cpp.hint>")
target_include_directories(papilio PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# Add an ALIAS target for using the library by add_subdirectory()
add_library(papilio::papilio ALIAS papilio)
# Add an ALIAS target for using the library by add_subdirectory()
add_library(papilio::papilio ALIAS papilio)

# Enable warnings for development
target_compile_options(papilio PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>
$<$<CXX_COMPILER_ID:Clang>:-Weverything>
)
if(${papilio_build_module})
file(GLOB_RECURSE papilio_modules_src "modules/*.cppm")
target_sources(
papilio
PUBLIC
FILE_SET papilio_modules TYPE CXX_MODULES FILES
${papilio_modules_src}
# Enable warnings for development
target_compile_options(papilio PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>
$<$<CXX_COMPILER_ID:Clang>:-Weverything>
)
endif()
if(${papilio_build_module})
file(GLOB_RECURSE papilio_modules_src "modules/*.cppm")
target_sources(
papilio
PUBLIC
FILE_SET papilio_modules TYPE CXX_MODULES FILES
${papilio_modules_src}
)
endif()

install(
TARGETS papilio
EXPORT PapilioTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.inl"
)
install(
TARGETS papilio
EXPORT PapilioTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.inl"
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"PapilioConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/PapilioConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/PapilioConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/papilio
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/PapilioConfig.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/papilio
)
install(
EXPORT PapilioTargets
FILE PapilioTargets.cmake
NAMESPACE papilio::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/papilio
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"PapilioConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/cmake/PapilioConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/PapilioConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/papilio
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/PapilioConfig.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/papilio
)
install(
EXPORT PapilioTargets
FILE PapilioTargets.cmake
NAMESPACE papilio::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake/papilio
)
endif()

if(${papilio_build_doc})
find_package(Doxygen REQUIRED)
Expand Down

0 comments on commit 164a5b7

Please sign in to comment.