ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.05k stars 437 forks source link

CMAKE_CXX_STANDARD 20 and RANGES_CXX_STD 17 - does not work #1807

Closed suhasghorp closed 5 months ago

suhasghorp commented 5 months ago

I am using FetchContent to download range-v3 in Visual Studio 2022 CMake project. I set CMAKE_CXX_STANDARD to 20 as follows. I am getting an error :

CMake Error at out/build/x64-debug/_deps/range-v3-src/cmake/ranges_flags.cmake:57 (message):
  [range-v3]: Cannot specify both CMAKE_CXX_STANDARD and RANGES_CXX_STD, or
  they must match.

I can debug cmake script in VS and I can see that ranges is using C++17 standard. Do I need to specify RANGES_CXX_STD to 20 ?

Thanks

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)

include(FetchContent)  
  FetchContent_Declare(
  range-v3
  GIT_REPOSITORY git@github.com:ericniebler/range-v3.git
  GIT_TAG "0.12.0" # https://github.com/ericniebler/range-v3/releases
  GIT_SHALLOW TRUE
  GIT_PROGRESS ON
  SYSTEM
)
FetchContent_MakeAvailable(range-v3)
suhasghorp commented 5 months ago

Answering my own question here if anyone comes across this issue. Set the RANGES_CXX_STD before FecthContent and then include_directories as follows:

set(RANGES_CXX_STD 20)
include(FetchContent)  
  FetchContent_Declare(
  range-v3
  GIT_REPOSITORY git@github.com:ericniebler/range-v3.git
  GIT_TAG "0.12.0" # https://github.com/ericniebler/range-v3/releases
  GIT_SHALLOW TRUE
  GIT_PROGRESS ON
  SYSTEM
)
FetchContent_MakeAvailable(range-v3)
include_directories(range-v3 INTERFACE "${range-v3_SOURCE_DIR}/include")