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

Visual Studio expands the __cplusplus macro to 199711L by default regardless of C++ std being used. #5

Closed
ttanguay opened this issue Jul 16, 2023 · 5 comments

Comments

@ttanguay
Copy link

https://learn.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170

Using the /Zc:__cplusplus compiler option forces visual studio to set this macro properly.

NOTE: I was able to add lockfree to a project with C++17 support using CPMAddPackage with the following:

CPMAddPackage(
    NAME lockfree
    GITHUB_REPOSITORY DNedic/lockfree
    GIT_TAG 2.0.2
)
if (lockfree_ADDED AND MSVC)
    target_compile_options(lockfree INTERFACE "/Zc:__cplusplus")
endif()
@DNedic
Copy link
Owner

DNedic commented Jul 16, 2023

Hello @ttanguay , thanks for the feedback. On first glance, this should be possible to integrate into our CMakeLists, however I'm interested if you would be able to test it, as I have never used MSVC.

@DNedic
Copy link
Owner

DNedic commented Jul 16, 2023

Apparently this cannot be fixed using CMake without affecting the linked targets, I've created a solution that checks for MSVC and then uses _MSVC_LANG. Please test it and provide feedback if you can.

@ttanguay
Copy link
Author

I will check out your latest commit.

@ttanguay
Copy link
Author

I tested with latest commit and the PopOptional method of spsc::Queue is now available in Visual Studio without needing that target_compile_options in CMake.

I am having some issues with the library when adding with CPMAddPackage. Everything works fine when I tested in main with a globally declared queue. But when I put the queue as a private member of a class I'm getting errors. Not sure if it's some conflict with another header I'm including or I just haven't linked the library in correctly. It works fine if I just include the header files for queue in the project directly. I'll try a few things. Do you have the proper cmake commands to add lockfree to a project using FetchContent... maybe i can use that instead and see if it's just a CPM issue.

Thanks.

@DNedic
Copy link
Owner

DNedic commented Jul 16, 2023

Thanks for the review, I will merge the PR, please open another issue for the CPM problem and post the output you're getting.

Please try the FetchContent with this code snippet:

Include(FetchContent)

FetchContent_Declare(
    lockfree
    GIT_REPOSITORY https://github.com/DNedic/lockfree.git
    GIT_TAG        2.0.2
)

FetchContent_MakeAvailable(lockfree)

@DNedic DNedic closed this as completed Jul 16, 2023
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

No branches or pull requests

2 participants