Skip to content

Commit c753245

Browse files
authored
Merge pull request #77 from Manu343726/master
Conan.io recipe, thirdparty with find_package(), etc
2 parents 169d038 + abca5dd commit c753245

File tree

3 files changed

+123
-35
lines changed

3 files changed

+123
-35
lines changed

CMakeLists.txt

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ 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)
3532

3633
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
3734
set(JINJA2CPP_IS_MAIN_PROEJCT TRUE)
@@ -54,35 +51,20 @@ add_library(${LIB_TARGET_NAME} STATIC
5451
${PublicHeaders}
5552
)
5653

57-
target_link_libraries(${LIB_TARGET_NAME} PUBLIC ThirdParty::nonstd boost_variant boost_filesystem boost_algorithm)
54+
add_subdirectory(thirdparty)
55+
56+
target_link_libraries(${LIB_TARGET_NAME} PUBLIC expected-lite variant-lite value-ptr-lite optional-lite boost_variant boost_filesystem boost_algorithm)
5857

5958
target_include_directories(${LIB_TARGET_NAME}
6059
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
6160

6261

6362
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-
8063
target_compile_options(${LIB_TARGET_NAME} PRIVATE -Wall -Werror)
8164
endif()
8265

8366
if (JINJA2CPP_BUILD_TESTS)
8467
enable_testing()
85-
add_subdirectory(thirdparty/gtest)
8668

8769
CollectSources(TestSources TestHeaders ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/test)
8870
add_executable(jinja2cpp_tests ${TestSources} ${TestHeaders})

thirdparty/CMakeLists.txt

Lines changed: 119 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,123 @@
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()
26

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
511

6-
include (build_thirdparty)
12+
cmake_parse_arguments("__ALIAS"
13+
""
14+
"ALIAS"
15+
""
16+
${ARGN}
17+
)
718

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()
1522

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()

thirdparty/gtest

Submodule gtest updated 227 files

0 commit comments

Comments
 (0)