Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize CMake code #734

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft

Modernize CMake code #734

wants to merge 16 commits into from

Conversation

kheaactua
Copy link
Contributor

@kheaactua kheaactua commented Jun 28, 2024

Status

For the moment this is still a WIP. I would love community feedback on this PR so that we can produce a modern CMake setup that functions well for everyone.

I suspect the cleanest way to organize the commits would be to squash them.

Description

General CMakeLists improvements - cmake v2→v3

  • Included a .cmake-format file, and ran applied it to the main CMakeList files in this project.
    • The format file does a poor job on if and foreach blocks, but I believe overall it does a better job that the default settings. The main benefit is a consistent format
  • Use targets instead of lib/include variables in CMake
  • [Conditionally] Linking DLT as a target
  • Write internal.hpp to build directory instead of source to prevent needless rebuilds
    • The include directives for this file are also updated in the code to use include paths rather than relative paths.
  • Remove hard coded CMAKE_VERBOSE_MAKEFILE, this should be injected by the user if so desired
  • "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.

Misc

  • Added more ignore rules to for common IDEs

CMakeLists.txt Outdated
Comment on lines 112 to 124
include(CMakeDependentOption)
cmake_dependent_option(ENABLE_WERROR "Enable -Werror flag" ON "CMAKE_SYSTEM_NAME MATCHES LINUX" OFF)
if (ENABLE_WERROR)
message(STATUS "Enabling -Werror flag")
add_compile_options(-Werror)
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you separated this flag from the others related to LINUX?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -Werror blocks my linux builds :) Honestly I don't think any component should ever include this. -Werror should be up to the toolchain - as the toolchain usually specifies which compile options to use, which warnings to watch for, and whether warnings should be allowed.

@kheaactua
Copy link
Contributor Author

I am still working on this PR, I'll likely rebase to Fabio's 3.5.x branch. Stuff just takes time. :)

@duartenfonseca
Copy link
Collaborator

I am still working on this PR, I'll likely rebase to Fabio's 3.5.x branch. Stuff just takes time. :)

In that case maybe i will check this PR later! great job anyway, it has interesting improvements

@kheaactua kheaactua force-pushed the modern_cmake branch 6 times, most recently from 46c5cac to da94c06 Compare August 16, 2024 21:29
@duartenfonseca
Copy link
Collaborator

duartenfonseca commented Sep 9, 2024

@kheaactua tried to build this new CMake code and got a failure.
I did :
cmake -B build
cmake --build build

I have ubuntu 22.04, gcc version 11.4

the error i got was the following:
/home/duartef/repos/covesa/vsomeip_duarte/vsomeip/implementation/endpoints/src/../../routing/include/../../endpoints/include/netlink_connector.hpp:197:47: error: ‘VSOMEIP_MAX_NETLINK_RETRIES’ was not declared in this scope
197 | static const std::uint32_t max_retries_ = VSOMEIP_MAX_NETLINK_RETRIES;

@kheaactua
Copy link
Contributor Author

@duartenfonseca I'll take a look! Was this on Fabio's 3.5.x? He did push a change to the network tests a few days back.

I'll also fix that conflict that appeared.

@duartenfonseca
Copy link
Collaborator

@kheaactua i just did a checkout to your branch and tried to build!

@duartenfonseca
Copy link
Collaborator

@kheaactua is the increase of minimum version on cmake is really necessary? from our side, we would like to avoid that

@kheaactua
Copy link
Contributor Author

@kheaactua is the increase of minimum version on cmake is really necessary? from our side, we would like to avoid that

I raised it to 3.15 to accommodate Conan 2.0. From the author:

Conan 2.0 requires at least CMake 3.15.

Though not yet posted, I've been prepping covesa/capi-conan, covesa/capi-docker, and some others that all use Conan to set up CommonAPI environments.

Curious though, what would be desirable about staying at 3.13? With 3.23 vsomeip could use file sets for a cleaner install of the includes

Locally I jack it up to 3.30 :)

CMakeLists.txt Outdated Show resolved Hide resolved
@duartenfonseca
Copy link
Collaborator

@kheaactua is the increase of minimum version on cmake is really necessary? from our side, we would like to avoid that

I raised it to 3.15 to accommodate Conan 2.0. From the author:

Conan 2.0 requires at least CMake 3.15.

Though not yet posted, I've been prepping covesa/capi-conan, covesa/capi-docker, and some others that all use Conan to set up CommonAPI environments.

Curious though, what would be desirable about staying at 3.13? With 3.23 vsomeip could use file sets for a cleaner install of the includes

Locally I jack it up to 3.30 :)

