Skip to content

Commit 5ce2c6d

Browse files
committed
build: avoid custom handling for C++ standard
Use the builtin CMake support for specifying the proper flags for the targets to build at a certain C++ standard. This avoids unnecessary checks in CMake, speeding up the configure phase as well as simplifies the logic overall.
1 parent f722071 commit 5ce2c6d

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

libcxx/CMakeLists.txt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -518,21 +518,18 @@ remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
518518

519519
# Required flags ==============================================================
520520
function(cxx_add_basic_build_flags target)
521-
if (LIBCXX_HAS_MUSL_LIBC OR LIBCXX_TARGETING_CLANG_CL)
522-
# musl's pthread implementations uses volatile types in their structs which is
523-
# not a constexpr in C++11 but is in C++14, so we use C++14 with musl.
524-
set(LIBCXX_STANDARD_VER c++14 CACHE STRING "internal option to change build dialect")
521+
if(LIBCXX_HAS_MUSL_LIBC OR LIBCXX_TARGETING_CLANG_CL)
522+
# musl's pthread implementations uses volatile types in their structs which
523+
# is not a constexpr in C++11 but is in C++14, so we use C++14 with musl.
524+
set_target_properties(${target} PROPERTIES
525+
CXX_STANDARD 14
526+
CXX_STANDARD_REQUIRED YES
527+
CXX_EXTENSIONS NO)
525528
else()
526-
set(LIBCXX_STANDARD_VER c++11 CACHE STRING "internal option to change build dialect")
527-
endif()
528-
target_add_compile_flags_if_supported(${target} PRIVATE -std=${LIBCXX_STANDARD_VER})
529-
target_add_compile_flags_if_supported(${target} PRIVATE "/std:${LIBCXX_STANDARD_VER}")
530-
mangle_name("LIBCXX_SUPPORTS_STD_EQ_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME)
531-
mangle_name("LIBCXX_SUPPORTS_STD_COLON_${LIBCXX_STANDARD_VER}_FLAG" SUPPORTS_DIALECT_NAME_MSVC)
532-
if(NOT ${SUPPORTS_DIALECT_NAME} AND NOT ${SUPPORTS_DIALECT_NAME_MSVC})
533-
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
534-
message(FATAL_ERROR "C++11 or greater is required but the compiler does not support ${LIBCXX_STANDARD_VER}")
535-
endif()
529+
set_target_properties(${target} PROPERTIES
530+
CXX_STANDARD 11
531+
CXX_STANDARD_REQUIRED YES
532+
CXX_EXTENSIONS NO)
536533
endif()
537534

538535
# On all systems the system c++ standard library headers need to be excluded.

0 commit comments

Comments
 (0)