Skip to content

Commit f0f8ee1

Browse files
committed
Rewrite handling of dependencies to use find_package
Moved all thirdparty handling code (or at least as much as possible) to thirdparty/CMakeLists.txt. Now all dependencies are searched using standard find_package() calls first, and if not found the config falls back to use the appropiate submodule. Also, updated gtest version (Latest gtest versions include a cmake setup, which simplifies the config {no build external project script needneeded}), and variant-lite to the latest release.
1 parent 169d038 commit f0f8ee1

File tree

3 files changed

+84
-35
lines changed

3 files changed

+84
-35
lines changed

CMakeLists.txt

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ else ()
2929

3030
endif()
3131

32-
set(BOOST_CMAKE_LIBRARIES filesystem algorithm variant optional CACHE INTERNAL "")
33-
add_subdirectory(thirdparty/boost EXCLUDE_FROM_ALL)
34-
add_subdirectory(thirdparty/nonstd EXCLUDE_FROM_ALL)
32+
add_subdirectory(thirdparty)
3533

3634
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
3735
set(JINJA2CPP_IS_MAIN_PROEJCT TRUE)
@@ -54,35 +52,18 @@ add_library(${LIB_TARGET_NAME} STATIC
5452
${PublicHeaders}
5553
)
5654

57-
target_link_libraries(${LIB_TARGET_NAME} PUBLIC ThirdParty::nonstd boost_variant boost_filesystem boost_algorithm)
55+
target_link_libraries(${LIB_TARGET_NAME} PUBLIC expected-lite variant-lite value-ptr-lite boost_variant boost_filesystem boost_algorithm)
5856

