Skip to content

Commit 0e910ee

Browse files
authored
Merge pull request #382 from AshFungor/different-cmake-layout
Restructure CMake project layout: make interacting with Artery's options and dependencies easier
2 parents a314ca8 + 8156d3e commit 0e910ee

File tree

19 files changed

+429
-284
lines changed

19 files changed

+429
-284
lines changed

.github/workflows/lint.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ jobs:
1919
fetch-depth: 0
2020

2121
- name: Configure CMake
22-
run: tools/build.py -cl
22+
run: |
23+
tools/build.py -cl \
24+
-D WITH_SIMULTE:BOOL=ON \
25+
-D WITH_OTS:BOOL=ON \
26+
-D WITH_TESTBED:BOOL=ON \
27+
-D WITH_TRANSFUSION:BOOL=ON
2328
2429
- name: Run clang-tidy
2530
run: |

.github/workflows/test.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- uses: actions/checkout@v5
1717
with:
1818
submodules: recursive
19+
fetch-depth: 0
1920

2021
- name: Create virtual environment
2122
run: python3 -m venv .venv
@@ -24,7 +25,11 @@ jobs:
2425
run: . .venv/bin/activate && pip install -r tools/ci/requirements.txt
2526

2627
- name: Configure and build CMake
27-
run: tools/build.py -cb --config Release --generator Ninja
28+
run: |
29+
tools/build.py -cb --config Release \
30+
--generator Ninja \
31+
-D WITH_SIMULTE:BOOL=ON \
32+
-D WITH_OTS:BOOL=ON
2833
2934
- name: Run tests
3035
run: . .venv/bin/activate && PYTHONPATH=$PWD python3 tools/ci/run.py -l build/Release/run-artery.ini -s scenarios

CMakeLists.txt

Lines changed: 97 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
cmake_minimum_required(VERSION 3.16)
2+
23
cmake_policy(VERSION 3.16...3.31)
3-
project(Artery)
44

5-
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
5+
project(Artery LANGUAGES CXX C)
6+
7+
enable_testing()
8+
69
set(CMAKE_CXX_STANDARD 17)
710
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8-
enable_testing()
11+
set(CMAKE_CXX_EXTENSIONS OFF)
912

10-
find_package(OmnetPP 5.5.1 MODULE REQUIRED)
11-
include(AddOppRun)
12-
include(AddOppTarget)
13-
include(AddVSCode)
14-
include(CheckGitSubmodule)
15-
include(GenerateOppMessage)
16-
include(GNUInstallDirs)
13+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
1714

18-
find_package(Boost 1.59 REQUIRED COMPONENTS date_time system CONFIG)
15+
##################
16+
# Artery Options #
17+
##################
18+
19+
# These are essential componets that are better to be turned on.
20+
option(WITH_INET "Build Artery with INET framework integration" ON)
21+
option(WITH_VEINS "Build Artery with Veins framework integration" ON)
22+
23+
# Various extensions, adjust them as needed.
24+
option(WITH_SIMULTE "Build Artery with SimuLTE integration" OFF)
25+
option(WITH_OTS "Build Artery with support for OpenTrafficSim" OFF)
26+
option(WITH_TESTBED "Build Artery with testbed feature" OFF)
27+
option(WITH_ENVMOD "Build Artery with environment model feature" ON)
28+
option(WITH_STORYBOARD "Build Artery with storyboard feature" ON)
29+
option(WITH_TRANSFUSION "Build Artery with transfusion feature" OFF)
30+
31+
# Miscellaneous stuff, does not affect functionality directly.
32+
option(WITH_SCENARIOS "Build Artery with scenarios" ON)
33+
option(VSCODE_LAUNCH_INTEGRATION "Generate VS Code configuration for debugging Artery (requires debug build)" OFF)
34+
35+
##############################
36+
# Artery build configuration #
37+
##############################
1938

