@@ -4,9 +4,29 @@ function(update_submodule submodule)
44 WORKING_DIRECTORY "${PROJECT_SOURCE_DIR} " )
55endfunction ()
66
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
11+
12+ cmake_parse_arguments ("__ALIAS"
13+ ""
14+ "ALIAS"
15+ ""
16+ ${ARGN}
17+ )
18+
19+ if (NOT __ALIAS_ALIAS)
20+ message (FATAL_ERROR "imported_target_alias invoked with wrong arguments, missing ALIAS" )
21+ endif ()
22+
23+ add_library (${ALIAS} INTERFACE )
24+ target_link_libraries (${ALIAS} INTERFACE ${__ALIAS_ALIAS} )
25+ endfunction ()
26+
727find_package (expected-lite QUIET )
828if (expected-lite_FOUND)
9- add_library (expected-lite ALIAS expected-lite::expected-lite)
29+ imported_target_alias (expected-lite ALIAS expected-lite::expected-lite)
1030else ()
1131 message (STATUS "expected-lite not found, using submodule" )
1232 update_submodule(nonstd/expected-light)
@@ -15,7 +35,7 @@ endif()
1535
1636find_package (variant-lite QUIET )
1737if (variant-lite_FOUND)
18- add_library (variant-lite ALIAS variant-lite::variant-lite)
38+ imported_target_alias (variant-lite ALIAS variant-lite::variant-lite)
1939else ()
2040 message (STATUS "variant-lite not found, using submodule" )
2141 update_submodule(nonstd/variant-light)
@@ -27,7 +47,7 @@ endif()
2747
2848find_package (value -ptr-lite QUIET )
2949if (value -ptr-lite_FOUND)
30- add_library (value -ptr-lite ALIAS value -ptr-lite::value -ptr-lite)
50+ imported_target_alias (value -ptr-lite ALIAS value -ptr-lite::value -ptr-lite)
3151else ()
3252 message (STATUS "value-ptr-lite not found, using submodule" )
3353 update_submodule(nonstd/value -ptr-lite)
@@ -44,10 +64,10 @@ if(boost_filesystem_FOUND AND
4464 boost_algorithm_FOUND AND
4565 boost_variant_FOUND AND
4666 boost_optional_FOUND)
47- add_library (boost_filesystem ALIAS boost_filesystem::boost_filesystem)
48- add_library (boost_algorithm ALIAS boost_algorithm::boost_algorithm)
49- add_library (boost_variant ALIAS boost_variant::boost_variant)
50- add_library (boost_optional ALIAS boost_optional::boost_optional)
67+ imported_target_alias (boost_filesystem ALIAS boost_filesystem::boost_filesystem)
68+ imported_target_alias (boost_algorithm ALIAS boost_algorithm::boost_algorithm)
69+ imported_target_alias (boost_variant ALIAS boost_variant::boost_variant)
70+ imported_target_alias (boost_optional ALIAS boost_optional::boost_optional)
5171else ()
5272 message (STATUS "One or more boost modules not found, using submodule" )
5373 update_submodule(boost)
@@ -77,7 +97,7 @@ if(JINJA2CPP_BUILD_TESTS)
7797 find_package (gtest QUIET )
7898
7999 if (gtest_FOUND)
80- add_library (gtest ALIAS gtest::gtest)
100+ imported_target_alias (gtest ALIAS gtest::gtest)
81101 else ()
82102 message (STATUS "expected-lite not found, using submodule" )
83103 update_submodule(gtest)
0 commit comments