I understand your reasons, but if we could find a way to keep the CMake changes without increasing from 3.13 would be best. From our internal process, increasing this there would need to be a strong justification for this change.

@kheaactua
Copy link
Contributor Author

kheaactua commented Oct 16, 2024

@kheaactua is the increase of minimum version on cmake is really necessary? from our side, we would like to avoid that

I raised it to 3.15 to accommodate Conan 2.0. From the author:

Conan 2.0 requires at least CMake 3.15.

Though not yet posted, I've been prepping covesa/capi-conan, covesa/capi-docker, and some others that all use Conan to set up CommonAPI environments.
Curious though, what would be desirable about staying at 3.13? With 3.23 vsomeip could use file sets for a cleaner install of the includes
Locally I jack it up to 3.30 :)

I understand your reasons, but if we could find a way to keep the CMake changes without increasing from 3.13 would be best. From our internal process, increasing this there would need to be a strong justification for this change.

I could make Conan apply a patch, that would solve the issue with Conan. I'll give it a try with 3.13 as soon as I can. I may have to remove some of the generator expressions to support 3.13 as well.

Also, for me the Docker setup for the network tests fails with CMake 3.22 and below.

That said, I would strongly encourage the update.

  • 3.26 supports LTO detection on QNX
  • 3.26 improves the debug on try_compile - really helpful when trying to build on new systems
  • 3.23 brings target_source( FILE_SET ) for better installation
  • 3.18 and 3.30 improve how Boost is found (even as far back as 3.16 find_package(boost) is harder than it should be)
  • 3.15 improves generator expressions
  • 3.14 and 3.27 improve the build debug
  • ~3.30 (I think) improves handling of generated files (helpful for CommonAPI)

Just a tonne of updates that help both with QNX and really just in general.

@kheaactua kheaactua force-pushed the modern_cmake branch 5 times, most recently from e2c4cdc to 9c53ff7 Compare November 26, 2024 13:19
@duartenfonseca duartenfonseca changed the base branch from master to vsomeip_3.5.3 November 26, 2024 17:07
@kheaactua kheaactua force-pushed the modern_cmake branch 2 times, most recently from d56e11e to 38c935a Compare November 26, 2024 17:53
@duartenfonseca duartenfonseca force-pushed the vsomeip_3.5.3 branch 2 times, most recently from 2638cb5 to 74bc25d Compare November 27, 2024 17:11
Comment on lines 25 to 27
if(ENABLE_SIGNAL_HANDLING)
target_compile_definitions(vsomeip_hello_world_example INTERFACE VSOMEIP_ENABLE_SIGNAL_HANDLING)
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed, since the VSOMEIP_ENABLE_SIGNAL_HANDLING has already been set on the main cmakelists as an add_definitions() command

Copy link
Contributor Author

@kheaactua kheaactua Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in the top level CMake file, but hello_world/CMakeLists.txt appears to be written to be a self contained project - and nothing uses add_subdirectory to include it in the build.

Comment on lines 17 to 26
# 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this way, the -Wl,-export-dynamic part of the EXPORT_SYMBOLS was not being removed. my suggestion would be to re-add the EXPORT_SYMBOLS as a list on the main CMakeLists.txt as:

set(EXPORTSYMBOLS
      -Wl,-export-dynamic
      -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exportmap.gcc) 

add that to the OS_INTERFACE:

  if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    # This is only relevant for GCC and causes warnings on Clang
    target_link_options(
      OS_INTERFACE
      INTERFACE
      -Wno-tsan -Wl,-z,relro,-z,now
      ${EXPORTSYMBOLS}
    )

and here instead of this foreach loop, use this one:

foreach(symbol ${EXPORTSYMBOLS})
    list(REMOVE_ITEM os_link_options ${symbol})
endforeach()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would make it simpler. I'll give it a try

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think it works better. Fixed in bf943c5

@kheaactua kheaactua force-pushed the modern_cmake branch 3 times, most recently from 1e8136d to 38685d1 Compare January 16, 2025 20:59
@kheaactua
Copy link
Contributor Author

The build error is weird.. Though I do get a similar one locally:

Run on (40 X 4800 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x20)
  L1 Instruction 32 KiB (x20)
  L2 Unified 2048 KiB (x20)
  L3 Unified 38400 KiB (x1)