2039
# use "RelWithDebInfo" as default build type
2140
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
@@ -26,83 +45,76 @@ endif()
2645
# running simulations with opp_run requires shared libraries
2746
set(BUILD_SHARED_LIBS ON CACHE INTERNAL "Cached for propagation to sub-projects with older CMake versions")
2847

29-
check_git_submodule(PATH extern/vanetza REQUIRED_FILES CMakeLists.txt)
30-
set(VANETZA_INSTALL ON)
31-
add_subdirectory(${PROJECT_SOURCE_DIR}/extern/vanetza)
32-
mark_as_advanced(BUILD_BENCHMARK BUILD_CERTIFY BUILD_SOCKTAP BUILD_TESTS BUILD_USING_CONAN)
33-
mark_as_advanced(VANETZA_ASN1_WITH_ASN1C VANETZA_EXPORT_PACKAGE VANETZA_NET_WITH_POSIX)
34-
35-
check_git_submodule(PATH extern/veins REQUIRED_FILES src/veins/package.ned)
36-
find_path(Veins_DIR NAMES src/veins/package.ned PATHS extern/veins DOC "Veins root directory")
37-
mark_as_advanced(Veins_DIR)
38-
add_opp_target(TARGET veins ROOT_DIR ${Veins_DIR})
39-
40-
41-
check_git_submodule(PATH extern/inet REQUIRED_FILES src/inet/package.ned)
42-
find_path(INET_DIR NAMES src/inet/package.ned PATHS extern/inet DOC "INET root directory")
43-
mark_as_advanced(INET_DIR)
44-
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${INET_DIR}/.oppfeaturestate ${INET_DIR}/.nedexclusions)
45-
46-
# collect INET's opp_makemake options
47-
execute_process(COMMAND ./inet_featuretool options -l -f
48-
WORKING_DIRECTORY ${INET_DIR}
49-
OUTPUT_VARIABLE INET_OPP_MAKEMAKE)
50-
separate_arguments(INET_OPP_MAKEMAKE UNIX_COMMAND ${INET_OPP_MAKEMAKE})
51-
52-
# generate INET's features and opp_defines header
53-
set(INET_GEN_DIR ${PROJECT_BINARY_DIR}/INET_gen)
54-
file(MAKE_DIRECTORY ${INET_GEN_DIR}/inet)
55-
add_custom_command(OUTPUT ${INET_DIR}/.oppfeaturestate
56-
COMMAND ./inet_featuretool repair
57-
DEPENDS ${INET_DIR}/.oppfeatures ${INET_DIR}/inet_featuretool
58-
WORKING_DIRECTORY ${INET_DIR})
59-
add_custom_command(OUTPUT ${INET_GEN_DIR}/inet/features.h
60-
COMMAND ./inet_featuretool defines >${INET_GEN_DIR}/inet/features.h
61-
DEPENDS ${INET_DIR}/.oppfeaturestate
62-
WORKING_DIRECTORY ${INET_DIR}
63-
COMMENT "Generate INET features.h")
64-
add_custom_command(OUTPUT ${INET_GEN_DIR}/inet/opp_defines.h
65-
COMMAND ${CMAKE_COMMAND} -E touch ${INET_GEN_DIR}/inet/opp_defines.h
66-
COMMENT "Generate INET opp_defines.h")
67-
68-
add_opp_target(TARGET INET ROOT_DIR ${INET_DIR}
69-
DEPENDS ${INET_GEN_DIR}/inet/features.h ${INET_GEN_DIR}/inet/opp_defines.h
70-
OPP_MAKEMAKE ${INET_OPP_MAKEMAKE})
71-
72-
73-
check_git_submodule(PATH extern/simulte REQUIRED_FILES src/package.ned)
74-
find_path(SimuLTE_DIR NAMES src/package.ned PATHS extern/simulte DOC "SimuLTE root directory")
75-
mark_as_advanced(SimuLTE_DIR)
76-
option(WITH_SIMULTE "Build Artery with SimuLTE integration" OFF)
77-
if(WITH_SIMULTE)
78-
add_opp_target(TARGET lte ROOT_DIR ${SimuLTE_DIR})
79-
target_link_libraries(lte PUBLIC INET)
80-
else()
81-
message(STATUS "SimuLTE integration disabled")
82-
endif()
48+
###############################
49+
# Required packages & scripts #
50+
###############################
8351

