-
Notifications
You must be signed in to change notification settings - Fork 7
build(cmake)!: Add support for installation and usage as a library in other CMake projects; Add example project to test this use case. #65
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
Changes from 97 commits
dec0712
4aa941c
662e768
93c4d50
0a88c49
e4dc708
a3bc9d5
601c462
2e54cdb
f5e2b4b
89f53c1
1d313c3
2f9f30b
a63a4f2
847162f
5e55b58
77fc7ea
521c1f9
1c44077
c8a3c93
ef48733
f62ee82
7a625e7
277dc1d
f25859e
e94d6ae
36ab649
cafa9be
134b1e0
487844d
96b2811
07df644
9a7400c
caff1ae
630d389
6c55590
7f2745f
93b4a70
3ab6484
f449cce
b1243ed
d14bfdb
aea57aa
729db5c
43ee6cc
c4e67c4
cd7b3aa
2dbca54
22a27c8
56470ad
8183762
1e5b9bc
e9cbd7c
596beb5
28916c0
a9f7054
b329870
7c62982
1633044
ed60a76
d351128
ebb9984
95cb0a0
5b944b0
962c1e0
7198859
edecfb2
30ba595
0395b33
bb56c10
346dcfe
5a404d5
2de6525
f02a658
1637b6e
0688e49
0e0651e
7133493
1e7cd87
24ea39a
64f3929
7687b09
2066564
7d89e7e
8453a16
dbd5f01
e72fb28
5e83d4e
913bdc1
6bf405e
bda1ea0
cfee30e
6cd8c8b
a9a73e0
461fa47
fc773c1
9a4099c
1a0c6df
ae147cd
b75247d
2af9ed7
4d81820
7b32ab0
550d683
a6d8f2b
f544f70
db7d25a
f13a591
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,73 +1,76 @@ | ||
| cmake_minimum_required(VERSION 3.22.1) | ||
| cmake_minimum_required(VERSION 3.23) | ||
|
|
||
| list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") | ||
| include(ystdlib-cpp-helpers) | ||
| project(ystdlib VERSION "0.1.0" LANGUAGES CXX) | ||
|
|
||
| project(YSTDLIB_CPP LANGUAGES CXX) | ||
|
|
||
| set(YSTDLIB_CPP_VERSION "0.0.1" CACHE STRING "Project version.") | ||
| list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") | ||
| include(CMakePackageConfigHelpers) | ||
| include(GNUInstallDirs) | ||
| include(ystdlib-helpers) | ||
|
|
||
| option(BUILD_SHARED_LIBS "Build using shared libraries." OFF) | ||
| option(YSTDLIB_CPP_BUILD_TESTING "Build the testing tree for ystdlib-cpp." ON) | ||
| option(ystdlib_BUILD_TESTING "Build the testing tree for ystdlib." ON) | ||
|
|
||
| # Require compiler versions that support the C++20 features necessary for compiling ystdlib-cpp | ||
| # Require compiler versions that support the C++20 features necessary for compiling ystdlib | ||
| if("AppleClang" STREQUAL "${CMAKE_CXX_COMPILER_ID}") | ||
| set(YSTDLIB_CPP_CMAKE_CXX_COMPILER_MIN_VERSION "16") | ||
| set(ystdlib_CMAKE_CXX_COMPILER_MIN_VERSION "16") | ||
| elseif("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID}") | ||
| set(YSTDLIB_CPP_CMAKE_CXX_COMPILER_MIN_VERSION "16") | ||
| set(ystdlib_CMAKE_CXX_COMPILER_MIN_VERSION "16") | ||
| elseif("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID}") | ||
| set(YSTDLIB_CPP_CMAKE_CXX_COMPILER_MIN_VERSION "11") | ||
| set(ystdlib_CMAKE_CXX_COMPILER_MIN_VERSION "11") | ||
davidlion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else() | ||
| message( | ||
| FATAL_ERROR | ||
| "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}. Please use AppleClang, Clang, or GNU." | ||
| ) | ||
| endif() | ||
| if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "${YSTDLIB_CPP_CMAKE_CXX_COMPILER_MIN_VERSION}") | ||
| if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "${ystdlib_CMAKE_CXX_COMPILER_MIN_VERSION}") | ||
| message( | ||
| FATAL_ERROR | ||
| "${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION} is too low. Must be at \ | ||
| least ${YSTDLIB_CPP_CMAKE_CXX_COMPILER_MIN_VERSION}." | ||
| least ${ystdlib_CMAKE_CXX_COMPILER_MIN_VERSION}." | ||
davidlion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
davidlion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| endif() | ||
davidlion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Enable exporting compile commands | ||
| set(CMAKE_EXPORT_COMPILE_COMMANDS | ||
| ON | ||
| CACHE BOOL | ||
| "Enable/Disable output of compile commands during generation." | ||
| FORCE | ||
| ) | ||
|
|
||
| if(YSTDLIB_CPP_IS_TOP_LEVEL) | ||
| set(ystdlib_LIBRARIES | ||
| "containers" | ||
| "error_handling" | ||
| "io_interface" | ||
| "wrapped_facade_headers" | ||
| CACHE STRING | ||
| "Semicolon-separated list of libraries to be built." | ||
| ) | ||
davidlion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| message(STATUS "Building the following libraries:") | ||
| foreach(LIB IN LISTS ystdlib_LIBRARIES) | ||
| message(STATUS " - ${LIB}") | ||
| endforeach() | ||
|
|
||
| if(ystdlib_IS_TOP_LEVEL) | ||
| # Include dependency settings if the project isn't being included as a subproject. | ||
| # NOTE: We mark the file optional because if the user happens to have the dependencies | ||
| # installed, this file is not necessary. | ||
| include("build/deps/cmake-settings/settings.cmake" OPTIONAL) | ||
| include("build/deps/cmake-settings/all.cmake" OPTIONAL) | ||
|
|
||
davidlion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # If previously undefined, `BUILD_TESTING` will be set to ON. | ||
| include(CTest) | ||
| endif() | ||
davidlion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if(BUILD_TESTING AND YSTDLIB_CPP_BUILD_TESTING) | ||
| set(YSTDLIB_CPP_ENABLE_TESTS ON) | ||
| if(BUILD_TESTING AND ystdlib_BUILD_TESTING) | ||
| set(ystdlib_ENABLE_TESTS ON) | ||
| endif() | ||
|
|
||
| find_package(Boost REQUIRED) | ||
| if(Boost_FOUND) | ||
| message(STATUS "Found Boost ${Boost_VERSION}.") | ||
| endif() | ||
|
|
||
| if(YSTDLIB_CPP_ENABLE_TESTS) | ||
| if(ystdlib_ENABLE_TESTS) | ||
| find_package(Catch2 3.8.0 REQUIRED) | ||
| if(Catch2_FOUND) | ||
| message(STATUS "Found Catch2 ${Catch2_VERSION}.") | ||
| else() | ||
| message(FATAL_ERROR "Could not find libraries for Catch2.") | ||
| endif() | ||
| message(STATUS "Found Catch2 ${Catch2_VERSION}.") | ||
| include(Catch) | ||
|
Comment on lines
+65
to
72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard use of
Add a default: if(NOT DEFINED BUILD_TESTING)
set(BUILD_TESTING OFF)
endif()before the 🤖 Prompt for AI Agents |
||
|
|
||
| # Set up the unified unit test target | ||
| set(UNIFIED_UNIT_TEST_TARGET "unit-test-all") | ||
| add_executable(${UNIFIED_UNIT_TEST_TARGET}) | ||
| target_link_libraries(${UNIFIED_UNIT_TEST_TARGET} PRIVATE Catch2::Catch2WithMain) | ||
|
|
@@ -82,4 +85,27 @@ if(YSTDLIB_CPP_ENABLE_TESTS) | |
| catch_discover_tests(${UNIFIED_UNIT_TEST_TARGET} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/testbin) | ||
| endif() | ||
|
|
||
| # All libraries are required to use the same minimum version of dependencies to avoid issues. | ||
davidlion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| set(MIN_BOOST_VERSOIN "1.81.0") | ||
davidlion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| add_subdirectory(src/ystdlib) | ||
|
|
||
| set(ystdlib_INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/ystdlib) | ||
|
|
||
| set(CONFIG_FILE_PREFIX "ystdlib-config") | ||
| set(CONFIG_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_FILE_PREFIX}.cmake") | ||
| set(CONFIG_VERSION_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_FILE_PREFIX}-version.cmake") | ||
| configure_package_config_file( | ||
| "${CMAKE_CURRENT_LIST_DIR}/cmake/${CONFIG_FILE_PREFIX}.cmake.in" | ||
| "${CONFIG_OUTPUT_PATH}" | ||
| INSTALL_DESTINATION "${ystdlib_INSTALL_CONFIG_DIR}" | ||
| ) | ||
davidlion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| write_basic_package_version_file("${CONFIG_VERSION_OUTPUT_PATH}" COMPATIBILITY SameMajorVersion) | ||
|
|
||
| install( | ||
| FILES | ||
| "${CONFIG_OUTPUT_PATH}" | ||
| "${CONFIG_VERSION_OUTPUT_PATH}" | ||
| DESTINATION "${ystdlib_INSTALL_CONFIG_DIR}" | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.