diff --git a/modules/CheckCXXFeatures.cmake b/modules/CheckCXXFeatures.cmake index 0f58c2f..00b8eb7 100644 --- a/modules/CheckCXXFeatures.cmake +++ b/modules/CheckCXXFeatures.cmake @@ -76,10 +76,10 @@ macro(vgkit_check_libcxx_linker_mismatch) #include #include int main() { std::unordered_map m; m[\"k\"]=1; return 0; } -" VGKIT_LIBCXX_LINKS) +" VGKIT_LIBCXX_LINKS_${PROJECT_NAME}) cmake_pop_check_state() - if (NOT VGKIT_LIBCXX_LINKS) + if (NOT VGKIT_LIBCXX_LINKS_${PROJECT_NAME}) # Derive libc++ lib dir: -print-resource-dir gives /lib/clang/ execute_process( COMMAND ${CMAKE_CXX_COMPILER} -print-resource-dir @@ -97,10 +97,10 @@ int main() { std::unordered_map m; m[\"k\"]=1; return 0; } #include #include int main() { std::unordered_map m; m[\"k\"]=1; return 0; } -" VGKIT_LIBCXX_LINKS_WITH_FLAGS) +" VGKIT_LIBCXX_LINKS_WITH_FLAGS_${PROJECT_NAME}) cmake_pop_check_state() - if (VGKIT_LIBCXX_LINKS_WITH_FLAGS) + if (VGKIT_LIBCXX_LINKS_WITH_FLAGS_${PROJECT_NAME}) if (_clmm_modify_global) message(STATUS "libc++ linker mismatch detected; adding -L${_clang_libcxx_dir} to global linker flags") string(APPEND CMAKE_EXE_LINKER_FLAGS @@ -137,4 +137,56 @@ int main() { std::unordered_map m; m[\"k\"]=1; return 0; } unset(_clmm_modify_global) -endmacro(vgkit_check_libcxx_linker_mismatch) \ No newline at end of file +endmacro(vgkit_check_libcxx_linker_mismatch) + +# P0522R0 (relaxed matching of template template arguments) is required by +# code that passes class templates with defaulted parameters (e.g. +# small_vector) to template template parameters expecting fewer +# args (e.g. template class Container). +# +# - GCC has supported this since GCC 7 (default in all C++17 modes) +# - LLVM Clang enabled it by default in Clang 19; earlier versions need +# -frelaxed-template-template-args +# - AppleClang 17+ works; AppleClang 16 and earlier do not support it at all +# +# This macro tests whether P0522R0 works out of the box and, if not, tries +# adding -frelaxed-template-template-args. +# +# Sets VGKIT_P0522R0_COMPILE_FLAG in the caller's scope to the compile +# option needed (empty string if P0522R0 works natively). The caller +# decides how to apply it (e.g. target_compile_options on specific targets). +# On failure, emits FATAL_ERROR. +macro(vgkit_check_p0522r0) + + set(VGKIT_P0522R0_COMPILE_FLAG) + + cmake_push_check_state(RESET) + check_cxx_source_compiles(" +template struct SmallVec {}; +template