From a25eb35712ef0b6dba48740a277a4212a50a8486 Mon Sep 17 00:00:00 2001 From: John Shumway Date: Mon, 25 Aug 2025 18:56:58 -0700 Subject: [PATCH] Add a CMake property for c++ standard (17 or 20) (#2736) Configure C++ standard with a CMake variable. Defaults to C++20, but can be set to C++17 to test backwards compatibility. * Add validation for allowed C++ standards. * build CK in rehl8 docker with std=c++17 --------- Co-authored-by: illsilin_amdeng [ROCm/composable_kernel commit: 99d27aca17f19f4cfed938c055917c4d27d2507e] --- CMakeLists.txt | 11 ++++++++++- Jenkinsfile | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39eb815680..52bb2ccd2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,15 @@ else() "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel.") endif() +# Allow user to specify the C++ standard. +# We must support C++17 builds until downstream users are migrated to C++20, but we default to C++20. +set(CK_CXX_STANDARD "20" CACHE STRING "C++ standard to use (e.g. 17 or 20)") +set(valid_cxx_standards 17 20) +set_property(CACHE CK_CXX_STANDARD PROPERTY STRINGS ${valid_cxx_standards}) +if(NOT CK_CXX_STANDARD IN_LIST valid_cxx_standards) + message(FATAL_ERROR "CK_CXX_STANDARD must be one of ${valid_cxx_standards}") +endif() + # Default installation path if(NOT WIN32) set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "") @@ -345,7 +354,7 @@ find_package(Threads REQUIRED) link_libraries(Threads::Threads) ## C++ -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD ${CK_CXX_STANDARD}) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}") diff --git a/Jenkinsfile b/Jenkinsfile index 8f5c724776..d590c01ba7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1358,6 +1358,7 @@ pipeline { def docker_name = "${env.CK_DOCKERHUB_PRIVATE}:ck_rhel8_rocm6.3" setup_args = """ -DGPU_TARGETS="gfx942" \ -DCMAKE_CXX_FLAGS=" -O3 " \ + -DCK_CXX_STANDARD="17" \ -DCK_USE_ALTERNATIVE_PYTHON=/opt/Python-3.8.13/bin/python3.8 """ execute_args = " " }