52+
find_package(OmnetPP 5.5.1 MODULE REQUIRED)
53+
find_package(Boost 1.59 REQUIRED COMPONENTS date_time system CONFIG)
8454

85-
option(WITH_ENVMOD "Build Artery with environment model feature" ON)
86-
option(WITH_STORYBOARD "Build Artery with storyboard feature" ON)
87-
option(WITH_TRANSFUSION "Build Artery with transfusion feature" OFF)
88-
option(WITH_TESTBED "Build Artery with testbed feature" OFF)
55+
include(AddOppRun)
56+
include(AddOppTarget)
57+
include(AddVSCode)
58+
include(CheckGitSubmodule)
59+
include(GenerateOppMessage)
60+
include(AddArterySubdirectory)
61+
include(GNUInstallDirs)
8962

90-
option(WITH_OTS "Build Artery with support for OpenTrafficSim" OFF)
91-
if(WITH_OTS)
92-
add_subdirectory(src/ots)
63+
# Packages below are needed by various
64+
# optional components. They should be used
65+
# with add_artery_subdirectory() to trigger
66+
# checks on them only if variables (WITH*)
67+
# are set.
68+
69+
find_package(Protobuf QUIET)
70+
find_package(PkgConfig MODULE QUIET)
71+
find_package(SEA_V2X CONFIG QUIET)
72+
73+
if(PkgConfig_FOUND)
74+
pkg_check_modules(ZEROMQ QUIET IMPORTED_TARGET libzmq)
9375
endif()
94-
add_subdirectory(src/traci)
9576

