Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions c/01_executable/source/src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ target_include_directories(
c
)

target_link_libraries(
${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE
PRIVATE
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
)

enable_compiler_warnings(
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE}
${${{VAR_PROJECT_NAME_UPPER}}_IGNORE_WARNINGS}
Expand Down
6 changes: 6 additions & 0 deletions c/02_library/source/src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ target_include_directories(
c
)

target_link_libraries(
${{VAR_PROJECT_NAME_UPPER}}_TARGET_LIB_MAIN
PRIVATE
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
)

set_target_properties(
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_LIB_MAIN}
PROPERTIES
Expand Down
6 changes: 6 additions & 0 deletions cpp/01_executable/source/src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ target_include_directories(
cpp
)

target_link_libraries(
${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE
PRIVATE
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
)

enable_compiler_warnings(
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE}
${${{VAR_PROJECT_NAME_UPPER}}_IGNORE_WARNINGS}
Expand Down
6 changes: 6 additions & 0 deletions cpp/02_library/source/src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ target_include_directories(
cpp
)

target_link_libraries(
${{VAR_PROJECT_NAME_UPPER}}_TARGET_LIB_MAIN
PRIVATE
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
)

set_target_properties(
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_LIB_MAIN}
PROPERTIES
Expand Down
1 change: 1 addition & 0 deletions cpp/03_server-poco/source/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependency(
DEPENDENCY_NAME poco
DEPENDENCY_RESOURCE pocoproject/poco
DEPENDENCY_VERSION poco-1.14.2-release
DEPENDENCY_LINK_TARGETS Poco::XML Poco::JSON Poco::Net Poco::Util
)

${{INCLUDE:cpp/cmake/DependenciesCommon.cmake}}
6 changes: 2 additions & 4 deletions cpp/03_server-poco/source/src/net/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ target_include_directories(

target_link_libraries(
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_NET_CORE}
Poco::XML
Poco::JSON
Poco::Net
Poco::Util
PUBLIC
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
)


Expand Down
1 change: 1 addition & 0 deletions cpp/04_desktop_imgui/source/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependency(
DEPENDENCY_NAME glfw
DEPENDENCY_RESOURCE glfw/glfw
DEPENDENCY_VERSION 3.4
DEPENDENCY_LINK_TARGETS glfw
)

${{INCLUDE:cpp/cmake/DependenciesCommon.cmake}}
2 changes: 1 addition & 1 deletion cpp/04_desktop_imgui/source/src/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ endif()
target_link_libraries(
${${{VAR_PROJECT_NAME_UPPER}}_TARGET_APPLICATION_CORE}
PUBLIC
glfw
${${{VAR_PROJECT_NAME_UPPER}}_PLATFORM_LINK_LIBRARIES}
${${{VAR_PROJECT_NAME_UPPER}}_DEPENDENCIES_LINK_TARGETS}
)

if(${{VAR_PROJECT_NAME_UPPER}}_USE_SANITIZERS)
Expand Down
40 changes: 39 additions & 1 deletion share/c/cmake/DependencyUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ include(FetchContent)
# to configure the dependency. This argument can optionally be used to
# specify a file which deviates from the convention.
#
# [multiValueArgs]
#
# DEPENDENCY_LINK_TARGETS:
# A list of target names that should be registered as link targets when
# consuming the dependency. This argument is optional. When specified,
# the provided names represent CMake targets that are made available to
# the underlying project by the dependency. These target names are then
# appended to the global variable ${PROJECT}_DEPENDENCIES_LINK_TARGETS
# where ${PROJECT} is the name in all caps of the underlying project as
# given to the CMake project() function. A dependency with "TEST" scope
# is never added to that list.
#
# [options]
#
# DEPENDENCY_QUIET:
Expand Down Expand Up @@ -182,7 +194,9 @@ function(dependency)
DEPENDENCY_FILE_HASH
DEPENDENCY_CONFIG_FILE
)
set(multiValueArgs "")
set(multiValueArgs
DEPENDENCY_LINK_TARGETS
)

cmake_parse_arguments(
DEP_ARGS
Expand Down Expand Up @@ -231,6 +245,7 @@ function(dependency)
endif()

set(DEP_ALLOWED_SCOPES ANY RELEASE TEST DEBUG)
set(DEP_TRACKED_SCOPES ANY RELEASE DEBUG)

if(NOT "${DEPENDENCY_SCOPE}" IN_LIST DEP_ALLOWED_SCOPES)
message(
Expand Down Expand Up @@ -434,4 +449,27 @@ function(dependency)

FetchContent_MakeAvailable(${DEP_ARGS_DEPENDENCY_NAME})

# Check tracked identifiers
if(DEPENDENCY_SCOPE IN_LIST DEP_TRACKED_SCOPES)
# Append dependency link targets to a tracked global cached list
if(DEP_ARGS_DEPENDENCY_LINK_TARGETS)
set(PROJECT_DEPENDENCIES_LINK_TARGETS
${PROJECT_NAME_UPPER}_DEPENDENCIES_LINK_TARGETS
)
set(_dep_link_list "${${PROJECT_DEPENDENCIES_LINK_TARGETS}}")
foreach(_link_item IN ITEMS ${DEP_ARGS_DEPENDENCY_LINK_TARGETS})
list(FIND _dep_link_list "${_link_item}" _dep_idx)
if(_dep_idx EQUAL -1)
list(APPEND _dep_link_list "${_link_item}")
endif()
endforeach()
set(${PROJECT_DEPENDENCIES_LINK_TARGETS}
${_dep_link_list}
CACHE STRING
"List of link targets of all dependencies"
FORCE
)
endif()
endif()

endfunction()
40 changes: 39 additions & 1 deletion share/cpp/cmake/DependencyUtil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ include(FetchContent)
# to configure the dependency. This argument can optionally be used to
# specify a file which deviates from the convention.
#
# [multiValueArgs]
#
# DEPENDENCY_LINK_TARGETS:
# A list of target names that should be registered as link targets when
# consuming the dependency. This argument is optional. When specified,
# the provided names represent CMake targets that are made available to
# the underlying project by the dependency. These target names are then
# appended to the global variable ${PROJECT}_DEPENDENCIES_LINK_TARGETS
# where ${PROJECT} is the name in all caps of the underlying project as
# given to the CMake project() function. A dependency with "TEST" scope
# is never added to that list.
#
# [options]
#
# DEPENDENCY_QUIET:
Expand Down Expand Up @@ -182,7 +194,9 @@ function(dependency)
DEPENDENCY_FILE_HASH
DEPENDENCY_CONFIG_FILE
)
set(multiValueArgs "")
set(multiValueArgs
DEPENDENCY_LINK_TARGETS
)

cmake_parse_arguments(
DEP_ARGS
Expand Down Expand Up @@ -231,6 +245,7 @@ function(dependency)
endif()

set(DEP_ALLOWED_SCOPES ANY RELEASE TEST DEBUG)
set(DEP_TRACKED_SCOPES ANY RELEASE DEBUG)

if(NOT "${DEPENDENCY_SCOPE}" IN_LIST DEP_ALLOWED_SCOPES)
message(
Expand Down Expand Up @@ -434,4 +449,27 @@ function(dependency)

FetchContent_MakeAvailable(${DEP_ARGS_DEPENDENCY_NAME})

# Check tracked identifiers
if(DEPENDENCY_SCOPE IN_LIST DEP_TRACKED_SCOPES)
# Append dependency link targets to a tracked global cached list
if(DEP_ARGS_DEPENDENCY_LINK_TARGETS)
set(PROJECT_DEPENDENCIES_LINK_TARGETS
${PROJECT_NAME_UPPER}_DEPENDENCIES_LINK_TARGETS
)
set(_dep_link_list "${${PROJECT_DEPENDENCIES_LINK_TARGETS}}")
foreach(_link_item IN ITEMS ${DEP_ARGS_DEPENDENCY_LINK_TARGETS})
list(FIND _dep_link_list "${_link_item}" _dep_idx)
if(_dep_idx EQUAL -1)
list(APPEND _dep_link_list "${_link_item}")
endif()
endforeach()
set(${PROJECT_DEPENDENCIES_LINK_TARGETS}
${_dep_link_list}
CACHE STRING
"List of link targets of all dependencies"
FORCE
)
endif()
endif()

endfunction()