|
1 | | -cmake_minimum_required(VERSION 3.0) |
| 1 | +function(update_submodule submodule) |
| 2 | + find_package(Git REQUIRED) |
| 3 | + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init thirdparty/${submodule} |
| 4 | + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}") |
| 5 | +endfunction() |
2 | 6 |
|
3 | | -project (thirdparty) |
4 | | -list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) |
| 7 | +function(imported_target_alias ALIAS) |
| 8 | + # For some unknown reason CMake does not support creating alias |
| 9 | + # libraries from IMPORTED libraries. This function is an ugly workaround |
| 10 | + # to get the same |
5 | 11 |
|
6 | | -include (build_thirdparty) |
| 12 | + cmake_parse_arguments("__ALIAS" |
| 13 | + "" |
| 14 | + "ALIAS" |
| 15 | + "" |
| 16 | + ${ARGN} |
| 17 | + ) |
7 | 18 |
|
8 | | -if (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") |
9 | | - if (MSVC_RUNTIME_TYPE STREQUAL "/MD" OR NOT MSVC_RUNTIME_TYPE) |
10 | | - set (GTEST_EXTRA_OPTIONS "-Dgtest_force_shared_crt=TRUE") |
11 | | - else () |
12 | | - set (GTEST_EXTRA_OPTIONS "-Dgtest_force_shared_crt=TRUE") |
13 | | - endif () |
14 | | -endif () |
| 19 | + if(NOT __ALIAS_ALIAS) |
| 20 | + message(FATAL_ERROR "imported_target_alias invoked with wrong arguments, missing ALIAS") |
| 21 | + endif() |
15 | 22 |
|
16 | | -BuildThirdparty(gtest ${CMAKE_CURRENT_SOURCE_DIR}/gtest include/gmock/gmock.h "${GTEST_EXTRA_OPTIONS}") |
17 | | -add_subdirectory (nonstd) |
| 23 | + add_library(${ALIAS} INTERFACE) |
| 24 | + target_link_libraries(${ALIAS} INTERFACE ${__ALIAS_ALIAS}) |
| 25 | +endfunction() |
| 26 | + |
| 27 | +find_package(expected-lite QUIET) |
| 28 | +if(expected-lite_FOUND) |
| 29 | + imported_target_alias(expected-lite ALIAS expected-lite::expected-lite) |
| 30 | +else() |
| 31 | + message(STATUS "expected-lite not found, using submodule") |
| 32 | + update_submodule(nonstd/expected-light) |
| 33 | + add_subdirectory(nonstd/expected-light EXCLUDE_FROM_ALL) |
| 34 | +endif() |
| 35 | + |
| 36 | +find_package(variant-lite QUIET) |
| 37 | +find_package(optional-lite QUIET) |
| 38 | +if(variant-lite_FOUND AND optional-lite_FOUND) |
| 39 | + imported_target_alias(variant-lite ALIAS variant-lite::variant-lite) |
| 40 | + imported_target_alias(optional-lite ALIAS optional-lite::optional-lite) |
| 41 | +else() |
| 42 | + message(STATUS "variant-lite or optional-lite not found, using submodule") |
| 43 | + update_submodule(nonstd/variant-light) |
| 44 | + add_subdirectory(nonstd/variant-light EXCLUDE_FROM_ALL) |
| 45 | + # There's a bug in the lib, the target does not include the header include dirs. |
| 46 | + # See https://github.com/martinmoene/variant-lite/issues/25 |
| 47 | + target_include_directories(variant-lite INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/nonstd/variant-light/include") |
| 48 | + |
| 49 | + # Fake target until we use separated optional-lite as submodule |
| 50 | + # See https://github.com/martinmoene/variant-lite/issues/19 |
| 51 | + add_library(optional-lite ALIAS variant-lite) |
| 52 | +endif() |
| 53 | + |
| 54 | +find_package(value-ptr-lite QUIET) |
| 55 | +if(value-ptr-lite_FOUND) |
| 56 | + imported_target_alias(value-ptr-lite ALIAS value-ptr-lite::value-ptr-lite) |
| 57 | +else() |
| 58 | + message(STATUS "value-ptr-lite not found, using submodule") |
| 59 | + update_submodule(nonstd/value-ptr-lite) |
| 60 | + add_subdirectory(nonstd/value-ptr-lite EXCLUDE_FROM_ALL) |
| 61 | + |
| 62 | + add_library(value-ptr-lite ALIAS value_ptr-lite) |
| 63 | +endif() |
| 64 | + |
| 65 | +find_package(boost_filesystem QUIET) |
| 66 | +find_package(boost_algorithm QUIET) |
| 67 | +find_package(boost_variant QUIET) |
| 68 | +find_package(boost_optional QUIET) |
| 69 | + |
| 70 | +if(boost_filesystem_FOUND AND |
| 71 | + boost_algorithm_FOUND AND |
| 72 | + boost_variant_FOUND AND |
| 73 | + boost_optional_FOUND) |
| 74 | + imported_target_alias(boost_filesystem ALIAS boost_filesystem::boost_filesystem) |
| 75 | + imported_target_alias(boost_algorithm ALIAS boost_algorithm::boost_algorithm) |
| 76 | + imported_target_alias(boost_variant ALIAS boost_variant::boost_variant) |
| 77 | + imported_target_alias(boost_optional ALIAS boost_optional::boost_optional) |
| 78 | +else() |
| 79 | + message(STATUS "One or more boost modules not found, using submodule") |
| 80 | + update_submodule(boost) |
| 81 | + list(APPEND BOOST_CMAKE_LIBRARIES filesystem algorithm variant optional) |
| 82 | + set(BOOST_CMAKE_LIBRARIES ${BOOST_CMAKE_LIBRARIES} CACHE INTERNAL "") |
| 83 | + add_subdirectory(boost EXCLUDE_FROM_ALL) |
| 84 | + |
| 85 | + if(NOT MSVC) |
| 86 | + # Enable -Werror and -Wall on jinja2cpp target, ignoring warning errors from thirdparty libs |
| 87 | + include(CheckCXXCompilerFlag) |
| 88 | + check_cxx_compiler_flag(-Wno-error=parentheses COMPILER_HAS_WNO_ERROR_PARENTHESES_FLAG) |
| 89 | + check_cxx_compiler_flag(-Wno-error=deprecated-declarations COMPILER_HAS_WNO_ERROR_DEPRECATED_DECLARATIONS_FLAG) |
| 90 | + check_cxx_compiler_flag(-Wno-error=maybe-uninitialized COMPILER_HAS_WNO_ERROR_MAYBE_UNINITIALIZED_FLAG) |
| 91 | + |
| 92 | + if(COMPILER_HAS_WNO_ERROR_PARENTHESES_FLAG) |
| 93 | + target_compile_options(boost_assert INTERFACE -Wno-error=parentheses) |
| 94 | + endif() |
| 95 | + if(COMPILER_HAS_WNO_ERROR_DEPRECATED_DECLARATIONS_FLAG) |
| 96 | + target_compile_options(boost_filesystem PRIVATE -Wno-error=deprecated-declarations) |
| 97 | + endif() |
| 98 | + if(COMPILER_HAS_WNO_ERROR_MAYBE_UNINITIALIZED_FLAG) |
| 99 | + target_compile_options(boost_variant INTERFACE -Wno-error=maybe-uninitialized) |
| 100 | + endif() |
| 101 | + endif() |
| 102 | +endif() |
| 103 | + |
| 104 | +if(JINJA2CPP_BUILD_TESTS) |
| 105 | + find_package(gtest QUIET) |
| 106 | + |
| 107 | + if(gtest_FOUND) |
| 108 | + imported_target_alias(gtest ALIAS gtest::gtest) |
| 109 | + else() |
| 110 | + message(STATUS "expected-lite not found, using submodule") |
| 111 | + update_submodule(gtest) |
| 112 | + |
| 113 | + if(MSVC) |
| 114 | + if (MSVC_RUNTIME_TYPE STREQUAL "/MD" OR NOT MSVC_RUNTIME_TYPE) |
| 115 | + set (GTEST_EXTRA_OPTIONS "-Dgtest_force_shared_crt=TRUE" CACHE INTERNAL "") |
| 116 | + else () |
| 117 | + set (GTEST_EXTRA_OPTIONS "-Dgtest_force_shared_crt=TRUE" CACHE INTERNAL "") |
| 118 | + endif () |
| 119 | + endif () |
| 120 | + |
| 121 | + add_subdirectory(gtest EXCLUDE_FROM_ALL) |
| 122 | + endif() |
| 123 | +endif() |
0 commit comments