Files
YYCCommonplace/CMakeLists.txt
T

92 lines
3.0 KiB
CMake
Raw Normal View History

2024-06-15 21:53:45 +08:00
cmake_minimum_required(VERSION 3.23)
2024-06-03 14:24:05 +08:00
project(YYCC
2025-06-20 23:38:34 +08:00
VERSION 2.0.0
2024-06-03 14:24:05 +08:00
LANGUAGES CXX
)
2024-05-29 23:11:52 +08:00
2025-07-25 09:35:26 +08:00
# Setup C++ standard
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
2024-06-06 13:16:55 +08:00
# Provide options
2025-09-29 13:34:02 +08:00
option(YYCC_BUILD_TEST "Build test of YYCCommonplace." OFF)
option(YYCC_BUILD_BENCHMARK "Build benchmark of YYCCommonplace." OFF)
2024-06-12 15:48:20 +08:00
option(YYCC_BUILD_DOC "Build document of YYCCommonplace." OFF)
2025-07-15 16:17:59 +08:00
option(YYCC_ENFORCE_ICONV "Enforce iconv support for this library (e.g. in MSYS2 environment)." OFF)
2024-06-06 13:16:55 +08:00
2024-07-22 13:56:00 +08:00
# Setup install path from CMake provided install path for convenient use.
include(GNUInstallDirs)
set(YYCC_INSTALL_INCLUDE_PATH ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH
"Public header install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.")
set(YYCC_INSTALL_LIB_PATH ${CMAKE_INSTALL_LIBDIR} CACHE PATH
"Library install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.")
set(YYCC_INSTALL_BIN_PATH ${CMAKE_INSTALL_BINDIR} CACHE PATH
"Binary install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.")
set(YYCC_INSTALL_DOC_PATH ${CMAKE_INSTALL_DOCDIR} CACHE PATH
"Non-arch doc install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.")
2024-06-20 15:47:15 +08:00
2026-01-23 14:37:21 +08:00
# Test charconv support due to shitty clang's libcxx.
include(${CMAKE_CURRENT_LIST_DIR}/cmake/check_charconv.cmake)
2025-06-20 23:38:34 +08:00
# Include dependency.
2025-09-29 13:34:02 +08:00
# GTest is required if we build test
if (YYCC_BUILD_TEST)
2025-06-20 23:38:34 +08:00
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
find_package(GTest REQUIRED)
endif ()
2025-09-29 13:34:02 +08:00
# Google Benchmark is required if we build benchmark
if (YYCC_BUILD_BENCHMARK)
find_package(benchmark REQUIRED)
endif ()
2026-01-13 15:45:38 +08:00
# Doxygen is required if we build doc
if (YYCC_BUILD_DOC)
find_package(Doxygen REQUIRED)
endif ()
2025-07-15 16:17:59 +08:00
# Iconv is required if we are not in Windows or user request it
if (YYCC_ENFORCE_ICONV OR (NOT WIN32))
find_package(Iconv REQUIRED)
endif ()
2025-06-20 23:38:34 +08:00
2025-09-29 13:34:02 +08:00
# Import 4 build targets
2024-05-29 23:11:52 +08:00
add_subdirectory(src)
2025-09-29 13:34:02 +08:00
if (YYCC_BUILD_TEST)
add_subdirectory(test)
endif ()
if (YYCC_BUILD_BENCHMARK)
add_subdirectory(benchmark)
2024-06-06 13:16:55 +08:00
endif ()
2024-06-12 15:48:20 +08:00
if (YYCC_BUILD_DOC)
add_subdirectory(doc)
endif ()
2024-05-29 23:11:52 +08:00
2024-07-22 13:56:00 +08:00
# Install target and package
# Install target
2024-06-03 14:24:05 +08:00
install(EXPORT YYCCommonplaceTargets
FILE YYCCommonplaceTargets.cmake
NAMESPACE YYCC::
2024-07-22 13:56:00 +08:00
DESTINATION ${YYCC_INSTALL_LIB_PATH}/cmake/YYCCommonplace
2024-06-03 14:24:05 +08:00
)
# Package configuration file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
YYCCommonplaceConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMinorVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/YYCCommonplaceConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/YYCCommonplaceConfig.cmake"
2024-12-23 09:30:39 +08:00
INSTALL_DESTINATION ${YYCC_INSTALL_LIB_PATH}/cmake/YYCCommonplace
2024-06-03 14:24:05 +08:00
)
2024-07-22 13:56:00 +08:00
# Copy package files to install destination
2024-06-03 14:24:05 +08:00
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/YYCCommonplaceConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/YYCCommonplaceConfigVersion.cmake"
DESTINATION
2024-12-23 09:30:39 +08:00
${YYCC_INSTALL_LIB_PATH}/cmake/YYCCommonplace
2024-06-03 14:24:05 +08:00
)