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

enable c++20 #173

Merged
merged 10 commits into from
Apr 9, 2024
Merged

enable c++20 #173

merged 10 commits into from
Apr 9, 2024

Conversation

jungleraptor
Copy link
Contributor

@jungleraptor jungleraptor commented Mar 25, 2024

Adds a couple of functions that are essentially necessary to enable using libc++ and clang-15 with C++20

I tested locally on mac with clang-15 and libc++

@jungleraptor jungleraptor marked this pull request as ready for review April 3, 2024 20:10
@jungleraptor jungleraptor requested a review from a team as a code owner April 3, 2024 20:10
@jungleraptor jungleraptor requested a review from RReichert April 3, 2024 20:19
Copy link

@pcrumley pcrumley left a comment

Choose a reason for hiding this comment

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

Wait for @RReichert approval before merging plz

Copy link
Contributor

@RReichert RReichert left a comment

Choose a reason for hiding this comment

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

Although the code works, I question if this is the best way forward. I would recommend something like this:

function(check_libcpp success)
  check_cxx_source_compiles("
    #include <iostream>
    int a =
    #ifdef _LIBCPP_VERSION
      1;
    #else
      kdfasfdl
    #endif
    int main() {
      return 0;
    }
  " ${success})
endfunction()

Where the function returns the true/false results. Its the responsibility of the caller to than add the definition to the compiler via target_compile_definitions. Using -D command line option is compiler specific way to add definitions, other compilers might not follow that approach (even though everything we support currently does).

I'd imagine that these checks would be used by one of the swift_add_* target functions to add the definitions to the source files, as PUBLIC definitions.

Copy link

sonarqubecloud bot commented Apr 8, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@jungleraptor
Copy link
Contributor Author

jungleraptor commented Apr 8, 2024

Although the code works, I question if this is the best way forward. I would recommend something like this:

function(check_libcpp success)
  check_cxx_source_compiles("
    #include <iostream>
    int a =
    #ifdef _LIBCPP_VERSION
      1;
    #else
      kdfasfdl
    #endif
    int main() {
      return 0;
    }
  " ${success})
endfunction()

Where the function returns the true/false results. Its the responsibility of the caller to than add the definition to the compiler via target_compile_definitions. Using -D command line option is compiler specific way to add definitions, other compilers might not follow that approach (even though everything we support currently does).

That was mostly for readability - _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES would also work fine with target_compile_definitions - I just thought that it would make what we're doing more obvious for a less cmake savvy future reader (cmake's syntax for setting a variable isn't exactly what I'd call expressive). I doubt that in practice we'd use this standard library with a non gcc/clang standard library.

I'd imagine that these checks would be used by one of the swift_add_* target functions to add the definitions to the source files, as PUBLIC definitions.

I agree with your overall point. It's not a good API - we're writing it to a specific implementation issue instead of providing an interface for the caller.

I've updated the functions to just be pass/fail and then the caller can figure out what to do with the result.

@jungleraptor jungleraptor merged commit 117b3f7 into master Apr 9, 2024
2 checks passed
@jungleraptor jungleraptor deleted the isaac/cpp20 branch April 9, 2024 22:27
woodfell added a commit to swift-nav/libsbp that referenced this pull request Apr 29, 2024
Automated PR by Jenkins. If CI has passed successfully, merge away!



**cmake**  f5113f7d  ->  117b3f73
-  117b3f73  :  enable c++20 (swift-nav/cmake#173)
-  436d339a  :  Handle new suitesparse version (swift-nav/cmake#171)


This pull request was created by
https://jenkins.ci.swift-nav.com/job/CI%20Infra/job/submodule-update/17095/.

Co-authored-by: Matt Woodward <[email protected]>
RReichert pushed a commit to swift-nav/albatross that referenced this pull request May 10, 2024
…485)

Automated PR by Jenkins. If CI has passed successfully, merge away!



**cmake**  436d339a  ->  68306be8
-  68306be8  :  ASIO gRPC boost container fix (swift-nav/cmake#174)
-  117b3f73  :  enable c++20 (swift-nav/cmake#173)


This pull request was created by
https://jenkins.ci.swift-nav.com/job/CI%20Infra/job/submodule-update/17362/.
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.

3 participants