5957
target_include_directories(${LIB_TARGET_NAME}
6058
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
6159

6260

6361
if(NOT MSVC)
64-
# Enable -Werror and -Wall on jinja2cpp target, ignoring warning errors from thirdparty libs
65-
include(CheckCXXCompilerFlag)
66-
check_cxx_compiler_flag(-Wno-error=parentheses COMPILER_HAS_WNO_ERROR_PARENTHESES_FLAG)
67-
check_cxx_compiler_flag(-Wno-error=deprecated-declarations COMPILER_HAS_WNO_ERROR_DEPRECATED_DECLARATIONS_FLAG)
68-
check_cxx_compiler_flag(-Wno-error=maybe-uninitialized COMPILER_HAS_WNO_ERROR_MAYBE_UNINITIALIZED_FLAG)
69-
70-
if(COMPILER_HAS_WNO_ERROR_PARENTHESES_FLAG)
71-
target_compile_options(boost_assert INTERFACE -Wno-error=parentheses)
72-
endif()
73-
if(COMPILER_HAS_WNO_ERROR_DEPRECATED_DECLARATIONS_FLAG)
74-
target_compile_options(boost_filesystem PRIVATE -Wno-error=deprecated-declarations)
75-
endif()
76-
if(COMPILER_HAS_WNO_ERROR_MAYBE_UNINITIALIZED_FLAG)
77-
target_compile_options(boost_variant INTERFACE -Wno-error=maybe-uninitialized)
78-
endif()
79-
8062
target_compile_options(${LIB_TARGET_NAME} PRIVATE -Wall -Werror)
8163
endif()
8264

8365
if (JINJA2CPP_BUILD_TESTS)
8466
enable_testing()
85-
add_subdirectory(thirdparty/gtest)
8667

8768
CollectSources(TestSources TestHeaders ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/test)
8869
add_executable(jinja2cpp_tests ${TestSources} ${TestHeaders})

thirdparty/CMakeLists.txt

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,85 @@
1-
cmake_minimum_required(VERSION 3.0)
21

3-
project (thirdparty)
4-
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
2+
find_package(expected-lite QUIET)
3+
if(expected-lite_FOUND)
4+
add_library(expected-lite ALIAS expected-lite::expected-lite)
5+
else()
6+
message(STATUS "expected-lite not found, using submodule")
7+
add_subdirectory(nonstd/expected-light EXCLUDE_FROM_ALL)
8+
endif()
59

6-
include (build_thirdparty)
10+
find_package(variant-lite QUIET)
11+
if(variant-lite_FOUND)
12+
add_library(variant-lite ALIAS variant-lite::variant-lite)
13+
else()
14+
message(STATUS "variant-lite not found, using submodule")
15+
add_subdirectory(nonstd/variant-light EXCLUDE_FROM_ALL)
16+
# There's a bug in the lib, the target does not include the header include dirs.
17+
# See https://github.com/martinmoene/variant-lite/issues/25
18+
target_include_directories(variant-lite INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/nonstd/variant-light/include")
19+
endif()
720

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 ()
21+
find_package(value-ptr-lite QUIET)
22+
if(value-ptr-lite_FOUND)
23+
add_library(value-ptr-lite ALIAS value-ptr-lite::value-ptr-lite)
24+
else()
25+
message(STATUS "value-ptr-lite not found, using submodule")
26+
add_subdirectory(nonstd/value-ptr-lite EXCLUDE_FROM_ALL)
27+
add_library(value-ptr-lite ALIAS value_ptr-lite)
28+
endif()
1529

16-
BuildThirdparty(gtest ${CMAKE_CURRENT_SOURCE_DIR}/gtest include/gmock/gmock.h "${GTEST_EXTRA_OPTIONS}")
17-
add_subdirectory (nonstd)
30+
find_package(boost_filesystem QUIET)
31+
find_package(boost_algorithm QUIET)
32+
find_package(boost_variant QUIET)
33+
find_package(boost_optional QUIET)
34+
35+
if(boost_filesystem_FOUND AND
36+
boost_algorithm_FOUND AND
37+
boost_variant_FOUND AND
38+
boost_optional_FOUND)
39+
add_library(boost_filesystem ALIAS boost_filesystem::boost_filesystem)
40+
add_library(boost_algorithm ALIAS boost_algorithm::boost_algorithm)
41+
add_library(boost_variant ALIAS boost_variant::boost_variant)
42+
add_library(boost_optional ALIAS boost_optional::boost_optional)
43+
else()
44+
message(STATUS "One or more boost modules not found, using submodule")
45+
set(BOOST_CMAKE_LIBRARIES filesystem algorithm variant optional CACHE INTERNAL "")
46+
add_subdirectory(boost EXCLUDE_FROM_ALL)
47+
48+
if(NOT MSVC)
49+
# Enable -Werror and -Wall on jinja2cpp target, ignoring warning errors from thirdparty libs
50+
include(CheckCXXCompilerFlag)
51+
check_cxx_compiler_flag(-Wno-error=parentheses COMPILER_HAS_WNO_ERROR_PARENTHESES_FLAG)
52+
check_cxx_compiler_flag(-Wno-error=deprecated-declarations COMPILER_HAS_WNO_ERROR_DEPRECATED_DECLARATIONS_FLAG)
53+
check_cxx_compiler_flag(-Wno-error=maybe-uninitialized COMPILER_HAS_WNO_ERROR_MAYBE_UNINITIALIZED_FLAG)
54+
55+
if(COMPILER_HAS_WNO_ERROR_PARENTHESES_FLAG)
56+
target_compile_options(boost_assert INTERFACE -Wno-error=parentheses)
57+
endif()
58+
if(COMPILER_HAS_WNO_ERROR_DEPRECATED_DECLARATIONS_FLAG)
59+
target_compile_options(boost_filesystem PRIVATE -Wno-error=deprecated-declarations)
60+
endif()
61+
if(COMPILER_HAS_WNO_ERROR_MAYBE_UNINITIALIZED_FLAG)
62+
target_compile_options(boost_variant INTERFACE -Wno-error=maybe-uninitialized)
63+
endif()
64+
endif()
65+
endif()
66+
67+
if(JINJA2CPP_BUILD_TESTS)
68+
find_package(gtest QUIET)
69+
70+
if(gtest_FOUND)
71+
add_library(gtest ALIAS gtest::gtest)
72+
else()
73+
message(STATUS "expected-lite not found, using submodule")
74+
75+
if(MSVC)
76+
if (MSVC_RUNTIME_TYPE STREQUAL "/MD" OR NOT MSVC_RUNTIME_TYPE)
77+
set (GTEST_EXTRA_OPTIONS "-Dgtest_force_shared_crt=TRUE" CACHE INTERNAL "")
78+
else ()
79+
set (GTEST_EXTRA_OPTIONS "-Dgtest_force_shared_crt=TRUE" CACHE INTERNAL "")
80+
endif ()
81+
endif ()
82+
83+
add_subdirectory(gtest EXCLUDE_FROM_ALL)
84+
endif()
85+
endif()

thirdparty/gtest

Submodule gtest updated 227 files

0 commit comments

Comments
 (0)