Skip to content

Commit 4209c63

Browse files
committed
General CMakeLists improvements - cmake v2→v3
- Use literal target names instead of variables - Write internal.hpp to build directory instead of source to prevent needless rebuilds - Fixed how this file is includes in source files - Remove hard coded CMAKE_VERBOSE_MAKEFILE - Ran cmake-format - "wrap"ing (ld's --wrap option) the "socket" symbol, see wrappers.cpp - Added install directive to vsomeip/example/hello_world and vsomeip_ctrl - Platform conditional socket lib linkage - hello_world code uses ENABLE_SIGNALS, but its setting was missing in CMake - Improve setup for boost stacktrace, really only helps on Linux and requires the backtrace.h file - Added QNX platform section, though the credential code changes for QNX are not included in this commit. - Use a CACHE variable for VSOMEIP_BASE_PATH. Upstream defaults this to /var for QNX which is a very bad choice. - Followed the 3.5.x example and remove the dependency on routingmanager in the tests, as it's not available on Windows
1 parent f36b98e commit 4209c63

File tree

28 files changed

+457
-327
lines changed

28 files changed

+457
-327
lines changed

CMakeLists.txt

Lines changed: 294 additions & 238 deletions
Large diffs are not rendered by default.

examples/CMakeLists.txt

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
2-
# This Source Code Form is subject to the terms of the Mozilla Public
3-
# License, v. 2.0. If a copy of the MPL was not distributed with this
4-
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
1+
# Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) This Source Code Form is subject to the
2+
# terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain
3+
# one at http://mozilla.org/MPL/2.0/.
4+
5+
cmake_minimum_required(VERSION 3.15)
56

67
set(EXAMPLE_CONFIG_FILES
78
"../config/vsomeip.json"
@@ -14,22 +15,53 @@ set(EXAMPLE_CONFIG_FILES
1415

1516
# Examples
1617
add_executable(request-sample request-sample.cpp ${EXAMPLE_CONFIG_FILES})
17-
target_link_libraries(request-sample ${VSOMEIP_NAME} ${Boost_LIBRARIES} ${DL_LIBRARY})
18+
target_link_libraries(
19+
request-sample
20+
vsomeip3
21+
Boost::system
22+
DL_INTERFACE
23+
)
1824

1925
add_executable(response-sample response-sample.cpp ${EXAMPLE_CONFIG_FILES})
20-
target_link_libraries(response-sample ${VSOMEIP_NAME} ${Boost_LIBRARIES} ${DL_LIBRARY})
26+
target_link_libraries(
27+
response-sample
28+
vsomeip3
29+
Boost::system
30+
DL_INTERFACE
31+
)
2132

2233
add_executable(subscribe-sample subscribe-sample.cpp ${EXAMPLE_CONFIG_FILES})
23-
target_link_libraries(subscribe-sample ${VSOMEIP_NAME} ${Boost_LIBRARIES} ${DL_LIBRARY})
34+
target_link_libraries(
35+
subscribe-sample
36+
vsomeip3
37+
Boost::system
38+
DL_INTERFACE
39+
)
2440

2541
add_executable(notify-sample notify-sample.cpp ${EXAMPLE_CONFIG_FILES})
26-
target_link_libraries(notify-sample ${VSOMEIP_NAME} ${Boost_LIBRARIES} ${DL_LIBRARY})
42+
target_link_libraries(
43+
notify-sample
44+
vsomeip3
45+
Boost::system
46+
DL_INTERFACE
47+
)
2748

28-
add_dependencies(examples request-sample response-sample subscribe-sample notify-sample)
49+
add_dependencies(
50+
examples
51+
request-sample
52+
response-sample
53+
subscribe-sample
54+
notify-sample
55+
)
2956

30-
install (
31-
TARGETS request-sample response-sample subscribe-sample notify-sample
32-
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
57+
install(
58+
TARGETS request-sample
59+
response-sample
60+
subscribe-sample
61+
notify-sample
62+
RUNTIME
63+
DESTINATION "${INSTALL_BIN_DIR}"
64+
COMPONENT bin
3365
)
3466

35-
###################################################################################################
67+
# ######################################################################################################################

examples/hello_world/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ project (vSomeIPHelloWorld)
88

99
find_package(Threads REQUIRED)
1010

11-
set(VSOMEIP_NAME "vsomeip3")
11+
include(GNUInstallDirs)
1212

1313
# create_target("executable")
1414
function(create_target executable)
@@ -21,6 +21,10 @@ function(create_target executable)
2121
target_include_directories(vsomeip_hello_world_${executable} INTERFACE
2222
${CMAKE_CURRENT_SOURCE_DIR}
2323
)
24+
25+
if(ENABLE_SIGNAL_HANDLING)
26+
target_compile_definitions(vsomeip_hello_world_example INTERFACE VSOMEIP_ENABLE_SIGNAL_HANDLING)
27+
endif()
2428
endfunction()
2529

2630
# link_target("executable")
@@ -30,8 +34,6 @@ function(link_target executable)
3034
target_link_libraries(hello_world_${executable} PRIVATE vsomeip_hello_world_${executable} vsomeip3 Threads::Threads)
3135
endfunction()
3236

33-
include_directories(${VSOMEIP_INCLUDE_DIRS})
34-
3537
create_target("service")
3638
create_target("client")
3739

examples/routingmanagerd/CMakeLists.txt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,31 @@
22
# terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain
33
# one at http://mozilla.org/MPL/2.0/.
44

5+
cmake_minimum_required(VERSION 3.15)
6+
7+
8+
option(VSOMEIP_INSTALL_ROUTINGMANAGERD "Whether or not to install the routing manager daemon.")
9+
510
# Daemon
6-
add_executable(routingmanagerd routingmanagerd.cpp)
11+
add_executable(routingmanagerd)
12+
target_sources(routingmanagerd PRIVATE routingmanagerd.cpp)
13+
14+
if(TARGET Genivi::dlt)
15+
target_compile_definitions(routingmanagerd PRIVATE USE_DLT)
16+
target_link_libraries(routingmanagerd PRIVATE Genivi::dlt)
17+
endif()
18+
719
target_link_libraries(
820
routingmanagerd
9-
${VSOMEIP_NAME}
10-
${Boost_LIBRARIES}
11-
${DL_LIBRARY}
12-
${DLT_LIBRARIES}
13-
${CMAKE_THREAD_LIBS_INIT}
21+
PRIVATE vsomeip3
22+
Boost::system
23+
Boost::filesystem
24+
STACKTRACE_INTERFACE
25+
OS_INTERFACE
26+
DL_INTERFACE
27+
RT_INTERFACE
28+
Threads::Threads
1429
)
15-
if(${CMAKE_SYSTEM_NAME} MATCHES "QNX")
16-
target_link_libraries(routingmanagerd socket)
17-
endif()
18-
add_dependencies(routingmanagerd ${VSOMEIP_NAME})
19-
20-
option(VSOMEIP_INSTALL_ROUTINGMANAGERD "Whether or not to install the routing manager daemon.")
2130

2231
if(VSOMEIP_INSTALL_ROUTINGMANAGERD)
2332
install(

test/CMakeLists.txt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ find_package(benchmark)
1414
##############################################################################
1515
# google test
1616

17-
# remove export symbols from the cxx flags
18-
string(REPLACE "${EXPORTSYMBOLS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
17+
# remove export symbols from the cxx flags. This is messy, but there's no `remove_link_flags` function
18+
get_target_property(os_link_options OS_INTERFACE INTERFACE_LINK_OPTIONS)
19+
foreach(opt IN ITEMS ${os_link_options})
20+
if(opt MATCHES ".*version.script.*.gcc")
21+
list(REMOVE_ITEM os_link_options ${opt})
22+
endif()
23+
endforeach()
24+
unset(opt)
25+
if(os_link_options)
26+
set_target_properties(OS_INTERFACE PROPERTIES INTERFACE_LINK_OPTIONS "${os_link_options}")
27+
endif()
28+
unset(os_link_options)
1929

2030
# check for set environment variable
2131
if(${GTEST_ROOT} STREQUAL "n/a")
@@ -107,19 +117,19 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
107117
add_dependencies(check build_tests)
108118

109119
add_custom_target(build_network_tests)
110-
add_dependencies(build_network_tests ${VSOMEIP_NAME})
111-
add_dependencies(build_network_tests ${VSOMEIP_NAME}-e2e)
112-
add_dependencies(build_network_tests ${VSOMEIP_NAME}-sd)
120+
add_dependencies(build_network_tests vsomeip3)
121+
add_dependencies(build_network_tests vsomeip3-e2e)
122+
add_dependencies(build_network_tests vsomeip3-sd)
113123
add_dependencies(build_tests build_network_tests)
114124

115125
add_custom_target(build_unit_tests)
116-
add_dependencies(build_unit_tests ${VSOMEIP_NAME})
117-
add_dependencies(build_unit_tests ${VSOMEIP_NAME}-sd)
126+
add_dependencies(build_unit_tests vsomeip3)
127+
add_dependencies(build_unit_tests vsomeip3-sd)
118128
add_dependencies(build_tests build_unit_tests)
119129

120130
add_custom_target(build_benchmark_tests)
121-
add_dependencies(build_benchmark_tests ${VSOMEIP_NAME})
122-
add_dependencies(build_benchmark_tests ${VSOMEIP_NAME}-sd)
131+
add_dependencies(build_benchmark_tests vsomeip3)
132+
add_dependencies(build_benchmark_tests vsomeip3-sd)
123133
add_dependencies(build_tests build_benchmark_tests)
124134

125135
##############################################################################
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
1-
# Copyright (C) 2015-2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
2-
# This Source Code Form is subject to the terms of the Mozilla Public
3-
# License, v. 2.0. If a copy of the MPL was not distributed with this
4-
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
1+
# Copyright (C) 2015-2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) This Source Code Form is subject to the
2+
# terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain
3+
# one at http://mozilla.org/MPL/2.0/.
54

6-
project ("benchmark_tests_bin" LANGUAGES CXX)
5+
project("benchmark_tests_bin" LANGUAGES CXX)
76

8-
file (GLOB SRCS main.cpp **/*.cpp)
7+
file(
8+
GLOB
9+
SRCS
10+
main.cpp
11+
**/*.cpp
12+
../common/utility.cpp
13+
)
914

1015
set(THREADS_PREFER_PTHREAD_FLAG ON)
1116

1217

1318
# ----------------------------------------------------------------------------
1419
# Executable and libraries to link
1520
# ----------------------------------------------------------------------------
16-
add_executable (${PROJECT_NAME} ${SRCS} )
17-
target_link_libraries (
18-
${PROJECT_NAME}
19-
vsomeip3
20-
vsomeip3-cfg
21-
Threads::Threads
22-
${Boost_LIBRARIES}
23-
${DL_LIBRARY}
24-
benchmark::benchmark
25-
gtest
26-
vsomeip_utilities
21+
add_executable(vsomeip3-benchmark-tests)
22+
target_sources(vsomeip3-benchmark-tests PRIVATE ${SRCS})
23+
target_link_libraries(
24+
vsomeip3-benchmark-tests
25+
PRIVATE vsomeip3
26+
vsomeip3-cfg
27+
vsomeip_utilities
28+
Threads::Threads
29+
Boost::filesystem
30+
Boost::system
31+
benchmark::benchmark
32+
gtest
33+
DL_INTERFACE
2734
)
35+
set_target_properties(vsomeip3-benchmark-tests PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
2836

29-
add_dependencies(build_benchmark_tests ${PROJECT_NAME})
37+
add_dependencies(build_benchmark_tests vsomeip3-benchmark-tests)

test/common/CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,32 @@ file (GLOB INC include/common/*.hpp, include/common/vsomeip_app_utilities/*.hpp)
1515
# Declare the library
1616
# ----------------------------------------------------------------------------
1717
add_library (
18-
${PROJECT_NAME} SHARED
18+
vsomeip_utilities
1919
${SRC}
2020
${INC}
2121
)
2222

23-
TARGET_LINK_LIBRARIES (
24-
${PROJECT_NAME}
23+
target_link_libraries (
24+
vsomeip_utilities
2525
PUBLIC
26-
${VSOMEIP_NAME}
27-
${Boost_LIBRARIES}
28-
${DL_LIBRARY}
29-
${TEST_LINK_LIBRARIES}
26+
vsomeip3
27+
PRIVATE
28+
Boost::system
29+
Boost::filesystem
30+
INTERFACE
31+
DL_INTERFACE
3032
)
3133

3234
# ----------------------------------------------------------------------------
3335
# Specify here the include directories exported
3436
# by this library
3537
# ----------------------------------------------------------------------------
3638
target_include_directories (
37-
${PROJECT_NAME}
39+
vsomeip_utilities
3840
PUBLIC include
3941
PRIVATE src
4042
)
4143

4244
if (MSVC)
43-
set_target_properties(${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
45+
set_target_properties(vsomeip_utilities PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
4446
endif ()

test/internal_routing_disabled_acceptance_test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ endif()
77

88
project(internal_routing_disabled_acceptance_test LANGUAGES CXX)
99

10-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wconversion -Wextra")
10+
add_compile_options(-pedantic -Wall -Wconversion -Wextra)
1111
set(CMAKE_CXX_STANDARD 17)
1212
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1313
set(CMAKE_CXX_EXTENSIONS OFF)
1414
set(THREADS_PREFER_PTHREAD_FLAG ON)
1515

1616
add_executable(${PROJECT_NAME} applet.cpp client.cpp server.cpp main.cpp)
1717
target_include_directories(${PROJECT_NAME} PRIVATE ${gtest_SOURCE_DIR}/include)
18-
target_link_libraries(${PROJECT_NAME} PRIVATE gtest Threads::Threads vsomeip3 ${Boost_LIBRARIES})
18+
target_link_libraries(${PROJECT_NAME} PRIVATE gtest Threads::Threads vsomeip3 Boost::system)
1919

2020
if (${CMAKE_SYSTEM_NAME} MATCHES "QNX")
2121
target_compile_definitions(${PROJECT_NAME} PRIVATE _QNX_SOURCE)

test/network_tests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ endfunction()
5757
function(targets_link_default_libraries targets)
5858
foreach(target ${targets})
5959
target_link_libraries(${target}
60-
${VSOMEIP_NAME}
61-
${Boost_LIBRARIES}
60+
vsomeip3
61+
Boost::system
6262
${DL_LIBRARY}
6363
${TEST_LINK_LIBRARIES}
6464
${DLT_LIBRARIES}

test/network_tests/client_id_tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ add_executable(client_id_test_utility
4141

4242
# Link vsomeip configuration libraries.
4343
target_link_libraries(client_id_test_utility
44-
${VSOMEIP_NAME}-cfg
44+
vsomeip3-cfg
4545
)
4646

4747
# Add build dependencies and link libraries to executables.

0 commit comments

Comments
 (0)