Skip to content

Commit

Permalink
General CMakeLists improvements - cmake v2→v3
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
kheaactua committed Oct 3, 2024
1 parent d719697 commit f3cabc5
Show file tree
Hide file tree
Showing 28 changed files with 433 additions and 330 deletions.
517 changes: 277 additions & 240 deletions CMakeLists.txt

Large diffs are not rendered by default.

58 changes: 45 additions & 13 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Copyright (C) 2015-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) This Source Code Form is subject to the
# terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain
# one at http://mozilla.org/MPL/2.0/.

cmake_minimum_required(VERSION 3.15)

set(EXAMPLE_CONFIG_FILES
"../config/vsomeip.json"
Expand All @@ -14,22 +15,53 @@ set(EXAMPLE_CONFIG_FILES

# Examples
add_executable(request-sample request-sample.cpp ${EXAMPLE_CONFIG_FILES})
target_link_libraries(request-sample ${VSOMEIP_NAME} ${Boost_LIBRARIES} ${DL_LIBRARY})
target_link_libraries(
request-sample
vsomeip3
Boost::system
DL_INTERFACE
)

add_executable(response-sample response-sample.cpp ${EXAMPLE_CONFIG_FILES})
target_link_libraries(response-sample ${VSOMEIP_NAME} ${Boost_LIBRARIES} ${DL_LIBRARY})
target_link_libraries(
response-sample
vsomeip3
Boost::system
DL_INTERFACE
)

add_executable(subscribe-sample subscribe-sample.cpp ${EXAMPLE_CONFIG_FILES})
target_link_libraries(subscribe-sample ${VSOMEIP_NAME} ${Boost_LIBRARIES} ${DL_LIBRARY})
target_link_libraries(
subscribe-sample
vsomeip3
Boost::system
DL_INTERFACE
)

add_executable(notify-sample notify-sample.cpp ${EXAMPLE_CONFIG_FILES})
target_link_libraries(notify-sample ${VSOMEIP_NAME} ${Boost_LIBRARIES} ${DL_LIBRARY})
target_link_libraries(
notify-sample
vsomeip3
Boost::system
DL_INTERFACE
)

add_dependencies(examples request-sample response-sample subscribe-sample notify-sample)
add_dependencies(
examples
request-sample
response-sample
subscribe-sample
notify-sample
)

install (
TARGETS request-sample response-sample subscribe-sample notify-sample
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
install(
TARGETS request-sample
response-sample
subscribe-sample
notify-sample
RUNTIME
DESTINATION "${INSTALL_BIN_DIR}"
COMPONENT bin
)

###################################################################################################
# ######################################################################################################################
8 changes: 5 additions & 3 deletions examples/hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project (vSomeIPHelloWorld)

find_package(Threads REQUIRED)

set(VSOMEIP_NAME "vsomeip3")
include(GNUInstallDirs)

# create_target("executable")
function(create_target executable)
Expand All @@ -21,6 +21,10 @@ function(create_target executable)
target_include_directories(vsomeip_hello_world_${executable} INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)

if(ENABLE_SIGNAL_HANDLING)
target_compile_definitions(vsomeip_hello_world_example INTERFACE VSOMEIP_ENABLE_SIGNAL_HANDLING)
endif()
endfunction()

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

include_directories(${VSOMEIP_INCLUDE_DIRS})

create_target("service")
create_target("client")

Expand Down
31 changes: 19 additions & 12 deletions examples/routingmanagerd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@
# terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain
# one at http://mozilla.org/MPL/2.0/.

cmake_minimum_required(VERSION 3.15)

option(VSOMEIP_INSTALL_ROUTINGMANAGERD "Whether or not to install the routing manager daemon.")

# Daemon
add_executable(routingmanagerd routingmanagerd.cpp)
add_executable(routingmanagerd)
target_sources(routingmanagerd PRIVATE routingmanagerd.cpp)

if(TARGET Genivi::dlt)
target_compile_definitions(routingmanagerd PRIVATE USE_DLT)
target_link_libraries(routingmanagerd PRIVATE Genivi::dlt)
endif()

target_link_libraries(
routingmanagerd
${VSOMEIP_NAME}
${Boost_LIBRARIES}
${DL_LIBRARY}
${DLT_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
PRIVATE vsomeip3
Boost::system
STACKTRACE_INTERFACE
OS_INTERFACE
DL_INTERFACE
RT_INTERFACE
Threads::Threads
)
if(${CMAKE_SYSTEM_NAME} MATCHES "QNX")
target_link_libraries(routingmanagerd socket)
endif()
add_dependencies(routingmanagerd ${VSOMEIP_NAME})

option(VSOMEIP_INSTALL_ROUTINGMANAGERD "Whether or not to install the routing manager daemon.")

if(VSOMEIP_INSTALL_ROUTINGMANAGERD)
install(
Expand Down
28 changes: 19 additions & 9 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ find_package(benchmark)
##############################################################################
# google test

# remove export symbols from the cxx flags
string(REPLACE "${EXPORTSYMBOLS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# remove export symbols from the cxx flags. This is messy, but there's no `remove_link_flags` function
get_target_property(os_link_options OS_INTERFACE INTERFACE_LINK_OPTIONS)
foreach(opt IN ITEMS ${os_link_options})
if(opt MATCHES ".*version.script.*.gcc")
list(REMOVE_ITEM os_link_options ${opt})
endif()
endforeach()
unset(opt)
if(os_link_options)
set_target_properties(OS_INTERFACE PROPERTIES INTERFACE_LINK_OPTIONS "${os_link_options}")
endif()
unset(os_link_options)

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

add_custom_target(build_network_tests)
add_dependencies(build_network_tests ${VSOMEIP_NAME})
add_dependencies(build_network_tests ${VSOMEIP_NAME}-e2e)
add_dependencies(build_network_tests ${VSOMEIP_NAME}-sd)
add_dependencies(build_network_tests vsomeip3)
add_dependencies(build_network_tests vsomeip3-e2e)
add_dependencies(build_network_tests vsomeip3-sd)
add_dependencies(build_tests build_network_tests)

add_custom_target(build_unit_tests)
add_dependencies(build_unit_tests ${VSOMEIP_NAME})
add_dependencies(build_unit_tests ${VSOMEIP_NAME}-sd)
add_dependencies(build_unit_tests vsomeip3)
add_dependencies(build_unit_tests vsomeip3-sd)
add_dependencies(build_tests build_unit_tests)

add_custom_target(build_benchmark_tests)
add_dependencies(build_benchmark_tests ${VSOMEIP_NAME})
add_dependencies(build_benchmark_tests ${VSOMEIP_NAME}-sd)
add_dependencies(build_benchmark_tests vsomeip3)
add_dependencies(build_benchmark_tests vsomeip3-sd)
add_dependencies(build_tests build_benchmark_tests)

##############################################################################
Expand Down
44 changes: 26 additions & 18 deletions test/benchmark_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
# Copyright (C) 2015-2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Copyright (C) 2015-2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) This Source Code Form is subject to the
# terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain
# one at http://mozilla.org/MPL/2.0/.

project ("benchmark_tests_bin" LANGUAGES CXX)
project("benchmark_tests_bin" LANGUAGES CXX)

file (GLOB SRCS main.cpp **/*.cpp)
file(
GLOB
SRCS
main.cpp
**/*.cpp
../common/utility.cpp
)

set(THREADS_PREFER_PTHREAD_FLAG ON)


# ----------------------------------------------------------------------------
# Executable and libraries to link
# ----------------------------------------------------------------------------
add_executable (${PROJECT_NAME} ${SRCS} )
target_link_libraries (
${PROJECT_NAME}
vsomeip3
vsomeip3-cfg
Threads::Threads
${Boost_LIBRARIES}
${DL_LIBRARY}
benchmark::benchmark
gtest
vsomeip_utilities
add_executable(vsomeip3-benchmark-tests)
target_sources(vsomeip3-benchmark-tests PRIVATE ${SRCS})
target_link_libraries(
vsomeip3-benchmark-tests
PRIVATE vsomeip3
vsomeip3-cfg
vsomeip_utilities
Threads::Threads
Boost::filesystem
Boost::system
benchmark::benchmark
gtest
DL_INTERFACE
)
set_target_properties(vsomeip3-benchmark-tests PROPERTIES OUTPUT_NAME ${PROJECT_NAME})

add_dependencies(build_benchmark_tests ${PROJECT_NAME})
add_dependencies(build_benchmark_tests vsomeip3-benchmark-tests)
20 changes: 11 additions & 9 deletions test/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,32 @@ file (GLOB INC include/common/*.hpp, include/common/vsomeip_app_utilities/*.hpp)
# Declare the library
# ----------------------------------------------------------------------------
add_library (
${PROJECT_NAME} SHARED
vsomeip_utilities
${SRC}
${INC}
)

TARGET_LINK_LIBRARIES (
${PROJECT_NAME}
target_link_libraries (
vsomeip_utilities
PUBLIC
${VSOMEIP_NAME}
${Boost_LIBRARIES}
${DL_LIBRARY}
${TEST_LINK_LIBRARIES}
vsomeip3
PRIVATE
Boost::system
Boost::filesystem
INTERFACE
DL_INTERFACE
)

# ----------------------------------------------------------------------------
# Specify here the include directories exported
# by this library
# ----------------------------------------------------------------------------
target_include_directories (
${PROJECT_NAME}
vsomeip_utilities
PUBLIC include
PRIVATE src
)

if (MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
set_target_properties(vsomeip_utilities PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif ()
4 changes: 2 additions & 2 deletions test/internal_routing_disabled_acceptance_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ endif()

project(internal_routing_disabled_acceptance_test LANGUAGES CXX)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wconversion -Wextra")
add_compile_options(-pedantic -Wall -Wconversion -Wextra)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(THREADS_PREFER_PTHREAD_FLAG ON)

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

if (${CMAKE_SYSTEM_NAME} MATCHES "QNX")
target_compile_definitions(${PROJECT_NAME} PRIVATE _QNX_SOURCE)
Expand Down
4 changes: 2 additions & 2 deletions test/network_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ endfunction()
function(targets_link_default_libraries targets)
foreach(target ${targets})
target_link_libraries(${target}
${VSOMEIP_NAME}
${Boost_LIBRARIES}
vsomeip3
Boost::system
${DL_LIBRARY}
${TEST_LINK_LIBRARIES}
${DLT_LIBRARIES}
Expand Down
2 changes: 1 addition & 1 deletion test/network_tests/client_id_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ add_executable(client_id_test_utility

# Link vsomeip configuration libraries.
target_link_libraries(client_id_test_utility
${VSOMEIP_NAME}-cfg
vsomeip3-cfg
)

# Add build dependencies and link libraries to executables.
Expand Down
2 changes: 1 addition & 1 deletion test/network_tests/configuration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ add_executable(configuration_test

# Link vsomeip configuration libraries.
target_link_libraries(configuration_test
${VSOMEIP_NAME}-cfg
vsomeip3-cfg
)

# Add build dependencies and link libraries to executable.
Expand Down
2 changes: 1 addition & 1 deletion test/network_tests/malicious_data_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ add_executable(malicious_data_test_msg_sender

# Link the vsomeip-sd library to the executable.
target_link_libraries(malicious_data_test_msg_sender
${VSOMEIP_NAME}-sd
vsomeip3-sd
)

# Add build dependencies and link libraries to executables.
Expand Down
2 changes: 1 addition & 1 deletion test/network_tests/npdu_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ if(NOT TESTS_BAT AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "QNX")

# Link executables to vsomeip-cfg.
foreach(target ${executables})
target_link_libraries(${target} ${VSOMEIP_NAME}-cfg)
target_link_libraries(${target} vsomeip3-cfg)
endforeach()

# Add custom test command.
Expand Down
2 changes: 1 addition & 1 deletion test/network_tests/offer_tests/offer_test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifdef ANDROID
#include "../../implementation/configuration/include/internal_android.hpp"
#else
#include "../../implementation/configuration/include/internal.hpp"
#include "internal.hpp"
#endif // ANDROID

#include "offer_test_globals.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifdef ANDROID
#include "../../implementation/configuration/include/internal_android.hpp"
#else
#include "../../implementation/configuration/include/internal.hpp"
#include "internal.hpp"
#endif

#include "offered_services_info_test_globals.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifdef ANDROID
#include "../../implementation/configuration/include/internal_android.hpp"
#else
#include "../../implementation/configuration/include/internal.hpp"
#include "internal.hpp"
#endif // ANDROID

#include "offered_services_info_test_globals.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ add_executable(pending_subscription_test_sd_msg_sender
)

# Link vsomeip-sd to executable.
target_link_libraries(pending_subscription_test_sd_msg_sender ${VSOMEIP_NAME}-sd)
target_link_libraries(pending_subscription_test_sd_msg_sender vsomeip3-sd)

# Add build dependencies and link libraries to executables.
set(executables
Expand Down
Loading

0 comments on commit f3cabc5

Please sign in to comment.