Skip to content

Commit 5dce7d1

Browse files
committed
cmake: add requires to add_subdirectory wrapper
1 parent ec05500 commit 5dce7d1

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

CMakeLists.txt

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,6 @@ option(WITH_TRANSFUSION "Build Artery with transfusion feature" OFF)
3232
option(WITH_SCENARIOS "Build Artery with scenarios" ON)
3333
option(VSCODE_LAUNCH_INTEGRATION "Generate VS Code configuration for debugging Artery (requires debug build)" OFF)
3434

35-
#################################
36-
# Resolving conflicting options #
37-
#################################
38-
39-
if(NOT WITH_INET)
40-
# SimuLTE extends INET network (see src/artery/lte/World.ned)
41-
if(WITH_SIMULTE)
42-
message(ERROR "SimuLTE requires INET framework integration (WITH_INET must be set to ON)")
43-
endif()
44-
45-
# Components below use INET classes
46-
if(WITH_OTS)
47-
message(ERROR "OpenTrafficSim requires INET framework integration (WITH_INET must be set to ON)")
48-
endif()
49-
if(WITH_TESTBED)
50-
message(ERROR "Testbed requires INET framework integration (WITH_INET must be set to ON)")
51-
endif()
52-
if(WITH_ENVMOD)
53-
message(ERROR "Environment model requires INET framework integration (WITH_INET must be set to ON)")
54-
endif()
55-
endif()
56-
5735
##############################
5836
# Artery build configuration #
5937
##############################
@@ -128,7 +106,7 @@ endmacro()
128106
add_subdirectory(src/traci)
129107
add_subdirectory(src/artery)
130108

131-
add_artery_subdirectory(src/ots DEPENDENCIES ZEROMQ SWITCH WITH_OTS)
109+
add_artery_subdirectory(src/ots REQUIRES INET DEPENDENCIES ZEROMQ SWITCH WITH_OTS)
132110

133111
# scenarios directory is part of repository but omitted for Docker build context
134112
if(WITH_SCENARIOS)

cmake/AddArterySubdirectory.cmake

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
function(add_artery_subdirectory directory)
2+
# include target subdirectory with certain artery
3+
# extension (feature), if the following conditions match:
4+
# 1) variable with id matching SWITCH is set to true (feature turned on)
5+
# 2) packages that are listed in DEPENDENCIES are found
6+
# 3) targets that are listed in REQUIRES are declared (used for extern modules)
7+
8+
# If condition 1) is not met, then subdirectory is not added and
9+
# debug message is issued. If either 2) or 3) fails, then this function raises error.
10+
211
set(one_value_args SWITCH)
3-
set(multi_value_args DEPENDENCIES)
12+
set(multi_value_args DEPENDENCIES;REQUIRES)
413
cmake_parse_arguments(args "" "${one_value_args}" "${multi_value_args}" ${ARGN})
514

615
if(args_UNPARSED_ARGUMENTS)
@@ -17,7 +26,16 @@ function(add_artery_subdirectory directory)
1726
if(NOT DEFINED ${_dep_var} OR NOT ${_dep_var})
1827
message(
1928
FATAL_ERROR
20-
"add_artery_subdirectory: required dependency '${dependency}' for '${directory}' not found: variable '${_dep_var}' is not defined"
29+
"add_artery_subdirectory: dependency '${dependency}' for '${directory}' was not found: variable '${_dep_var}' is not defined"
30+
)
31+
endif()
32+
endforeach()
33+
34+
foreach(required_target IN LISTS args_REQUIRES)
35+
if(NOT TARGET ${required_target})
36+
message(
37+
FATAL_ERROR
38+
"add_artery_subdirectory: required target '${required_target}' for '${directory}' was not found"
2139
)
2240
endif()
2341
endforeach()

extern/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ if(WITH_INET)
7272
endif()
7373

7474
if(WITH_SIMULTE)
75+
message(STATUS "Enable SimuLTE integration")
76+
if(NOT TARGET INET)
77+
message(FATAL_ERROR "SimuLTE requires INET")
78+
endif()
79+
7580
check_git_submodule(PATH simulte REQUIRED_FILES src/package.ned)
7681
find_path(SimuLTE_DIR NAMES src/package.ned PATHS simulte DOC "SimuLTE root directory")
7782
mark_as_advanced(SimuLTE_DIR)
83+
7884
add_opp_target(TARGET lte ROOT_DIR ${SimuLTE_DIR})
7985
target_link_libraries(lte PUBLIC INET)
8086
else()

src/artery/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,15 @@ add_artery_subdirectory(inet SWITCH WITH_INET)
4343
add_artery_subdirectory(storyboard SWITCH WITH_STORYBOARD)
4444

4545
add_artery_subdirectory(transfusion DEPENDENCIES Protobuf SWITCH WITH_TRANSFUSION)
46-
add_artery_subdirectory(testbed DEPENDENCIES SEA_V2X Protobuf SWITCH WITH_TESTBED)
46+
add_artery_subdirectory(testbed REQUIRES INET DEPENDENCIES SEA_V2X Protobuf SWITCH WITH_TESTBED)
4747

4848
if(TARGET lte)
4949
# SimuLTE is a non-integral feature: add it to "artery" but not "core"
50-
message(STATUS "Enable SimuLTE integration")
5150
target_link_libraries(artery INTERFACE lte)
5251
endif()
5352

53+
add_artery_subdirectory(envmod REQUIRES INET SWITCH WITH_ENVMOD)
5454
if(WITH_ENVMOD)
55-
add_subdirectory(envmod)
5655
set_property(SOURCE application/VehicleMiddleware.cc APPEND PROPERTY COMPILE_DEFINITIONS "WITH_ENVMOD")
5756
endif()
5857

0 commit comments

Comments
 (0)