diff --git a/build_release_vs.bat b/build_release_vs.bat index 78419dadf5..a52d940455 100644 --- a/build_release_vs.bat +++ b/build_release_vs.bat @@ -20,6 +20,18 @@ for %%a in (%*) do ( if "%%a"=="-x" set USE_NINJA=1 ) +@REM Check for clang-cl option (-l). Combined with -x it also builds the deps with +@REM clang-cl; on the Visual Studio generator it applies to the slicer only, because +@REM the dependency sub-builds have no toolset to inherit and stay on MSVC. +set CLANG_ARG= +set TOOLSET_ARG= +for %%a in (%*) do ( + if "%%a"=="-l" ( + set CLANG_ARG=-DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl + set TOOLSET_ARG=-T ClangCL + ) +) + @REM Check for unit-tests option ("tests") set BUILD_TESTS=OFF for %%a in (%*) do ( @@ -127,12 +139,13 @@ if "%1"=="slicer" ( GOTO :slicer ) echo "building deps.." +if defined CLANG_ARG if "%USE_NINJA%"=="0" echo Note: -l needs -x for the dependencies; building them with MSVC. echo on REM Set minimum CMake policy to avoid <3.5 errors set CMAKE_POLICY_VERSION_MINIMUM=3.5 if "%USE_NINJA%"=="1" ( - cmake ../ -G %CMAKE_GENERATOR% -DCMAKE_BUILD_TYPE=%build_type% + cmake ../ -G %CMAKE_GENERATOR% %CLANG_ARG% -DCMAKE_BUILD_TYPE=%build_type% cmake --build . --config %build_type% --target deps ) else ( cmake ../ -G %CMAKE_GENERATOR% -A %arch% -DCMAKE_BUILD_TYPE=%build_type% @@ -151,10 +164,10 @@ cd %build_dir% echo on set CMAKE_POLICY_VERSION_MINIMUM=3.5 if "%USE_NINJA%"=="1" ( - cmake .. -G %CMAKE_GENERATOR% -DORCA_TOOLS=ON %SIG_FLAG% -DBUILD_TESTS=%BUILD_TESTS% -DCMAKE_BUILD_TYPE=%build_type% + cmake .. -G %CMAKE_GENERATOR% %CLANG_ARG% -DORCA_TOOLS=ON %SIG_FLAG% -DBUILD_TESTS=%BUILD_TESTS% -DCMAKE_BUILD_TYPE=%build_type% cmake --build . --config %build_type% --target all ) else ( - cmake .. -G %CMAKE_GENERATOR% -A %arch% -DORCA_TOOLS=ON %SIG_FLAG% -DBUILD_TESTS=%BUILD_TESTS% -DCMAKE_BUILD_TYPE=%build_type% + cmake .. -G %CMAKE_GENERATOR% -A %arch% %TOOLSET_ARG% -DORCA_TOOLS=ON %SIG_FLAG% -DBUILD_TESTS=%BUILD_TESTS% -DCMAKE_BUILD_TYPE=%build_type% cmake --build . --config %build_type% --target ALL_BUILD -- -m ) @echo off diff --git a/deps/Assimp/Assimp.cmake b/deps/Assimp/Assimp.cmake index 8b4de03b09..9b973a55d5 100644 --- a/deps/Assimp/Assimp.cmake +++ b/deps/Assimp/Assimp.cmake @@ -21,6 +21,9 @@ orcaslicer_add_cmake_project(Assimp URL ${_assimp_url} URL_HASH ${_assimp_hash} CMAKE_ARGS + # Assimp's ccache support sets the global RULE_LAUNCH_COMPILE, which breaks + # the Ninja RC rule. The superbuild forwards CMAKE__COMPILER_LAUNCHER. + -DASSIMP_BUILD_USE_CCACHE=OFF -DASSIMP_BUILD_TESTS=OFF -DASSIMP_BUILD_SAMPLES=OFF -DASSIMP_BUILD_ASSIMP_TOOLS=OFF diff --git a/deps/Boost/Boost.cmake b/deps/Boost/Boost.cmake index bdd801857e..08b62b9fb8 100644 --- a/deps/Boost/Boost.cmake +++ b/deps/Boost/Boost.cmake @@ -24,6 +24,13 @@ if (MSVC AND DEP_DEBUG) set(_options "FORWARD_CONFIG") endif () +# Boost.Container's bundled dlmalloc passes int* where the Win32 Interlocked API +# takes volatile long*; cl compiles that with a warning, clang errors out. +set(_boost_c_flags_line "") +if (MSVC AND CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(_boost_c_flags_line "-DCMAKE_C_FLAGS:STRING=-Wno-incompatible-pointer-types") +endif () + orcaslicer_add_cmake_project(Boost ${_options} URL "https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.gz" @@ -38,6 +45,7 @@ orcaslicer_add_cmake_project(Boost "${_context_abi_line}" "${_context_arch_line}" "${_context_impl_line}" + "${_boost_c_flags_line}" ) -set(DEP_Boost_DEPENDS ZLIB) \ No newline at end of file +set(DEP_Boost_DEPENDS ZLIB) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 8f4bc2a215..c95cdf8d73 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -157,8 +157,16 @@ endif () function(orcaslicer_add_cmake_project projectname) cmake_parse_arguments(P_ARGS "FORWARD_CONFIG" "INSTALL_DIR;BUILD_COMMAND;INSTALL_COMMAND" "CMAKE_ARGS" ${ARGN}) + # MSVC is true for clang-cl as well, so the sub-build toolchain has to key on the + # generator. A non-Visual-Studio superbuild passes its own generator down, and with + # it the CMAKE_C_COMPILER / CMAKE_CXX_COMPILER forwarded below. + set(_dep_msvc_gen FALSE) + if (MSVC AND CMAKE_GENERATOR MATCHES "Visual Studio") + set(_dep_msvc_gen TRUE) + endif () + set(_configs_line -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}) - if (_is_multi OR MSVC) + if (_is_multi OR _dep_msvc_gen) if (P_ARGS_FORWARD_CONFIG) set(_configs_line -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}) elseif (ORCA_INCLUDE_DEBUG_INFO AND NOT DEP_DEBUG) @@ -174,7 +182,7 @@ function(orcaslicer_add_cmake_project projectname) set(_target_config "Release") endif() - if (MSVC) + if (_dep_msvc_gen) set(_gen CMAKE_GENERATOR "${DEP_MSVC_GEN}" CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}") else() set(_gen "") @@ -182,7 +190,7 @@ function(orcaslicer_add_cmake_project projectname) if ($ENV{CMAKE_BUILD_PARALLEL_LEVEL}) set(_build_j "") # assume environment will control --build parallel setting - elseif(MSVC) + elseif(_dep_msvc_gen) set(_build_j "/m") else() set(_build_j "-j${NPROC}") diff --git a/deps/CURL/CURL.cmake b/deps/CURL/CURL.cmake index a5ae1b9d00..3d649dfdea 100644 --- a/deps/CURL/CURL.cmake +++ b/deps/CURL/CURL.cmake @@ -56,6 +56,18 @@ else() set(_curl_static ON) endif() +# curl 7.75's configure probes and code rely on C laxness cl allows but clang +# errors on (implicit function declarations, int* vs u_long* in ioctlsocket), +# which flips probe results and misconfigures nonblock.c into the AmigaOS +# IoctlSocket branch. Relax both diagnostics so the probes behave like cl, and +# pin the camel-case probes off since they only "pass" by implicit declaration. +set(_curl_c_flags_line "") +set(_curl_probe_overrides "") +if (MSVC AND CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(_curl_c_flags_line "-DCMAKE_C_FLAGS:STRING=-Wno-implicit-function-declaration -Wno-incompatible-pointer-types") + set(_curl_probe_overrides -DHAVE_IOCTLSOCKET_CAMEL=0 -DHAVE_IOCTLSOCKET_CAMEL_FIONBIO=0) +endif () + orcaslicer_add_cmake_project(CURL # GIT_REPOSITORY https://github.com/curl/curl.git # GIT_TAG curl-7_75_0 @@ -69,6 +81,8 @@ orcaslicer_add_cmake_project(CURL -DBUILD_CURL_EXE:BOOL=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCURL_STATICLIB=${_curl_static} + "${_curl_c_flags_line}" + ${_curl_probe_overrides} ${_curl_platform_flags} ) diff --git a/deps/Eigen/Eigen.cmake b/deps/Eigen/Eigen.cmake index 599976debb..2a9cc7105c 100644 --- a/deps/Eigen/Eigen.cmake +++ b/deps/Eigen/Eigen.cmake @@ -7,5 +7,20 @@ orcaslicer_add_cmake_project(Eigen URL https://gitlab.com/libeigen/eigen/-/archive/5.0.1/eigen-5.0.1.zip URL_HASH SHA256=0dbb1f9e3aaad66f352c03227d8c983f6f0b49e0b07e71a7300f4abcc01aee12 CMAKE_ARGS "${_eigen_extra_flags}" + # Only the headers are consumed here. Everything below builds nothing we + # use, and all three enable_language(Fortran): test/CMakeLists.txt:9, + # lapack/CMakeLists.txt:6 and blas/testing/CMakeLists.txt:2. They default + # to ON because the dependency configures as its own top-level project. + # + # Whether that probe is harmless depends on what CMake finds. The Visual + # Studio generator supports no Fortran, so it finds nothing; clang-cl sits + # next to the LLVM toolset's flang, which works. MSVC with Ninja finds + # Strawberry Perl's MinGW gfortran instead, which the deps build already + # requires for OpenSSL, and hands it the MSVC-style /machine:x64 that + # MinGW's ld reads as a missing input file. The configure dies there and + # takes the rest of the superbuild with it. + -DEIGEN_BUILD_TESTING=OFF + -DEIGEN_BUILD_BLAS=OFF + -DEIGEN_BUILD_LAPACK=OFF DEPENDS dep_Boost dep_GMP dep_MPFR ) diff --git a/deps/OCCT/0001-OCCT-fix.patch b/deps/OCCT/0001-OCCT-fix.patch index 27f5db7e0f..d251cc7ab6 100644 --- a/deps/OCCT/0001-OCCT-fix.patch +++ b/deps/OCCT/0001-OCCT-fix.patch @@ -1,3 +1,20 @@ +diff --git a/adm/cmake/occt_defs_flags.cmake b/adm/cmake/occt_defs_flags.cmake +index 00000000..00000001 100644 +--- a/adm/cmake/occt_defs_flags.cmake ++++ b/adm/cmake/occt_defs_flags.cmake +@@ -134,7 +134,11 @@ + set (CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}") + endif() + # Optimize size of binaries +- set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-s ${CMAKE_SHARED_LINKER_FLAGS}") ++ # clang-cl reports the Clang compiler ID, and OCCT builds shared on Windows, ++ # where the MSVC-style linker gets this flag as an argument it does not know. ++ if (NOT WIN32) ++ set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-s ${CMAKE_SHARED_LINKER_FLAGS}") ++ endif() + elseif(MINGW) + add_definitions(-D_WIN32_WINNT=0x0601) + # _WIN32_WINNT=0x0601 (use Windows 7 SDK) diff --git a/CMakeLists.txt b/CMakeLists.txt index d98acc0f..28eb8eb4 100644 --- a/CMakeLists.txt @@ -168,6 +185,32 @@ index d98acc0f..28eb8eb4 100644 endforeach() if (BUILD_SAMPLES_QT) +diff --git a/adm/cmake/occt_macros.cmake b/adm/cmake/occt_macros.cmake +index 224c96b1..8c94a1c5 100644 +--- a/adm/cmake/occt_macros.cmake ++++ b/adm/cmake/occt_macros.cmake +@@ -608,7 +608,7 @@ macro (OCCT_INSERT_CODE_FOR_TARGET) + install(CODE "if (\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$\") + set (OCCT_INSTALL_BIN_LETTER \"\") + elseif (\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Rr][Ee][Ll][Ww][Ii][Tt][Hh][Dd][Ee][Bb][Ii][Nn][Ff][Oo])$\") +- set (OCCT_INSTALL_BIN_LETTER \"i\") ++ set (OCCT_INSTALL_BIN_LETTER \"\") + elseif (\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Dd][Ee][Bb][Uu][Gg])$\") + set (OCCT_INSTALL_BIN_LETTER \"d\") + endif()") +diff --git a/adm/cmake/occt_toolkit.cmake b/adm/cmake/occt_toolkit.cmake +index 550e0e2f..7ac1a3b8 100644 +--- a/adm/cmake/occt_toolkit.cmake ++++ b/adm/cmake/occt_toolkit.cmake +@@ -241,7 +241,7 @@ + else() + set (aReleasePdbConf) + endif() +- install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb ++ install (FILES $ + CONFIGURATIONS Debug ${aReleasePdbConf} RelWithDebInfo + DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}") + endif() diff --git a/src/Font/Font_FTFont.cxx b/src/Font/Font_FTFont.cxx index 5ae9899f..0a17372b 100644 --- a/src/Font/Font_FTFont.cxx diff --git a/deps/OpenSSL/OpenSSL.cmake b/deps/OpenSSL/OpenSSL.cmake index e43997265b..ddeb680052 100644 --- a/deps/OpenSSL/OpenSSL.cmake +++ b/deps/OpenSSL/OpenSSL.cmake @@ -17,10 +17,20 @@ else() endif() if(WIN32) - set(_conf_cmd perl Configure ) + set(_openssl_msvc_env CC=cl CXX=cl RC=rc CL=/FS) + # OpenSSL's perl Configure honors the CC environment variable, but the + # VC-WIN64A makefile only works with cl (an unquoted clang-cl path with + # spaces, e.g. exported by CLion, silently produces no .obj files and the + # lib step fails with LNK1181). Pin the upstream toolchain. + # Keep rc.exe resolved from the MSVC developer environment as well. The + # absolute Windows SDK path contains spaces and OpenSSL 1.1.1 writes it to + # the generated nmake file without quoting, which skips .res generation. + # /FS serializes access to OpenSSL's shared generated PDB when cl is + # driven through nmake from a Ninja configure step. + set(_conf_cmd ${CMAKE_COMMAND} -E env ${_openssl_msvc_env} perl Configure ) set(_cross_comp_prefix_line "") - set(_make_cmd nmake) - set(_install_cmd nmake install_sw ) + set(_make_cmd ${CMAKE_COMMAND} -E env ${_openssl_msvc_env} nmake) + set(_install_cmd ${CMAKE_COMMAND} -E env ${_openssl_msvc_env} nmake install_sw ) else() if(APPLE) set(_conf_cmd export MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} && ./Configure -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}) diff --git a/deps/wxInspector/wxInspector.cmake b/deps/wxInspector/wxInspector.cmake index 97c3810809..4a5b28407f 100644 --- a/deps/wxInspector/wxInspector.cmake +++ b/deps/wxInspector/wxInspector.cmake @@ -1,3 +1,26 @@ +# wxInspector finds wxWidgets through CMake's FindwxWidgets module, which only +# searches lib/vc*_lib because _WX_TOOL is hardcoded to "vc". A superbuild driven +# by clang-cl installs wxWidgets into lib/clang_x64_lib, so hand the module the +# directory wxWidgets actually used, derived the same way wxWidgetsConfig.cmake +# derives it. +set(_wxinspector_wx_hints "") +if (MSVC) + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(_wx_compiler_prefix "clang") + else () + set(_wx_compiler_prefix "vc") + endif () + set(_wx_arch_suffix "") + if (CMAKE_GENERATOR_PLATFORM AND NOT CMAKE_GENERATOR_PLATFORM STREQUAL "Win32") + string(TOLOWER "_${CMAKE_GENERATOR_PLATFORM}" _wx_arch_suffix) + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + set(_wx_arch_suffix "_x64") + endif () + set(_wxinspector_wx_hints + "-DwxWidgets_ROOT_DIR=${DESTDIR}" + "-DwxWidgets_LIB_DIR=${DESTDIR}/lib/${_wx_compiler_prefix}${_wx_arch_suffix}_lib") +endif () + orcaslicer_add_cmake_project( wxInspector URL https://github.com/Noisyfox/wxInspector/archive/refs/tags/v1.0.0.zip @@ -6,6 +29,7 @@ orcaslicer_add_cmake_project( CMAKE_ARGS -DCMAKE_CXX_FLAGS="-DwxDEBUG_LEVEL=0" -DCMAKE_POSITION_INDEPENDENT_CODE=ON + ${_wxinspector_wx_hints} ) if (MSVC) diff --git a/deps/wxWidgets/0001-Clang-CL-fix.patch b/deps/wxWidgets/0001-Clang-CL-fix.patch deleted file mode 100644 index 23bf23b3f4..0000000000 --- a/deps/wxWidgets/0001-Clang-CL-fix.patch +++ /dev/null @@ -1,28 +0,0 @@ ---- - build/cmake/wxWidgetsConfig.cmake.in | 10 +++++++++- - 1 file changed, 10 insertions(+), 1 deletion(-) - -diff --git a/build/cmake/wxWidgetsConfig.cmake.in b/build/cmake/wxWidgetsConfig.cmake.in -index 1a83f36..70ad8a4 100644 ---- a/build/cmake/wxWidgetsConfig.cmake.in -+++ b/build/cmake/wxWidgetsConfig.cmake.in -@@ -58,7 +58,16 @@ if(WIN32_MSVC_NAMING) - endif() - endif() - --include("${CMAKE_CURRENT_LIST_DIR}${wxPLATFORM_LIB_DIR}/@PROJECT_NAME@Targets.cmake") -+if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") -+ if (CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64" OR CMAKE_VS_PLATFORM_NAME STREQUAL "ARM64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM64|arm64|aarch64)$") -+ set(_wx_clang_msvc_lib_dir "vc_arm64_lib") -+ else() -+ set(_wx_clang_msvc_lib_dir "vc_x64_lib") -+ endif() -+ include("${CMAKE_CURRENT_LIST_DIR}${wxPLATFORM_LIB_DIR}/${_wx_clang_msvc_lib_dir}/@PROJECT_NAME@Targets.cmake") -+else() -+ include("${CMAKE_CURRENT_LIST_DIR}${wxPLATFORM_LIB_DIR}/@PROJECT_NAME@Targets.cmake") -+endif() - - macro(wx_inherit_property source dest name) - # property name without _ --- -2.43.0 diff --git a/deps/wxWidgets/wxWidgets.cmake b/deps/wxWidgets/wxWidgets.cmake index 07bb31d8be..1e2cc85f78 100644 --- a/deps/wxWidgets/wxWidgets.cmake +++ b/deps/wxWidgets/wxWidgets.cmake @@ -28,7 +28,6 @@ orcaslicer_add_cmake_project( GIT_SHALLOW ON GIT_SUBMODULES 3rdparty/catch 3rdparty/pcre 3rdparty/libwebp DEPENDS ${PNG_PKG} ${ZLIB_PKG} ${EXPAT_PKG} ${JPEG_PKG} - PATCH_COMMAND git apply --verbose --ignore-space-change --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/0001-Clang-CL-fix.patch CMAKE_ARGS -DwxBUILD_PRECOMP=ON ${_wx_toolkit}