Load Average: 2.77, 3.31, 3.34
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
-----------------------------------------------------------------------------------------------------------------
Benchmark                                                                       Time             CPU   Iterations
-----------------------------------------------------------------------------------------------------------------
BM_check_credentials_policies_not_loaded                                     2.82 ns         2.82 ns    265491910
BM_check_credentials_policies_loaded_invalid_values                          2.66 ns         2.66 ns    259855302
BM_check_credentials_policies_loaded_valid_values                            3.09 ns         3.09 ns    243618071
BM_check_credentials_policies_loaded_audit_mode_invalid_values               3.17 ns         3.17 ns    221014699
BM_check_credentials_policies_loaded_audit_mode_valid_values                 3.12 ns         3.12 ns    227970630
BM_check_routing_credentials_policies_not_loaded                              399 ns          399 ns      1713574
BM_check_routing_credentials_policies_loaded_invalid_values                   407 ns          407 ns      1777926
BM_check_routing_credentials_policies_loaded_valid_values                     409 ns          409 ns      1706650
BM_check_routing_credentials_policies_loaded_lazy_load_invalid_values         399 ns          398 ns      1760846
BM_check_routing_credentials_policies_loaded_lazy_load_valid_values           403 ns          403 ns      1712075
BM_get_client_to_sec_client_mapping_valid_values                             17.0 ns         17.0 ns     41920684
BM_get_client_to_sec_client_mapping_invalid_values                           14.2 ns         14.2 ns     49793167
BM_get_clients                                                               32.7 ns         32.7 ns     21492018
BM_get_sec_client_to_clients_mapping_valid_values                            35.1 ns         35.1 ns     19821518
BM_get_sec_client_to_clients_mapping_invalid_values                          18.8 ns         18.8 ns     36769476
BM_is_client_allowed_policies_not_loaded                                     3.18 ns         3.18 ns    218177708
BM_is_client_allowed_policies_loaded_valid_values                            2.90 ns         2.90 ns    241320837
BM_is_client_allowed_cache_policies_loaded                                   2.89 ns         2.89 ns    241970142
BM_is_client_allowed_policies_loaded_invalid_values                          2.99 ns         2.99 ns    234260981
BM_is_client_allowed_policies_loaded_deny_valid_values                       2.96 ns         2.96 ns    231424899
BM_is_client_allowed_policies_loaded_audit_mode_valid_values                 2.91 ns         2.91 ns    239781608
BM_is_client_allowed_cache_policies_loaded_audit_mode                        2.90 ns         2.90 ns    240085452
BM_is_client_allowed_policies_loaded_audit_mode_invalid_values               2.94 ns         2.94 ns    234957408
BM_is_client_allowed_policies_loaded_audit_mode_deny_valid_values            3.19 ns         3.19 ns    217727636
BM_is_offer_allowed_policies_not_loaded                                      3.49 ns         3.49 ns    195235638
BM_is_offer_allowed_policies_loaded_valid_values                             3.51 ns         3.51 ns    199208643
BM_is_offer_allowed_policies_loaded_invalid_values                           3.52 ns         3.52 ns    200094570
BM_is_offer_allowed_policies_loaded_deny_valid_values                        3.55 ns         3.55 ns    199501975
BM_is_offer_allowed_policies_loaded_audit_mode_valid_values                  3.52 ns         3.52 ns    200815148
BM_is_offer_allowed_policies_loaded_audit_mode_invalid_values                3.55 ns         3.55 ns    200287792
BM_is_offer_allowed_policies_loaded_audit_mode_deny_valid_values             3.56 ns         3.56 ns    196855102
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
zsh: IOT instruction (core dumped)

Not sure what the cause is, will investigate.

@kheaactua kheaactua force-pushed the modern_cmake branch 2 times, most recently from f92a8ee to 3d85504 Compare January 20, 2025 14:42
kheaactua and others added 4 commits January 20, 2025 12:13
Included a .cmake-format file, and ran applied it to the main CMakeList files in this project.
- 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
Co-authored-by: "Duarte Fonseca" <[email protected]>
Co-authored-by: "Matthew Russell" <[email protected]>
@kheaactua kheaactua force-pushed the modern_cmake branch 2 times, most recently from 3da3c04 to 4e04a75 Compare January 21, 2025 14:09
…2→v3

Removed redundant VSOMEIP_DLL_COMPILATION on vsomeip target
…cmake v2→v3

Fixing how tests clean EXPORT_SYMBOLS
…ents - cmake v2→v3

Re-introduced -Wno-tsan
Ensuring -O exists in CMAKE_CXX_FLAGS_RELWITHDEBINFO per Duarte's request
…eLists improvements - cmake v2→v3

Removed stacktrace interface, this doesn't work well.  Also set min
boost to 1.66 (same as 3.5.3)
Suggested by Duarte, a better fix is likely to be posted upstream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants