Skip to content

Commit 5bcf3b9

Browse files
committed
Merge pull request #119
Add Variable for List of Dependency Link Targets Signed-off-by: kilo52 <[email protected]>
2 parents 8be116b + 4f08b28 commit 5bcf3b9

File tree

10 files changed

+106
-9
lines changed

10 files changed

+106
-9
lines changed

c/01_executable/source/src/main/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ target_include_directories(
1717
c
1818
)
1919

20+
target_link_libraries(
21+
${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE
22+
PRIVATE
23+
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
24+
)
25+
2026
enable_compiler_warnings(
2127
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE}
2228
${${{VAR_PROJECT_NAME_UPPER}}_IGNORE_WARNINGS}

c/02_library/source/src/main/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ target_include_directories(
4141
c
4242
)
4343

44+
target_link_libraries(
45+
${{VAR_PROJECT_NAME_UPPER}}_TARGET_LIB_MAIN
46+
PRIVATE
47+
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
48+
)
49+
4450
set_target_properties(
4551
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_LIB_MAIN}
4652
PROPERTIES

cpp/01_executable/source/src/main/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ target_include_directories(
1717
cpp
1818
)
1919

20+
target_link_libraries(
21+
${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE
22+
PRIVATE
23+
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
24+
)
25+
2026
enable_compiler_warnings(
2127
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE}
2228
${${{VAR_PROJECT_NAME_UPPER}}_IGNORE_WARNINGS}

cpp/02_library/source/src/main/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ target_include_directories(
4141
cpp
4242
)
4343

44+
target_link_libraries(
45+
${{VAR_PROJECT_NAME_UPPER}}_TARGET_LIB_MAIN
46+
PRIVATE
47+
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
48+
)
49+
4450
set_target_properties(
4551
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_LIB_MAIN}
4652
PROPERTIES

cpp/03_server-poco/source/Dependencies.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dependency(
44
DEPENDENCY_NAME poco
55
DEPENDENCY_RESOURCE pocoproject/poco
66
DEPENDENCY_VERSION poco-1.14.2-release
7+
DEPENDENCY_LINK_TARGETS Poco::XML Poco::JSON Poco::Net Poco::Util
78
)
89

910
${{INCLUDE:cpp/cmake/DependenciesCommon.cmake}}

cpp/03_server-poco/source/src/net/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ target_include_directories(
4242

4343
target_link_libraries(
4444
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_NET_CORE}
45-
Poco::XML
46-
Poco::JSON
47-
Poco::Net
48-
Poco::Util
45+
PUBLIC
46+
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
4947
)
5048

5149

cpp/04_desktop_imgui/source/Dependencies.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependency(
1111
DEPENDENCY_NAME glfw
1212
DEPENDENCY_RESOURCE glfw/glfw
1313
DEPENDENCY_VERSION 3.4
14+
DEPENDENCY_LINK_TARGETS glfw
1415
)
1516

1617
${{INCLUDE:cpp/cmake/DependenciesCommon.cmake}}

cpp/04_desktop_imgui/source/src/main/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ endif()
4444
target_link_libraries(
4545
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE}
4646
PUBLIC
47-
glfw
4847
${${{VAR_PROJECT_NAME_UPPER}}_PLATFORM_LINK_LIBRARIES}
48+
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
4949
)
5050

5151
if(${{VAR_PROJECT_NAME_UPPER}}_USE_SANITIZERS)

share/c/cmake/DependencyUtil.cmake

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ include(FetchContent)
152152
# to build the dependency. This argument can optionally be used to
153153
# specify a file which deviates from the convention.
154154
#
155+
# [multiValueArgs]
156+
#
157+
# DEPENDENCY_LINK_TARGETS:
158+
# A list of target names that should be registered as link targets when
159+
# consuming the dependency. This argument is optional. When specified,
160+
# the provided names represent CMake targets that are made available to
161+
# the underlying project by the dependency. These target names are then
162+
# appended to the global variable ${PROJECT}_DEPENDENCIES_LINK_TARGETS
163+
# where ${PROJECT} is the name in all caps of the underlying project as
164+
# given to the CMake project() function. A dependency with "TEST" scope
165+
# is never added to that list.
166+
#
155167
# [options]
156168
#
157169
# DEPENDENCY_QUIET:
@@ -201,7 +213,9 @@ function(dependency)
201213
DEPENDENCY_CONFIG_FILE
202214
DEPENDENCY_BUILD_FILE
203215
)
204-
set(multiValueArgs "")
216+
set(multiValueArgs
217+
DEPENDENCY_LINK_TARGETS
218+
)
205219

206220
cmake_parse_arguments(
207221
DEP_ARGS
@@ -488,8 +502,9 @@ function(dependency)
488502
endif()
489503
endif()
490504

491-
# Append dependency name to a tracked global cached list
505+
# Check tracked identifiers
492506
if(DEPENDENCY_SCOPE IN_LIST DEP_TRACKED_SCOPES)
507+
# Append dependency name to a tracked global cached list
493508
set(PROJECT_DEPENDENCIES_LIST ${PROJECT_NAME_UPPER}_DEPENDENCIES_LIST)
494509
set(_dep_list "${${PROJECT_DEPENDENCIES_LIST}}")
495510
list(FIND _dep_list "${DEP_ARGS_DEPENDENCY_NAME}" _dep_idx)
@@ -503,5 +518,26 @@ function(dependency)
503518
FORCE
504519
)
505520
endif()
521+
522+
# Append dependency link targets to a tracked global cached list
523+
if(DEP_ARGS_DEPENDENCY_LINK_TARGETS)
524+
set(PROJECT_DEPENDENCIES_LINK_TARGETS
525+
${PROJECT_NAME_UPPER}_DEPENDENCIES_LINK_TARGETS
526+
)
527+
set(_dep_link_list "${${PROJECT_DEPENDENCIES_LINK_TARGETS}}")
528+
foreach(_link_item IN ITEMS ${DEP_ARGS_DEPENDENCY_LINK_TARGETS})
529+
list(FIND _dep_link_list "${_link_item}" _dep_idx)
530+
if(_dep_idx EQUAL -1)
531+
list(APPEND _dep_link_list "${_link_item}")
532+
endif()
533+
endforeach()
534+
set(${PROJECT_DEPENDENCIES_LINK_TARGETS}
535+
${_dep_link_list}
536+
CACHE STRING
537+
"List of link targets of all dependencies"
538+
FORCE
539+
)
540+
endif()
506541
endif()
542+
507543
endfunction()

share/cpp/cmake/DependencyUtil.cmake

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ include(FetchContent)
152152
# to build the dependency. This argument can optionally be used to
153153
# specify a file which deviates from the convention.
154154
#
155+
# [multiValueArgs]
156+
#
157+
# DEPENDENCY_LINK_TARGETS:
158+
# A list of target names that should be registered as link targets when
159+
# consuming the dependency. This argument is optional. When specified,
160+
# the provided names represent CMake targets that are made available to
161+
# the underlying project by the dependency. These target names are then
162+
# appended to the global variable ${PROJECT}_DEPENDENCIES_LINK_TARGETS
163+
# where ${PROJECT} is the name in all caps of the underlying project as
164+
# given to the CMake project() function. A dependency with "TEST" scope
165+
# is never added to that list.
166+
#
155167
# [options]
156168
#
157169
# DEPENDENCY_QUIET:
@@ -201,7 +213,9 @@ function(dependency)
201213
DEPENDENCY_CONFIG_FILE
202214
DEPENDENCY_BUILD_FILE
203215
)
204-
set(multiValueArgs "")
216+
set(multiValueArgs
217+
DEPENDENCY_LINK_TARGETS
218+
)
205219

206220
cmake_parse_arguments(
207221
DEP_ARGS
@@ -465,6 +479,7 @@ function(dependency)
465479

466480
FetchContent_MakeAvailable(${DEP_ARGS_DEPENDENCY_NAME})
467481

482+
# Check if a build file needs to be included
468483
if(DEFINED DEP_ARGS_DEPENDENCY_BUILD_FILE)
469484
set(
470485
DEPENDENCY_BUILD_FILE
@@ -487,8 +502,9 @@ function(dependency)
487502
endif()
488503
endif()
489504

490-
# Append dependency name to a tracked global cached list
505+
# Check tracked identifiers
491506
if(DEPENDENCY_SCOPE IN_LIST DEP_TRACKED_SCOPES)
507+
# Append dependency name to a tracked global cached list
492508
set(PROJECT_DEPENDENCIES_LIST ${PROJECT_NAME_UPPER}_DEPENDENCIES_LIST)
493509
set(_dep_list "${${PROJECT_DEPENDENCIES_LIST}}")
494510
list(FIND _dep_list "${DEP_ARGS_DEPENDENCY_NAME}" _dep_idx)
@@ -502,5 +518,26 @@ function(dependency)
502518
FORCE
503519
)
504520
endif()
521+
522+
# Append dependency link targets to a tracked global cached list
523+
if(DEP_ARGS_DEPENDENCY_LINK_TARGETS)
524+
set(PROJECT_DEPENDENCIES_LINK_TARGETS
525+
${PROJECT_NAME_UPPER}_DEPENDENCIES_LINK_TARGETS
526+
)
527+
set(_dep_link_list "${${PROJECT_DEPENDENCIES_LINK_TARGETS}}")
528+
foreach(_link_item IN ITEMS ${DEP_ARGS_DEPENDENCY_LINK_TARGETS})
529+
list(FIND _dep_link_list "${_link_item}" _dep_idx)
530+
if(_dep_idx EQUAL -1)
531+
list(APPEND _dep_link_list "${_link_item}")
532+
endif()
533+
endforeach()
534+
set(${PROJECT_DEPENDENCIES_LINK_TARGETS}
535+
${_dep_link_list}
536+
CACHE STRING
537+
"List of link targets of all dependencies"
538+
FORCE
539+
)
540+
endif()
505541
endif()
542+
506543
endfunction()

0 commit comments

Comments
 (0)