77+
if(SEA_V2X_FOUND)
78+
mark_as_advanced(SEA_V2X_DIR)
79+
endif()
80+
81+
add_subdirectory(extern)
82+
83+
##########################
84+
# Primary Artery targets #
85+
##########################
86+
87+
# TODO: temporarily targets are moved into src/artery
88+
89+
macro(add_artery_feature name)
90+
add_library(${name} SHARED ${ARGN})
91+
add_library(Artery::${name} ALIAS ${name})
92+
get_target_property(ned_folder ${name} SOURCE_DIR)
93+
set_target_properties(${name} PROPERTIES
94+
OUTPUT_NAME artery_${name}
95+
OMNETPP_LIBRARY ON
96+
NED_FOLDERS ${ned_folder})
97+
target_link_libraries(${name} PRIVATE core)
98+
target_link_libraries(artery INTERFACE Artery::${name})
99+
install(TARGETS ${name} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
100+
endmacro()
101+
102+
##########
103+
# Artery #
104+
##########
105+
106+
add_subdirectory(src/traci)
96107
add_subdirectory(src/artery)
97108

98-
option(VSCODE_LAUNCH_INTEGRATION "Generate VS Code configuration for debugging Artery (requires debug build)" OFF)
109+
add_artery_subdirectory(src/ots REQUIRES INET PkgConfig::ZEROMQ SWITCH WITH_OTS)
99110

100111
# scenarios directory is part of repository but omitted for Docker build context
101-
if(EXISTS ${PROJECT_SOURCE_DIR}/scenarios)
112+
if(WITH_SCENARIOS)
102113
add_subdirectory(scenarios)
103114
endif()
104115

105116
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
117+
106118
if(is_multi_config)
107119
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
108120
string(TOLOWER "${config}" config_lower)
@@ -113,3 +125,13 @@ else()
113125
generate_run_config(TARGET artery CONFIG ${CMAKE_BUILD_TYPE} FILE "${PROJECT_BINARY_DIR}/run-artery.ini")
114126
generate_run_config(TARGET artery CONFIG ${CMAKE_BUILD_TYPE} FILE "${PROJECT_BINARY_DIR}/run-artery.ini.install" INSTALL)
115127
endif()
128+
129+
if(VSCODE_LAUNCH_INTEGRATION)
130+
if(is_multi_config AND "Debug" NOT IN CMAKE_CONFIGURATION_TYPES)
131+
message(STATUS "VS Code integration is enabled, but Debug is not included in build types")
132+
elseif(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
133+
message(STATUS "VS Code integration is enabled, but build type is not Debug")
134+
else()
135+
generate_vscode(TARGET artery FILE ${PROJECT_SOURCE_DIR}/.vscode/launch.json)
136+
endif()
137+
endif()

cmake/AddArterySubdirectory.cmake

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
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) targets that are listed in REQUIRES are declared (exist by their provided names)
6+
7+
# If condition 1) is not met, then subdirectory is not added and
8+
# debug message is issued. If one or more targets specified by REQUIRES does not exist,
9+
# this function raises error. Note: these checks are not meant to determine if package
10+
# was loaded correctly, but rather to make feature-to-package relation verbose in CMake files.
11+
12+
set(one_value_args SWITCH)
13+
set(multi_value_args REQUIRES)
14+
cmake_parse_arguments(args "" "${one_value_args}" "${multi_value_args}" ${ARGN})
15+
16+
if(args_UNPARSED_ARGUMENTS)
17+
message(SEND_ERROR "add_artery_subdirectory called with invalid arguments: ${args_UNPARSED_ARGUMENTS}")
18+
endif()
19+
20+
if(NOT ${${args_SWITCH}})
21+
message(STATUS "add_artery_subdirectory: skipping ${directory} (switched off)")
22+
else()
23+
message(STATUS "add_artery_subdirectory: adding ${directory} (switched on)")
24+
25+
foreach(required_target IN LISTS args_REQUIRES)
26+
if(NOT TARGET ${required_target})
27+
message(
28+
FATAL_ERROR
29+
"add_artery_subdirectory: required target '${required_target}' for '${directory}' does not exist"
30+
)
31+
endif()
32+
endforeach()
33+
34+
add_subdirectory("${directory}")
35+
endif()
36+
endfunction()

cmake/GenerateOppMessage.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function(generate_opp_message msg_input)
1010
set(msg_output_root ${PROJECT_BINARY_DIR}/opp_messages)
1111
get_filename_component(msg_name "${msg_input}" NAME_WE)
1212
get_filename_component(msg_dir "${msg_input}" DIRECTORY)
13+
1314
if(args_DIRECTORY)
1415
set(msg_prefix "${args_DIRECTORY}")
1516
else()

extern/CMakeLists.txt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
check_git_submodule(PATH vanetza REQUIRED_FILES CMakeLists.txt)
2+
set(VANETZA_INSTALL ON)
3+
4+
add_subdirectory(vanetza)
5+
mark_as_advanced(
6+
BUILD_BENCHMARK
7+
BUILD_CERTIFY
8+
BUILD_SOCKTAP
9+
BUILD_TESTS
10+
BUILD_USING_CONAN
11+
VANETZA_ASN1_WITH_ASN1C
12+
VANETZA_EXPORT_PACKAGE
13+
VANETZA_NET_WITH_POSIX
14+
)
15+
16+
if(WITH_VEINS)
17+
message(STATUS "Enable Veins integration")
18+
check_git_submodule(PATH veins REQUIRED_FILES src/veins/package.ned)
19+
20+
find_path(Veins_DIR NAMES src/veins/package.ned PATHS veins DOC "Veins root directory")
21+
mark_as_advanced(Veins_DIR)
22+
add_opp_target(TARGET veins ROOT_DIR ${Veins_DIR})
23+
endif()
24+
25+
if(WITH_INET)
26+
message(STATUS "Enable INET integration")
27+
28+
check_git_submodule(PATH inet REQUIRED_FILES src/inet/package.ned)
29+
find_path(INET_DIR NAMES src/inet/package.ned PATHS inet DOC "INET root directory")
30+
mark_as_advanced(INET_DIR)
31+
32+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${INET_DIR}/.oppfeaturestate ${INET_DIR}/.nedexclusions)
33+
34+
# collect INET's opp_makemake options
35+
execute_process(
36+
COMMAND ./inet_featuretool options -l -f
37+
WORKING_DIRECTORY ${INET_DIR}
38+
OUTPUT_VARIABLE INET_OPP_MAKEMAKE
39+
)
40+
separate_arguments(INET_OPP_MAKEMAKE UNIX_COMMAND ${INET_OPP_MAKEMAKE})
41+
42+
# generate INET's features and opp_defines header
43+
set(INET_GEN_DIR ${PROJECT_BINARY_DIR}/INET_gen)
44+
file(MAKE_DIRECTORY ${INET_GEN_DIR}/inet)
45+
46+
add_custom_command(
47+
OUTPUT ${INET_DIR}/.oppfeaturestate
48+
COMMAND ./inet_featuretool repair
49+
DEPENDS ${INET_DIR}/.oppfeatures ${INET_DIR}/inet_featuretool
50+
WORKING_DIRECTORY ${INET_DIR}
51+
)
52+
53+
add_custom_command(
54+
OUTPUT ${INET_GEN_DIR}/inet/features.h
55+
COMMAND ./inet_featuretool defines >${INET_GEN_DIR}/inet/features.h
56+
DEPENDS ${INET_DIR}/.oppfeaturestate
57+
WORKING_DIRECTORY ${INET_DIR}
58+
COMMENT "Generate INET features.h"
59+
)
60+
61+
add_custom_command(
62+
OUTPUT ${INET_GEN_DIR}/inet/opp_defines.h
63+
COMMAND ${CMAKE_COMMAND} -E touch ${INET_GEN_DIR}/inet/opp_defines.h
64+
COMMENT "Generate INET opp_defines.h"
65+
)
66+
67+
add_opp_target(
68+
TARGET INET ROOT_DIR ${INET_DIR}
69+
DEPENDS ${INET_GEN_DIR}/inet/features.h ${INET_GEN_DIR}/inet/opp_defines.h
70+
OPP_MAKEMAKE ${INET_OPP_MAKEMAKE}
71+
)
72+
endif()
73+
74+
if(WITH_SIMULTE)
75+
message(STATUS "Enable SimuLTE integration")
76+
if(NOT TARGET INET)
77+
message(FATAL_ERROR "SimuLTE requires INET")
78+
endif()
79+
80+
check_git_submodule(PATH simulte REQUIRED_FILES src/package.ned)
81+
find_path(SimuLTE_DIR NAMES src/package.ned PATHS simulte DOC "SimuLTE root directory")
82+
mark_as_advanced(SimuLTE_DIR)
83+
84+
add_opp_target(TARGET lte ROOT_DIR ${SimuLTE_DIR})
85+
target_link_libraries(lte PUBLIC INET)
86+
else()
87+
message(STATUS "SimuLTE integration disabled")
88+
endif()
89+
90+
if(WITH_STORYBOARD)
91+
add_subdirectory(pybind11)
92+
endif()
93+
94+
if(WITH_OTS)
95+
set(SIM0MQPP_INSTALL ON)
96+
set(SIM0MQPP_SHARED_LIB ON)
97+
add_subdirectory(sim0mqpp ${PROJECT_BINARY_DIR}/sim0mqpp)
98+
endif()

0 commit comments

Comments
 (0)