microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.26k stars 6.17k forks source link

How to support diffenrent C++ standards? #15099

Closed playgithub closed 3 years ago

playgithub commented 3 years ago

e.g. C++17 application can not use poppler that is built in C++14.

In CMakeLists.txt

set(CMAKE_CXX_STANDARD 14)

Does it need multiple ports to support different C++ standards, e.g. port poppler-cpp14 for C++14 and port poppler-cpp17 for C++17? Any better way?

JonLiu1993 commented 3 years ago

@playgithub ,You can setting it during the configure call.

vcpkg_configure_cmake(
    ...
    -DCMAKE_CXX_STANDARD 17
)
playgithub commented 3 years ago

@playgithub ,You can setting it during the configure call.

vcpkg_configure_cmake(
    ...
    -DCMAKE_CXX_STANDARD 17
)

But by this who is using C++14 can't use the port.

JonLiu1993 commented 3 years ago

@playgithub ,It can be solved by adding features, adding C++17 as an option to the portifile.cmake file:

if("cxx17" IN_LIST FEATURES)
    set(CXX_STANDARD 17)
else()
    set(CXX_STANDARD 14)
endif()

vcpkg_configure_cmake(
    ...
    -DCXX_STANDARD=${CXX_STANDARD}
)
GreyRaphael commented 2 months ago

For a new version of vcpkg(version 2024-03-14-7d353e869753e5609a1f1a057df3db8fd356e49d), I change the file in ~/vcpkg/ports/avro-cpp/portfile.cmake for the library avro-cpp that I want to use, e.g.-DCMAKE_CXX_STANDARD=20

vcpkg_cmake_configure(
    SOURCE_PATH "${SOURCE_PATH}/lang/c++"
    OPTIONS
        -DBUILD_TESTING=OFF
        -DCMAKE_CXX_STANDARD=20
        ${FEATURE_OPTIONS}
)