From 9a50c56bd36c3292060c66fa81995ab5f466ad47 Mon Sep 17 00:00:00 2001 From: bgottamd Date: Thu, 4 Apr 2024 16:43:59 -0700 Subject: [PATCH 1/9] clang-cl: pass unsupported clang-cl flags directly to the clang driver --- intern/cycles/CMakeLists.txt | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt index 896fa5b3e91..266458dc973 100644 --- a/intern/cycles/CMakeLists.txt +++ b/intern/cycles/CMakeLists.txt @@ -122,11 +122,23 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) check_cxx_compiler_flag(-mavx2 CXX_HAS_AVX2) # Assume no signal trapping for better code generation. - set(CYCLES_KERNEL_FLAGS "-fno-trapping-math") - # Avoid overhead of setting errno for NaNs. - string(APPEND CYCLES_KERNEL_FLAGS " -fno-math-errno") - # Let compiler optimize 0.0 - x without worrying about signed zeros. - string(APPEND CYCLES_KERNEL_FLAGS " -fno-signed-zeros") + # We need to omit or modify specific flags to pass through clang-cl to prevent + # unknown flag errors + if (WIN32 AND MSVC) + # Pass clang flags directly to clang otherwise. Clang-cl doesn't recognize + # these flags by default + set(CYCLES_KERNEL_FLAGS " /clang:-fno-trapping-math") + # Avoid overhead of setting errno for NaNs. + string(APPEND CYCLES_KERNEL_FLAGS " /clang:-fno-math-errno") + # Let compiler optimize 0.0 - x without worrying about signed zeros. + string(APPEND CYCLES_KERNEL_FLAGS " /clang:-fno-signed-zeros") + else () + set(CYCLES_KERNEL_FLAGS " -fno-trapping-math") + # Avoid overhead of setting errno for NaNs. + string(APPEND CYCLES_KERNEL_FLAGS " -fno-math-errno") + # Let compiler optimize 0.0 - x without worrying about signed zeros. + string(APPEND CYCLES_KERNEL_FLAGS " -fno-signed-zeros") + endif() if(CMAKE_COMPILER_IS_GNUCC) # Assume no signal trapping for better code generation. -- 2.30.2 From 79a3802ce179f6ccbfa7750d857e62c8f86ccb2c Mon Sep 17 00:00:00 2001 From: bgottamd Date: Thu, 4 Apr 2024 16:44:17 -0700 Subject: [PATCH 2/9] clang-cl: dont define unique address for clang-cl, attribute not recognized --- source/blender/blenlib/BLI_utildefines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index cfdc3b30e0a..71646cbc7e2 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -676,7 +676,7 @@ extern bool BLI_memory_is_zero(const void *arr, size_t arr_size); */ #define BLI_ENABLE_IF(condition) typename std::enable_if_t<(condition)> * = nullptr -#if defined(_MSC_VER) +#if defined(_MSC_VER) && !defined(__clang__) # define BLI_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] #elif defined(__has_cpp_attribute) # if __has_cpp_attribute(no_unique_address) -- 2.30.2 From a6b159c62bae6daa69d774878343bc0741a28234 Mon Sep 17 00:00:00 2001 From: bgottamd Date: Thu, 4 Apr 2024 16:44:10 -0700 Subject: [PATCH 3/9] clang-cl:added _LIBCPP_VERSION define to resolve tbb header errors --- source/blender/editors/sculpt_paint/CMakeLists.txt | 7 ++++++- source/blender/nodes/geometry/CMakeLists.txt | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt index cd270ed0f58..be52dd33954 100644 --- a/source/blender/editors/sculpt_paint/CMakeLists.txt +++ b/source/blender/editors/sculpt_paint/CMakeLists.txt @@ -133,7 +133,12 @@ if(WITH_GTESTS) blender_add_test_suite_lib(editor_sculpt_paint "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${TEST_LIB}") endif() -blender_add_lib(bf_editor_sculpt_paint "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") +# If compiling with msvc clang we need to add the D_LIBCPP_VERSION define +# so we don't run into tbb errors when compiling with lib +if(MSVC_CLANG) + string(APPEND CMAKE_CXX_FLAGS " /D_LIBCPP_VERSION") +endif() +blender_add_lib(bf_editor_sculpt_paint "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") # RNA_prototypes.h add_dependencies(bf_editor_sculpt_paint bf_rna) diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt index 8153efedf0c..7790abd6af3 100644 --- a/source/blender/nodes/geometry/CMakeLists.txt +++ b/source/blender/nodes/geometry/CMakeLists.txt @@ -288,6 +288,13 @@ list(APPEND LIB bf_nodes_geometry_generated ) +# If compiling with msvc clang we need to add the D_LIBCPP_VERSION define +# so we don't run into tbb errors when compiling with lib +if(MSVC_CLANG) + string(APPEND CMAKE_CXX_FLAGS " /D_LIBCPP_VERSION") +endif() + + blender_add_lib(bf_nodes_geometry "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") target_link_libraries(bf_nodes_geometry_generated bf_nodes_geometry) -- 2.30.2 From 95ac3e359f801760a991073d819b61263cd562c0 Mon Sep 17 00:00:00 2001 From: bgottamd Date: Thu, 4 Apr 2024 16:44:07 -0700 Subject: [PATCH 4/9] clang-cl: removed strippedpd --- source/creator/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 3d92439e5b7..80f15b57de4 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -1118,7 +1118,9 @@ elseif(WIN32) ) if(WITH_WINDOWS_RELEASE_PDB) - if(WITH_WINDOWS_RELEASE_STRIPPED_PDB) + # Skip install of stripped pdb if compiling with clang since there doesn't seem + # to be a pdbstripped version for clang-cl + if(WITH_WINDOWS_RELEASE_STRIPPED_PDB AND NOT(CMAKE_C_COMPILER_ID MATCHES "Clang")) # Icky hack for older CMAKE from https://stackoverflow.com/a/21198501 # `$` will work in newer CMAKE but the version currently (3.12) # on the build-bot does not support this endeavor. @@ -1851,7 +1853,8 @@ if(WIN32) PDB_NAME "blender_private" PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$" ) - if(WITH_WINDOWS_RELEASE_PDB AND WITH_WINDOWS_RELEASE_STRIPPED_PDB) + # If compiling with clang-cl we skip PDBSTRIPPED. There's doesn't seem to be a switch for it currently + if(WITH_WINDOWS_RELEASE_PDB AND WITH_WINDOWS_RELEASE_STRIPPED_PDB AND NOT(CMAKE_C_COMPILER_ID MATCHES "Clang")) # This is slightly messy, but single target generators like ninja will not have the # `CMAKE_CFG_INTDIR` variable and multi-target generators like `msbuild` will not have # `CMAKE_BUILD_TYPE`. This can be simplified by `target_link_options` and the `$` -- 2.30.2 From 1c3043c7419330c426e54be611ddb39aaf50c05d Mon Sep 17 00:00:00 2001 From: bgottamd Date: Wed, 10 Apr 2024 11:03:04 -0700 Subject: [PATCH 5/9] apply work around only when tbb version < 12 --- source/blender/blenlib/intern/task_pool.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/blenlib/intern/task_pool.cc b/source/blender/blenlib/intern/task_pool.cc index 24720dbb8c6..bba4a2cf96a 100644 --- a/source/blender/blenlib/intern/task_pool.cc +++ b/source/blender/blenlib/intern/task_pool.cc @@ -78,7 +78,10 @@ class Task { other.freedata = nullptr; } -#if defined(WITH_TBB) && TBB_INTERFACE_VERSION_MAJOR < 10 +// TBB has a check in tbb/include/task_group.h where __TBB_CPP11_RVALUE_REF_PRESENT should evaluate to true as with +// the other MSVC build. However, because of the clang compiler it does not and we attempt to call a deleted constructor +// in the tbb_task_pool_run function. This check fixes this issue and keeps our Task constructor valid +#if (defined(WITH_TBB) && TBB_INTERFACE_VERSION_MAJOR < 10) || (defined(_MSC_VER) && defined(__clang__) && TBB_INTERFACE_VERSION_MAJOR < 12) Task(const Task &other) : pool(other.pool), run(other.run), -- 2.30.2 From 08a182c99eb7a837b02dda1f07dc6a917add4560 Mon Sep 17 00:00:00 2001 From: bgottamd Date: Mon, 15 Apr 2024 21:10:35 -0700 Subject: [PATCH 6/9] clang-cl: now using msvc_clang to check compiler. Checking WITH_TBB for tbb fix --- source/blender/nodes/geometry/CMakeLists.txt | 2 +- source/creator/CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt index 7790abd6af3..d4cc5636a0e 100644 --- a/source/blender/nodes/geometry/CMakeLists.txt +++ b/source/blender/nodes/geometry/CMakeLists.txt @@ -290,7 +290,7 @@ list(APPEND LIB # If compiling with msvc clang we need to add the D_LIBCPP_VERSION define # so we don't run into tbb errors when compiling with lib -if(MSVC_CLANG) +if(WITH_TBB AND MSVC_CLANG) string(APPEND CMAKE_CXX_FLAGS " /D_LIBCPP_VERSION") endif() diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 80f15b57de4..6b554612f95 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -1120,7 +1120,7 @@ elseif(WIN32) if(WITH_WINDOWS_RELEASE_PDB) # Skip install of stripped pdb if compiling with clang since there doesn't seem # to be a pdbstripped version for clang-cl - if(WITH_WINDOWS_RELEASE_STRIPPED_PDB AND NOT(CMAKE_C_COMPILER_ID MATCHES "Clang")) + if(WITH_WINDOWS_RELEASE_STRIPPED_PDB AND NOT(MSVC_CLANG)) # Icky hack for older CMAKE from https://stackoverflow.com/a/21198501 # `$` will work in newer CMAKE but the version currently (3.12) # on the build-bot does not support this endeavor. @@ -1854,7 +1854,7 @@ if(WIN32) PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$" ) # If compiling with clang-cl we skip PDBSTRIPPED. There's doesn't seem to be a switch for it currently - if(WITH_WINDOWS_RELEASE_PDB AND WITH_WINDOWS_RELEASE_STRIPPED_PDB AND NOT(CMAKE_C_COMPILER_ID MATCHES "Clang")) + if(WITH_WINDOWS_RELEASE_PDB AND WITH_WINDOWS_RELEASE_STRIPPED_PDB AND NOT(MSVC_CLANG)) # This is slightly messy, but single target generators like ninja will not have the # `CMAKE_CFG_INTDIR` variable and multi-target generators like `msbuild` will not have # `CMAKE_BUILD_TYPE`. This can be simplified by `target_link_options` and the `$` -- 2.30.2 From 2149ae0657970f7b7fcb58c058db392ead1c2959 Mon Sep 17 00:00:00 2001 From: bgottamd Date: Wed, 17 Apr 2024 15:51:44 -0700 Subject: [PATCH 7/9] set clang cmake args in win32 to clangcl --- build_files/windows/configure_msbuild.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_files/windows/configure_msbuild.cmd b/build_files/windows/configure_msbuild.cmd index d4be40aff4f..6bf05d7448a 100644 --- a/build_files/windows/configure_msbuild.cmd +++ b/build_files/windows/configure_msbuild.cmd @@ -8,7 +8,7 @@ if "%BUILD_WITH_SCCACHE%"=="1" ( ) if "%WITH_CLANG%"=="1" ( - set CLANG_CMAKE_ARGS=-T"llvm" + set CLANG_CMAKE_ARGS=-T"ClangCl" ) if "%WITH_ASAN%"=="1" ( -- 2.30.2 From edd2f667b961e02d106bdc67822fc51cc0603a6c Mon Sep 17 00:00:00 2001 From: bgottamd Date: Mon, 22 Apr 2024 10:46:16 -0700 Subject: [PATCH 8/9] clang-cl: removed parentheses around not msvc_clang --- source/creator/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 6b554612f95..a660aaccf81 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -1120,7 +1120,7 @@ elseif(WIN32) if(WITH_WINDOWS_RELEASE_PDB) # Skip install of stripped pdb if compiling with clang since there doesn't seem # to be a pdbstripped version for clang-cl - if(WITH_WINDOWS_RELEASE_STRIPPED_PDB AND NOT(MSVC_CLANG)) + if(WITH_WINDOWS_RELEASE_STRIPPED_PDB AND NOT MSVC_CLANG) # Icky hack for older CMAKE from https://stackoverflow.com/a/21198501 # `$` will work in newer CMAKE but the version currently (3.12) # on the build-bot does not support this endeavor. @@ -1854,7 +1854,7 @@ if(WIN32) PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$" ) # If compiling with clang-cl we skip PDBSTRIPPED. There's doesn't seem to be a switch for it currently - if(WITH_WINDOWS_RELEASE_PDB AND WITH_WINDOWS_RELEASE_STRIPPED_PDB AND NOT(MSVC_CLANG)) + if(WITH_WINDOWS_RELEASE_PDB AND WITH_WINDOWS_RELEASE_STRIPPED_PDB AND NOT MSVC_CLANG) # This is slightly messy, but single target generators like ninja will not have the # `CMAKE_CFG_INTDIR` variable and multi-target generators like `msbuild` will not have # `CMAKE_BUILD_TYPE`. This can be simplified by `target_link_options` and the `$` -- 2.30.2 From 90b7958ae89650d1c8c97a39a0bbecbeb3308f24 Mon Sep 17 00:00:00 2001 From: bgottamd Date: Mon, 22 Apr 2024 11:22:44 -0700 Subject: [PATCH 9/9] clang-cl: added missing with_tbb for LIBCPP_VERSION define --- source/blender/editors/sculpt_paint/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt index be52dd33954..42ccc789469 100644 --- a/source/blender/editors/sculpt_paint/CMakeLists.txt +++ b/source/blender/editors/sculpt_paint/CMakeLists.txt @@ -135,7 +135,7 @@ endif() # If compiling with msvc clang we need to add the D_LIBCPP_VERSION define # so we don't run into tbb errors when compiling with lib -if(MSVC_CLANG) +if(WITH_TBB AND MSVC_CLANG) string(APPEND CMAKE_CXX_FLAGS " /D_LIBCPP_VERSION") endif() -- 2.30.2