CMAKE_CXX_STANDARD: cmake 3.16 vs 3.24

I am observing a change in behavior in between cmake 3.16.3 and 3.24.2.

Basically the following is working as expected in cmake 3.16.3 :

cmake_minimum_required(VERSION 3.10)
project(p)
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
check_cxx_source_compiles("${my_code}" MY_VAR)

However in cmake 3.24.1, the try_compile fails because -std=c++98 is being added after my -std=c++11. Is there a way to preseve the behavior from 3.16 ?

@tambre might have some idea what’s going on with this one.

Please provide the resulting zipped build directory of a clean build with --debug-trycompile --trace --trace-expand --trace-redirect=trace.txt.

However in cmake 3.24.1, the try_compile fails because -std=c++98 is being added after my -std=c++11.

I presume this is with CMP0128 set to NEW? If there’s a change with it still being OLD then that’s a bug.

Here you go:

bad.tgz (131.3 KB)
good.tgz (116.7 KB)

Full code is:

cmake_minimum_required(VERSION 3.10)
if(POLICY CMP0128)
  cmake_policy(SET CMP0128 OLD)
endif()
project(p VERSION 1.0.0)
set(CMAKE_CXX_EXTENSIONS OFF) # important
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
find_package(Atomics REQUIRED)

Use case:

Highway is not compiled with any particular CMAKE_CXX_STANDARD set.

@tambre do you need any additional details ? thanks

Sorry, I’m simply very busy. Should hopefully have the time for a closer look over the weekend.

Would you be able to build CMake from source and bisect 3.16.3 and 3.24.2 for this issue?
I’ve combed through the CMP0128 implementation once again and I suspect this is more likely to have resulted from an earlier refactor.

Ok, then I’ll try to find some time then. I did report an issue to track progress, and communicate with upstream. Thanks