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

CMake Updates, main branch (2024.11.10.) #41

Closed

Conversation

krasznaa
Copy link
Member

While helping @CarloVarni in setting up the build of traccc on his Mac laptop, we bumped into a warning coming from covfie. While trying to silence that warning, I found that I really didn't like the target names used by this project. 🤔

The main change of this PR is to add a covfie_ prefix to the name of every library and executable of the project. So that it wouldn't claim basic names like core, cpu, benchmark, etc. for itself. (The last one, benchmark, is I guess the reason why the project is able to build GoogleTest by itself, but not GoogleBenchmark... Since the latter uses the target name benchmark itself for its own library target...)

I have some other ideas/plans as well, but these updates should not be too controversial. (The others may be...)

The removal of COVFIE_REQUIRE_CXX20 is just an added bonus. 😉

Copy link
Member

@stephenswat stephenswat left a comment

Choose a reason for hiding this comment

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

I'm not generally opposed to this, but the changes are far too extensive; let's not update the examples, tests, or benchmarks; they are not installed anyway so there are no name collisions with them. For the library targets, can't we just install them into a namespace to solve the problem?

Comment on lines +9 to +15
add_library(covfie_benchmark test_field.cpp)

target_include_directories(benchmark PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(covfie_benchmark PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(benchmark PUBLIC core)
target_link_libraries(covfie_benchmark PUBLIC covfie::core)

target_compile_definitions(benchmark PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(covfie_benchmark PRIVATE _CRT_SECURE_NO_WARNINGS)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not on board with the benchmarks, tests, and examples being renamed; these should never be installed anyway, so there is no way for any name collisions to occur.

#
# 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/.

# Create the benchmark executable from the individual files.
add_executable(benchmark_cpu benchmark_cpu.cpp)
add_executable(covfie_benchmark_cpu benchmark_cpu.cpp)
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep the original name on this.

@@ -12,15 +12,15 @@ enable_language(CUDA)
include(covfie-compiler-options-cuda)

# Create the benchmark executable from the individual files.
add_executable(benchmark_cuda benchmark_cuda.cu)
add_executable(covfie_benchmark_cuda benchmark_cuda.cu)
Copy link
Member

Choose a reason for hiding this comment

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

And on this.

Comment on lines +25 to +32
set_target_properties(
covfie_core
PROPERTIES
EXPORT_NAME
core
)

install(TARGETS covfie_core EXPORT ${PROJECT_NAME}Targets)
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to make this so complicated? Can't we just set install(... NAMESPACE something_)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't touch the code that specifies the NAMESPACE. The EXPORT_NAME needs to be specified, because without it, the exported library would now be called covfie::covfie_core.

This is exactly how the "trick" of using vecmem::core, detray::core, etc. is achieved, whether or not we're using the project directly, or we're finding an installed version of it. (With the "actual target names" being vecmem_core, detray_core, etc.)

Copy link
Member

Choose a reason for hiding this comment

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

Right, but this is what I am saying, just like Google Benchmark does it, the target should be named e.g. core and then the namespace should be added to it, so that the full name becomes covfie::core.

@krasznaa
Copy link
Member Author

The problem is not with installed versions of Covfie. The problem is when you "compile" Covfie together with a client project. Whether they are installed or not, unless the user makes sure not to build any of Covfie's tests or benchmarks, those target names will now have to be reserved for Covfie. So better no client use benchmark_cuda in their own code...

I really insist that we give covfie specific names to all these targets.

@krasznaa
Copy link
Member Author

Also, note that you are not able to currently build GoogleBenchmark together with / as part of covfie, because of:

https://github.com/google/benchmark/blob/main/src/CMakeLists.txt#L20

Google also decided to use the target name benchmark. That's why you have to build GoogleBenchmark separately from Covfie at the moment in all cases.

@stephenswat
Copy link
Member

Also, note that you are not able to currently build GoogleBenchmark together with / as part of covfie, because of:

https://github.com/google/benchmark/blob/main/src/CMakeLists.txt#L20

Google also decided to use the target name benchmark. That's why you have to build GoogleBenchmark separately from Covfie at the moment in all cases.

Indeed, as Google Benchmark also makes handy use of the namespacing feature, see https://github.com/google/benchmark/blob/main/src/CMakeLists.txt#L114

@stephenswat
Copy link
Member

The problem is not with installed versions of Covfie. The problem is when you "compile" Covfie together with a client project. Whether they are installed or not, unless the user makes sure not to build any of Covfie's tests or benchmarks, those target names will now have to be reserved for Covfie. So better no client use benchmark_cuda in their own code...

I really insist that we give covfie specific names to all these targets.

As a compromise, we can make it a configuration error for NOT PROJECT_IS_TOP_LEVEL AND COVFIE_BUILD_BENCHMARKS to be true. Is that okay for you?

@krasznaa
Copy link
Member Author

The problem is not with installed versions of Covfie. The problem is when you "compile" Covfie together with a client project. Whether they are installed or not, unless the user makes sure not to build any of Covfie's tests or benchmarks, those target names will now have to be reserved for Covfie. So better no client use benchmark_cuda in their own code...
I really insist that we give covfie specific names to all these targets.

As a compromise, we can make it a configuration error for NOT PROJECT_IS_TOP_LEVEL AND COVFIE_BUILD_BENCHMARKS to be true. Is that okay for you?

Why would that be a good setup? Is it evil from clients to want to build the covfie tests / benchmarks as part of their own project?

@krasznaa
Copy link
Member Author

Also, note that you are not able to currently build GoogleBenchmark together with / as part of covfie, because of:
https://github.com/google/benchmark/blob/main/src/CMakeLists.txt#L20
Google also decided to use the target name benchmark. That's why you have to build GoogleBenchmark separately from Covfie at the moment in all cases.

Indeed, as Google Benchmark also makes handy use of the namespacing feature, see https://github.com/google/benchmark/blob/main/src/CMakeLists.txt#L114

But you understand the issue, right? 😕 You can't have two subdirectories in a single project declaring libraries with the same names. The aliases don't matter in this case. If CMake sees two targets with the same name (core, benchmark, etc.) then it will not generate build files.

@stephenswat
Copy link
Member

Why would that be a good setup? Is it evil from clients to want to build the covfie tests / benchmarks as part of their own project?

I really don't see a legitimate use case for this. 🤔

@krasznaa
Copy link
Member Author

Why would that be a good setup? Is it evil from clients to want to build the covfie tests / benchmarks as part of their own project?

I really don't see a legitimate use case for this. 🤔

With Covfie being a header-only library, clients wanting to test their own build setup through the built-in tests and benchmarks of the project may not be as crazy as you might think. 🤔

The C++20 standard is always required in the code since a while,
the flag was not doing anything.
This is to ensure that common names like "core" and "cpu" would
not clash with target names used in client projects.
@krasznaa krasznaa force-pushed the CMakeUpdates-main-20241110 branch from d387f02 to b40a9d3 Compare November 15, 2024 14:23
stephenswat added a commit to stephenswat/covfie that referenced this pull request Nov 15, 2024
Following the discussion in acts-project#41, this commit makes it a configuration
error to request the builds of tests, benchmarks, or examples if covfie
is not the top level project. Also removes vestigial Google Test code.
@stephenswat
Copy link
Member

As a compromise, we can make it a configuration error for NOT PROJECT_IS_TOP_LEVEL AND COVFIE_BUILD_BENCHMARKS to be true. Is that okay for you?

FYI I thought about it a bit more and became increasingly convinced that this is the way to go, so I implemented it this way and then renamed the library targets. I also took your COVFIE_REQUIRE_CXX20 commit verbatim which was great, thanks for that. I assume the issue is now resolved so I'll close this PR, but please feel free to reopen if you have any more concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants