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 Aug 16, 2024
1 parent 514f3bf commit 74c8250
Show file tree
Hide file tree
Showing 14 changed files with 683 additions and 587 deletions.
504 changes: 269 additions & 235 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
)

###################################################################################################
# ######################################################################################################################
48 changes: 27 additions & 21 deletions examples/hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@
# 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 2.8.7)
cmake_minimum_required(VERSION 3.15)
project(vSomeIPHelloWorld)

find_package(Threads REQUIRED)

set(VSOMEIP_NAME "vsomeip3")
include(GNUInstallDirs)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(INSTALL_BIN_DIR
${CMAKE_INSTALL_BINDIR}
CACHE STRING "Installation directory for executables"
)

include_directories(${VSOMEIP_INCLUDE_DIRS})
add_library(vsomeip_hello_world_example INTERFACE)
target_compile_features(vsomeip_hello_world_example INTERFACE cxx_std_17)
if(ENABLE_SIGNAL_HANDLING)
target_compile_definitions(vsomeip_hello_world_example INTERFACE VSOMEIP_ENABLE_SIGNAL_HANDLING)
endif()

add_library(vsomeip_hello_world_service INTERFACE)
target_sources(vsomeip_hello_world_service INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/hello_world_service.hpp")
target_include_directories(vsomeip_hello_world_service INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(vsomeip_hello_world_service INTERFACE vsomeip_hello_world_example)

add_library(vsomeip_hello_world_client INTERFACE)
target_sources(vsomeip_hello_world_client INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/hello_world_client.hpp")
target_link_libraries(vsomeip_hello_world_client INTERFACE vsomeip_hello_world_example)

target_include_directories(vsomeip_hello_world_client INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")

Expand All @@ -27,26 +35,24 @@ if(NOT
MATCHES
"Android"
)
# This will get us acces to VSOMEIP_INCLUDE_DIRS - include directories for vSomeIP VSOMEIP_LIBRARIES - libraries to
# link against
find_package(${VSOMEIP_NAME})
if(NOT ${VSOMEIP_NAME}_FOUND)
message("${VSOMEIP_NAME} was not found. Please specify vsomeip_DIR")
# This will get us acces to the vsomeip target, along with VSOMEIP_INCLUDE_DIRS - include directories for vSomeIP
# VSOMEIP_LIBRARIES - libraries to link against
if(NOT TARGET vsomeip3)
find_package(vsomeip3)
if(NOT vsomeip3_FOUND)
message("vsomeip was not found. Please specify vsomeip_DIR")
endif()
endif()

add_executable(hello_world_service hello_world_service_main.cpp)
target_link_libraries(
hello_world_service
vsomeip_hello_world_service
${VSOMEIP_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(hello_world_service PUBLIC vsomeip_hello_world_service vsomeip3 Threads::Threads)

add_executable(hello_world_client hello_world_client_main.cpp)
target_link_libraries(
hello_world_client
vsomeip_hello_world_client
${VSOMEIP_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
target_link_libraries(hello_world_client PUBLIC vsomeip_hello_world_client vsomeip3 Threads::Threads)

install(
TARGETS hello_world_client hello_world_service RUNTIME
DESTINATION "${INSTALL_BIN_DIR}"
COMPONENT example-hello_world
)
endif()
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
46 changes: 26 additions & 20 deletions test/benchmark_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +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)

find_package(Threads REQUIRED)
find_package(Boost 1.55 COMPONENTS filesystem system REQUIRED)

# ----------------------------------------------------------------------------
# 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)
18 changes: 10 additions & 8 deletions test/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,28 @@ 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
)
7 changes: 2 additions & 5 deletions test/internal_routing_disabled_acceptance_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +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)

find_package(Threads REQUIRED)
find_package(Boost 1.55 COMPONENTS system REQUIRED)

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
Loading

0 comments on commit 74c8250

Please sign in to comment.