-
Notifications
You must be signed in to change notification settings - Fork 7
Update CMakeLists, prepare for packaging #31
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,6 @@ | |
| # ignore emacs temp files | ||
| *~ | ||
| \#*\# | ||
|
|
||
| # ignore vscode settings | ||
| .vscode | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,29 +2,87 @@ | |
|
|
||
| cmake_minimum_required(VERSION 3.25) | ||
|
|
||
| project(beman.scope DESCRIPTION "Generic Scope Guard" LANGUAGES CXX) | ||
|
|
||
| enable_testing() | ||
| project( | ||
| beman.scope | ||
| DESCRIPTION "Generic Scope Guard" | ||
| LANGUAGES CXX | ||
| VERSION 0.0.1 | ||
| ) | ||
|
|
||
| # [CMAKE.SKIP_TESTS] | ||
| option( | ||
| BEMAN_SCOPE_BUILD_TESTS | ||
| "Enable building tests and test infrastructure. Default: ON. Values: { ON, OFF }." | ||
| "Enable building tests and test infrastructure. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
edit: I completely misread the rule there -- was also thrown off because as I recall optional sets testing off by default. |
||
| ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| # [CMAKE.SKIP_EXAMPLES] | ||
| option( | ||
| BEMAN_SCOPE_BUILD_EXAMPLES | ||
| "Enable building examples. Default: ON. Values: { ON, OFF }." | ||
| "Enable building examples. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }." | ||
| ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| option( | ||
| BEMAN_SCOPE_INSTALL_CONFIG_FILE_PACKAGE | ||
| "Enable creating and installing a CMake config-file package. Default: ${PROJECT_IS_TOP_LEVEL}. Values: { ON, OFF }." | ||
| ${PROJECT_IS_TOP_LEVEL} | ||
| ) | ||
|
|
||
| include(GNUInstallDirs) | ||
| add_library(beman.scope INTERFACE) | ||
| add_library(beman::scope ALIAS beman.scope) | ||
|
|
||
| # gersemi: off | ||
| set_target_properties( | ||
| beman.scope | ||
| PROPERTIES | ||
| VERIFY_INTERFACE_HEADER_SETS ON | ||
| EXPORT_NAME scope | ||
nickelpro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| target_sources( | ||
| beman.scope | ||
| INTERFACE | ||
| FILE_SET HEADERS | ||
| BASE_DIRS include | ||
| FILES include/beman/scope/scope.hpp | ||
| ) | ||
|
|
||
| install( | ||
| TARGETS beman.scope | ||
| EXPORT beman.scope-targets | ||
| COMPONENT beman.scope | ||
nickelpro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| FILE_SET HEADERS | ||
| ) | ||
| # gersemi: on | ||
|
|
||
| if(BEMAN_SCOPE_INSTALL_CONFIG_FILE_PACKAGE) | ||
| include(GNUInstallDirs) | ||
| include(CMakePackageConfigHelpers) | ||
|
|
||
| write_basic_package_version_file( | ||
| ${CMAKE_CURRENT_BINARY_DIR}/beman.scope-config-version.cmake | ||
| COMPATIBILITY ExactVersion | ||
| ) | ||
|
|
||
| # todo rm add_subdirectory(src/beman/scope) | ||
| install( | ||
| FILES | ||
| cmake/beman.scope-config.cmake | ||
| ${CMAKE_CURRENT_BINARY_DIR}/beman.scope-config-version.cmake | ||
| DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman.scope | ||
| COMPONENT beman.scope | ||
| ) | ||
|
|
||
| install( | ||
| EXPORT beman.scope-targets | ||
| DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/beman.scope | ||
| NAMESPACE beman:: | ||
| COMPONENT beman.scope | ||
| ) | ||
| endif() | ||
|
|
||
| if(BEMAN_SCOPE_BUILD_TESTS) | ||
| enable_testing() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another case where exemplar perhaps should be updated -- in that repo ctest is unconditionally included in the top level project
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been updated multiple time, the consensus formed is to just use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe @nickelpro is correct and any consensus that has been formed around this is incorrect. The question comes down to are we using 'the dashboard' -- we most certainly are not currently.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think bemanproject/exemplar#153 or bemanproject/exemplar#109 mentioned anything about dashboard.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more about consistently define the test target. Please check the back-and-forth reasoning behind these PRs:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't realize this was a beehive already thrice stepped on
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a couple lines in exemplar's CMake that has undergone a lot of discussion and back-and-forth edits.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the expectation is that we add something to the beman standard explaining when we have a recommendation or a requirement. I won't have time in the next few weeks to follow up on that, so if someone else wants to take a pass, please do. Otherwise, hopefully it can wait my other activities (like finalizing the CppCon program) can wrap up. |
||
| add_subdirectory(tests) | ||
| endif() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| include(${CMAKE_CURRENT_LIST_DIR}/beman.scope-targets.cmake) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to open an issue against exemplar repo since an example of this doesn't appear? |
||
|
|
||
| foreach(comp IN LISTS beman.scope_FIND_COMPONENTS) | ||
| if(beman.scope_FIND_REQUIRED_${comp}) | ||
| set(beman.scope_FOUND FALSE) | ||
| return() | ||
| endif() | ||
| endforeach() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,5 +7,5 @@ message("Examples to be built: ${ALL_EXAMPLES}") | |
| foreach(example ${ALL_EXAMPLES}) | ||
| add_executable(${example}) | ||
| target_sources(${example} PRIVATE ${example}.cpp) | ||
| target_include_directories(${example} PRIVATE ${CMAKE_SOURCE_DIR}/include) | ||
| target_link_libraries(${example} PRIVATE beman::scope) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is interesting and something I didn't realize. So I guess modern cmake practice is to add the 'link library', even if there isn't one and let cmake infer the includes. So really the macro has become target_depenencies
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. To address something you commented on here, But for now, you just have to know that |
||
| endforeach() | ||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the recommendation is to use
include(CTest)instead ofenable_testing().See: bemanproject/exemplar#153
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see conversation above
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not fully opposed to reverting this back to
include(CTest), but we should formalize something here.A default, always-on
testtarget is of questionable utility and, in my experience, is more misleading than helpful. Users running thetesttarget without realizing that tests are not enabled are not met with loud failure, which would be the expectation. Instead they must consult the logs to recognize anything has gone wrong at all. To be clear: running thetesttarget with no tests is not a failure. The tests "pass".include(CTest)also drags in many other targets that are totally useless for Beman and make interacting with the generated build system a bear, ie:This is undesirable unless you're getting a lot out of the rest of the
CTestmodule. Beman gets nothing out of theCTestmodule besides the defaulttesttarget discussed above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can move this discussion to an exemplar issue, I'll let this settle for a day or two and if I can't convince the peanut gallery to side with me unwind the testing change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree that it's of questionable utility. It's very helpful for the higher level workflow orchestrator (me as a contributor, a common conan workflow, or a shared github workflow) to know exactly how and when to run tests, especially from a plain vanilla checkout of the code in a plain vanilla environment. Having an always-available test target that, yes, sometimes runs zero tests is a positive validation that all available tests are passing.
We could talk about alternative ways to let the higher-level workflows tool know that there are tests available and in what circumstances, but having an always-on test target that can be augmented or pared down by various
MYREPO_TEST_THIS=ONandMYREPO_TEST_THAT=OFFoptions is a good combination of intuitive and flexible in my experience.I agree that the extra targets are annoying, especially in IDEs that try to expose these via dropdowns, though I'd consider that more annoying than a problem as such. I'm also OK with
enable_testing(), but people feel strongly about being able to inspect and respectBUILD_TESTING, soinclude(CTest)being on always seems to be a compromise in the truest form -- nobody's entirely happy but everyone can live with it. If anyone knows any core CMake engineers that can come up with something that everyone can love whole-heartedly, please let them know!