-
Notifications
You must be signed in to change notification settings - Fork 763
cmake: surface headers in Visual Studio solution #1222
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
base: main
Are you sure you want to change the base?
Changes from 3 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 |
|---|---|---|
|
|
@@ -17,7 +17,51 @@ target_compile_features(GSL INTERFACE "cxx_std_14") | |
| # Setup include directory | ||
| add_subdirectory(include) | ||
|
|
||
| target_sources(GSL INTERFACE $<BUILD_INTERFACE:${GSL_SOURCE_DIR}/GSL.natvis>) | ||
| file(GLOB GSL_HEADER_FILES | ||
| RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/include" | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/include/gsl/*" | ||
| ) | ||
| list(SORT GSL_HEADER_FILES) | ||
|
|
||
| # Build/install interface lists ensure CMake is happy when exporting headers via | ||
| # INTERFACE sources. Absolute paths would be rejected by newer CMake versions | ||
|
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. nit: "Newer" may be true now but won't be true in the future. Any chance you know which version of CMake starts throwing the error?
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. I believe it's 4.1.2, below that didn't throw for me. |
||
| # (discovered while testing with 4.1). | ||
|
carsonRadtke marked this conversation as resolved.
Outdated
|
||
| set(GSL_HEADER_INTERFACE_SOURCES) | ||
| foreach(header ${GSL_HEADER_FILES}) | ||
| list(APPEND GSL_HEADER_INTERFACE_SOURCES | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/${header}> | ||
| $<INSTALL_INTERFACE:include/${header}> | ||
| ) | ||
| endforeach() | ||
|
|
||
| target_sources(GSL INTERFACE | ||
| ${GSL_HEADER_INTERFACE_SOURCES} | ||
|
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. suggestion: According to https://github.com/microsoft/GSL/pull/1112/files#r1190452831 this only affects VS solutions. Let's move it into your new |
||
| $<BUILD_INTERFACE:${GSL_SOURCE_DIR}/GSL.natvis> | ||
| ) | ||
|
|
||
| if (CMAKE_GENERATOR MATCHES "Visual Studio") | ||
|
carsonRadtke marked this conversation as resolved.
|
||
| # Visual Studio still needs concrete file paths for solution grouping. | ||
| set(GSL_HEADER_ABSOLUTE_PATHS) | ||
| foreach(header ${GSL_HEADER_FILES}) | ||
| list(APPEND GSL_HEADER_ABSOLUTE_PATHS ${GSL_SOURCE_DIR}/include/${header}) | ||
| endforeach() | ||
| source_group(TREE ${GSL_SOURCE_DIR}/include PREFIX "Header Files" FILES ${GSL_HEADER_ABSOLUTE_PATHS}) | ||
|
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.
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. I added a source_group call, the docs should land in the solution items node now. |
||
|
|
||
| set(GSL_SOLUTION_FILES | ||
| ${GSL_SOURCE_DIR}/.clang-format | ||
| ${GSL_SOURCE_DIR}/.gitattributes | ||
| ${GSL_SOURCE_DIR}/.gitignore | ||
| ${GSL_SOURCE_DIR}/CMakeSettings.json | ||
| ${GSL_SOURCE_DIR}/CONTRIBUTING.md | ||
| ${GSL_SOURCE_DIR}/LICENSE | ||
| ${GSL_SOURCE_DIR}/README.md | ||
| ${GSL_SOURCE_DIR}/SECURITY.md | ||
| ${GSL_SOURCE_DIR}/ThirdPartyNotices.txt | ||
| ) | ||
|
|
||
| set_property(DIRECTORY PROPERTY VS_SOLUTION_ITEMS ${GSL_SOLUTION_FILES}) | ||
|
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. issue: The From what I understand, before 4.0.0 there was no way of adding arbitrary files to VS solutions. What you'll need to do is create a custom target and add the files in the GSL workspace to that target. Something like: And that should probably be the bulk of the change. https://cmake.org/cmake/help/latest/prop_dir/VS_SOLUTION_ITEMS.html |
||
| source_group("Solution Items" FILES ${GSL_SOLUTION_FILES}) | ||
| endif() | ||
|
|
||
| if (GSL_TEST) | ||
| enable_testing() | ||
|
|
||

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.
nit: According to the docs, the result of
file(GLOB, ...is already sorted.https://cmake.org/cmake/help/latest/command/file.html#filesystem