|
| 1 | +# |
| 2 | +# Copyright (c) 2022 alandefreitas (alandefreitas@gmail.com) |
| 3 | +# |
| 4 | +# Distributed under the Boost Software License, Version 1.0. |
| 5 | +# https://www.boost.org/LICENSE_1_0.txt |
| 6 | +# |
| 7 | + |
| 8 | +cmake_minimum_required(VERSION 3.8...3.20) |
| 9 | + |
| 10 | +project(cmake_test LANGUAGES CXX) |
| 11 | +set(__ignore__ ${CMAKE_C_COMPILER}) |
| 12 | +set(__ignore__ ${CMAKE_C_FLAGS}) |
| 13 | + |
| 14 | +if(BOOST_CI_INSTALL_TEST) |
| 15 | + # Boost as a package (https://github.com/boostorg/cmake#using-boost-after-building-and-installing-it-with-cmake) |
| 16 | + find_package(Boost CONFIG REQUIRED COMPONENTS openmethod) |
| 17 | +elseif(BOOST_CI_INSTALL_MODULE_TEST) |
| 18 | + # Boost.OpenMethod as a package |
| 19 | + find_package(boost_openmethod CONFIG REQUIRED) |
| 20 | +elseif(BOOST_CI_BOOST_SUBDIR_TEST) |
| 21 | + # Boost as a subdirectory (https://github.com/boostorg/cmake#using-boost-after-building-and-installing-it-with-cmake) |
| 22 | + if (BUILD_SHARED_LIBS) |
| 23 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) |
| 24 | + endif() |
| 25 | + set(BOOST_OPENMETHOD_BUILD_TESTS OFF CACHE BOOL "Build the tests." FORCE) |
| 26 | + set(PREV_BUILD_TESTING ${BUILD_TESTING}) |
| 27 | + set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE) |
| 28 | + set(BOOST_INCLUDE_LIBRARIES openmethod) |
| 29 | + add_subdirectory(../../../.. boost) |
| 30 | + set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE) |
| 31 | +else() |
| 32 | + # Boost.OpenMethod as a subdirectory (https://github.com/boostorg/cmake#using-an-individual-boost-library-with-add_subdirectory) |
| 33 | + if (BUILD_SHARED_LIBS) |
| 34 | + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) |
| 35 | + endif() |
| 36 | + set(BOOST_OPENMETHOD_BUILD_TESTS OFF CACHE BOOL "Build the tests." FORCE) |
| 37 | + set(BOOST_OPENMETHOD_BUILD_FUZZERS OFF CACHE BOOL "Build the fuzzers." FORCE) |
| 38 | + set(BOOST_OPENMETHOD_BUILD_EXAMPLES OFF CACHE BOOL "Build the examples." FORCE) |
| 39 | + set(PREV_BUILD_TESTING ${BUILD_TESTING}) |
| 40 | + set(BUILD_TESTING OFF CACHE BOOL "Build the tests." FORCE) |
| 41 | + file(GLOB subdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_CURRENT_SOURCE_DIR}/../../../*) |
| 42 | + foreach(subdir ${subdirs}) |
| 43 | + # This is testing the case when the super-project is not available |
| 44 | + # and users want to add libraries as subdirectories. |
| 45 | + # According to the convention above, users should scan all dependencies |
| 46 | + # with boostdep and include each of them with add_subdirectory. |
| 47 | + # For developers, hard-coding all dependencies is impractical |
| 48 | + # and error-prone because the list of transitive dependencies |
| 49 | + # is unstable over time and across Boost versions and branches. |
| 50 | + # For this reason, we list all directories in ../.. and add them |
| 51 | + # as subdirectories. Only directories previously cloned |
| 52 | + # with `depinst.py` in CI will be added. This will unfortunately |
| 53 | + # add test dependencies we don't need. |
| 54 | + if ( |
| 55 | + IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../../${subdir} AND |
| 56 | + EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../../${subdir}/CMakeLists.txt |
| 57 | + ) |
| 58 | + add_subdirectory(../../../${subdir} boostorg/${subdir}) |
| 59 | + endif() |
| 60 | + endforeach() |
| 61 | + if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric) |
| 62 | + # Iterate potential transitive dependencies in libs/numeric |
| 63 | + file(GLOB subdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric/*) |
| 64 | + foreach(subdir ${subdirs}) |
| 65 | + if ( |
| 66 | + IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric/${subdir} AND |
| 67 | + EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../../numeric/${subdir}/CMakeLists.txt |
| 68 | + ) |
| 69 | + add_subdirectory(../../../numeric/${subdir} boostorg/numeric/${subdir}) |
| 70 | + endif() |
| 71 | + endforeach() |
| 72 | + endif() |
| 73 | + set(BUILD_TESTING ${PREV_BUILD_TESTING} CACHE BOOL "Build the tests." FORCE) |
| 74 | +endif() |
| 75 | + |
| 76 | +add_executable(main main.cpp) |
| 77 | +target_link_libraries(main Boost::openmethod) |
| 78 | + |
| 79 | +if (BUILD_TESTING) |
| 80 | + enable_testing() |
| 81 | + add_test(NAME main COMMAND main) |
| 82 | + add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>) |
| 83 | +endif() |
0 commit comments