Added missing include (Clang 12).

First attempt to enable MemorySanitizer builds on Linux with clang.

remove wx specific stuff


Append msan cmake opts to common cmake opts


Clean up


fix


cleanup 2


add expat es dependency for fontconfig


revert fPIC in fontconfig


fpic


fix boost


add pic for qhull


working compiler flag forwarding
This commit is contained in:
tamasmeszaros 2022-01-21 18:24:55 +01:00
parent 3e087adc18
commit 588b158555
19 changed files with 465 additions and 17 deletions

View File

@ -33,6 +33,9 @@ option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1)
option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1) option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1)
option(SLIC3R_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0) option(SLIC3R_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0)
option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0)
option(SLIC3R_MSAN "Enable MemorySanitizer on Clang for Linux" 0)
option(SLIC3R_MSAN_RECOVERY "Enable recovery from an error after an initialized value is found" 1) # It is enabled by default until all reports are investigated.
option(SLIC3R_MSAN_ORIGIN_TRACKING "Enable tracking origins of uninitialized values" 0) # It causes another slows down of program execution by a factor of 1.5x-2x.
# If SLIC3R_FHS is 1 -> SLIC3R_DESKTOP_INTEGRATION is always 0, othrewise variable. # If SLIC3R_FHS is 1 -> SLIC3R_DESKTOP_INTEGRATION is always 0, othrewise variable.
CMAKE_DEPENDENT_OPTION(SLIC3R_DESKTOP_INTEGRATION "Allow perfoming desktop integration during runtime" 1 "NOT SLIC3R_FHS" 0) CMAKE_DEPENDENT_OPTION(SLIC3R_DESKTOP_INTEGRATION "Allow perfoming desktop integration during runtime" 1 "NOT SLIC3R_FHS" 0)
@ -249,6 +252,44 @@ if (NOT MSVC AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMP
endif() endif()
if (SLIC3R_MSAN)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL Clang)
message(FATAL_ERROR "MemorySanitizer is available only in Clang.")
endif ()
if (SLIC3R_ASAN)
message(FATAL_ERROR "MemorySanitizer cannot be used at the same time as AddressSanitizer.")
endif ()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 12)
message(WARNING "MemorySanitizer builds are tested only with CLANG 12, other versions are untested but could be working.")
endif()
add_compile_options(-nostdinc++)
add_compile_options(-stdlib=libc++)
add_compile_options(-fsanitize=memory)
add_compile_options(-fno-omit-frame-pointer)
include_directories(${CMAKE_PREFIX_PATH}/include)
include_directories(${CMAKE_PREFIX_PATH}/include/c++/v1)
link_directories(${CMAKE_PREFIX_PATH}/lib)
# Some libraries aren't correctly found without -Wl,--disable-new-dtags. https://stackoverflow.com/a/47243544
set(_msan_linker_flags "-fsanitize=memory -stdlib=libc++ -L${CMAKE_PREFIX_PATH}/lib -Wl,--disable-new-dtags -Wl,--rpath='$ORIGIN/../lib'")
if (SLIC3R_MSAN_RECOVERY)
add_compile_options(-fsanitize-recover=memory)
set(_msan_linker_flags "${_msan_linker_flags} -fsanitize-recover=memory")
endif ()
if (SLIC3R_MSAN_ORIGIN_TRACKING)
add_compile_options(-fsanitize-memory-track-origins=2)
set(_msan_linker_flags "${_msan_linker_flags} -fsanitize-memory-track-origins=2")
endif ()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_msan_linker_flags}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_msan_linker_flags}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${_msan_linker_flags}")
endif ()
if (SLIC3R_ASAN) if (SLIC3R_ASAN)
# ASAN should be available on MSVC starting with Visual Studio 2019 16.9 # ASAN should be available on MSVC starting with Visual Studio 2019 16.9
# https://devblogs.microsoft.com/cppblog/address-sanitizer-for-msvc-now-generally-available/ # https://devblogs.microsoft.com/cppblog/address-sanitizer-for-msvc-now-generally-available/
@ -614,6 +655,14 @@ else ()
install(FILES src/platform/unix/PrusaSlicer.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/resources/applications) install(FILES src/platform/unix/PrusaSlicer.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/resources/applications)
install(FILES src/platform/unix/PrusaGcodeviewer.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/resources/applications) install(FILES src/platform/unix/PrusaGcodeviewer.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/resources/applications)
install(DIRECTORY "${SLIC3R_RESOURCES_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/resources") install(DIRECTORY "${SLIC3R_RESOURCES_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/resources")
if (SLIC3R_MSAN)
install(CODE "set(_MSAN_COPY_FROM \"${CMAKE_PREFIX_PATH}/../lib\")")
install(CODE "set(_MSAN_COPY_TO \"${CMAKE_INSTALL_PREFIX}/lib\")")
install(SCRIPT deps/MSan_Deps/Chromium_prebuilt_libraries/copy_chromium_prebuilt_libraries.cmake)
install(CODE "set(_MSAN_COPY_FROM \"${CMAKE_PREFIX_PATH}/lib\")")
install(SCRIPT deps/MSan_Deps/install_msan_shared_libraries.cmake)
endif ()
endif () endif ()
configure_file(${LIBDIR}/platform/unix/fhs.hpp.in ${LIBDIR_BIN}/platform/unix/fhs.hpp) configure_file(${LIBDIR}/platform/unix/fhs.hpp.in ${LIBDIR_BIN}/platform/unix/fhs.hpp)

View File

@ -11,8 +11,8 @@ endif()
set(_patch_command ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/common.jam ./tools/build/src/tools/common.jam) set(_patch_command ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/common.jam ./tools/build/src/tools/common.jam)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
configure_file(${CMAKE_CURRENT_LIST_DIR}/user-config.jam boost-user-config.jam)
set(_boost_toolset gcc) set(_boost_toolset gcc)
configure_file(${CMAKE_CURRENT_LIST_DIR}/user-config.jam boost-user-config.jam)
set(_patch_command ${_patch_command} && ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/boost-user-config.jam ./tools/build/src/tools/user-config.jam) set(_patch_command ${_patch_command} && ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/boost-user-config.jam ./tools/build/src/tools/user-config.jam)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html # https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
@ -38,7 +38,9 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (WIN32) if (WIN32)
set(_boost_toolset "clang-win") set(_boost_toolset "clang-win")
else() else()
set(_boost_toolset "clang") set(_boost_toolset clang)
configure_file(${CMAKE_CURRENT_LIST_DIR}/user-config.jam boost-user-config.jam)
set(_patch_command ${_patch_command} && ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/boost-user-config.jam ./tools/build/src/tools/user-config.jam)
endif() endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(_boost_toolset "intel") set(_boost_toolset "intel")
@ -72,7 +74,14 @@ file(TO_NATIVE_PATH ${DESTDIR}/usr/local/ _prefix)
set(_boost_flags "") set(_boost_flags "")
if (UNIX) if (UNIX)
set(_boost_flags "cflags=-fPIC;cxxflags=-fPIC") if (DEP_MSAN)
set(_boost_flags
"cflags=-fPIC ${MSAN_CMAKE_C_FLAGS};"
"cxxflags=-fPIC ${MSAN_CMAKE_CXX_FLAGS};"
"linkflags=-fPIC ${MSAN_CMAKE_LD_FLAGS}")
else()
set(_boost_flags "cflags=-fPIC;cxxflags=-fPIC")
endif()
elseif(APPLE) elseif(APPLE)
set(_boost_flags set(_boost_flags
"cflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};" "cflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"

View File

@ -1 +1 @@
using gcc : : @CMAKE_CXX_COMPILER@ ; using @_boost_toolset@ : : @CMAKE_CXX_COMPILER@ ;

65
deps/CMakeLists.txt vendored
View File

@ -40,6 +40,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
option(DEP_WX_GTK3 "Build wxWidgets against GTK3" OFF) option(DEP_WX_GTK3 "Build wxWidgets against GTK3" OFF)
endif() endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
option(DEP_MSAN "Enable MemorySanitizer on Clang for Linux" OFF)
option(DEP_MSAN_RECOVERY "Enable recovery from an error after an initialized value is found" ON) # It is enabled by default until all reports are investigated.
option(DEP_MSAN_ORIGIN_TRACKING "Enable tracking origins of uninitialized values" OFF) # It causes another slows down of program execution by a factor of 1.5x-2x.
endif()
# On developer machines, it can be enabled to speed up compilation and suppress warnings coming from IGL. # On developer machines, it can be enabled to speed up compilation and suppress warnings coming from IGL.
# FIXME: # FIXME:
# Enabling this option is not safe. IGL will compile itself with its own version of Eigen while # Enabling this option is not safe. IGL will compile itself with its own version of Eigen while
@ -82,6 +88,7 @@ function(prusaslicer_add_cmake_project projectname)
EXCLUDE_FROM_ALL ON EXCLUDE_FROM_ALL ON
INSTALL_DIR ${DESTDIR}/usr/local INSTALL_DIR ${DESTDIR}/usr/local
DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/${projectname} DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/${projectname}
DEPENDS ${RUNTIME_LIBS}
${_gen} ${_gen}
CMAKE_ARGS CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR}/usr/local -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR}/usr/local
@ -141,18 +148,66 @@ else()
include("deps-linux.cmake") include("deps-linux.cmake")
endif() endif()
if (DEP_MSAN)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL Clang)
message(FATAL_ERROR "MemorySanitizer is available only in Clang.")
endif ()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 12)
message(WARNING "MemorySanitizer builds are tested only with CLANG 12, other versions are untested but could be working.")
endif()
file(MAKE_DIRECTORY ${DESTDIR}/usr/lib)
include(MSan_Deps/Libcxx/Libcxx.cmake)
include(MSan_Deps/Chromium_prebuilt_libraries/Chromium.cmake)
include(MSan_Deps/LLVM/LLVM.cmake)
include(MSan_Deps/Mesa3D/Mesa3D.cmake)
include(MSan_Deps/fontconfig/fontconfig.cmake)
set(_msan_linker_flags "-fsanitize=memory")
if (DEP_MSAN_RECOVERY)
set(_msan_linker_flags "${_msan_linker_flags} -fsanitize-recover=memory")
endif ()
if (DEP_MSAN_ORIGIN_TRACKING)
set(_msan_linker_flags "${_msan_linker_flags} -fsanitize-memory-track-origins=2")
endif ()
set(_msan_common_flags "${_msan_linker_flags} -fno-omit-frame-pointer")
set(_msan_only_cxx_flags "-nostdinc++ -stdlib=libc++ -isystem ${DESTDIR}/usr/local/include -isystem ${DESTDIR}/usr/local/include/c++/v1")
set(_msan_only_ld_flags "-nostdinc++ -stdlib=libc++ -L${DESTDIR}/usr/local/lib -Wl,--rpath=${DESTDIR}/usr/local/lib")
# For dependencies that are configure using CFLAGS, CXXFLAGS and LDFLAGS instead of CMAKE_*_FLAGS.
set(MSAN_CMAKE_C_FLAGS "${_msan_common_flags}")
set(MSAN_CMAKE_CXX_FLAGS "${_msan_common_flags} ${_msan_only_cxx_flags}")
set(MSAN_CMAKE_LD_FLAGS "${_msan_common_flags} ${_msan_only_ld_flags}")
set(_msan_all_flags "${_msan_common_flags} ${_msan_only_cxx_flags} ${_msan_only_ld_flags}")
set(MSAN_CMAKE_ARGS ${_MSAN_CMAKE_ARGS} -DCMAKE_C_FLAGS:STRING=${MSAN_CMAKE_C_FLAGS} -DCMAKE_CXX_FLAGS:STRING=${_msan_all_flags})
set(DEP_CMAKE_OPTS ${DEP_CMAKE_OPTS} ${MSAN_CMAKE_ARGS})
set(LIBCXX_PKG dep_Libcxx)
set(FONTCONFIG_PKG dep_fontconfig)
set(RUNTIME_LIBS ${LIBCXX_PKG})
else ()
set(MSAN_CMAKE_ARGS "")
set(LIBCXX_PKG "")
set(FONTCONFIG_PKG "")
endif ()
set(ZLIB_PKG "") set(ZLIB_PKG "")
if (NOT ZLIB_FOUND) if (NOT ZLIB_FOUND OR DEP_MSAN)
include(ZLIB/ZLIB.cmake) include(ZLIB/ZLIB.cmake)
set(ZLIB_PKG dep_ZLIB) set(ZLIB_PKG dep_ZLIB)
endif () endif ()
set(PNG_PKG "") set(PNG_PKG "")
if (NOT PNG_FOUND) if (NOT PNG_FOUND OR DEP_MSAN)
include(PNG/PNG.cmake) include(PNG/PNG.cmake)
set(PNG_PKG dep_PNG) set(PNG_PKG dep_PNG)
endif () endif ()
set(EXPAT_PKG "") set(EXPAT_PKG "")
if (NOT EXPAT_FOUND) if (NOT EXPAT_FOUND OR DEP_MSAN)
include(EXPAT/EXPAT.cmake) include(EXPAT/EXPAT.cmake)
set(EXPAT_PKG dep_EXPAT) set(EXPAT_PKG dep_EXPAT)
endif () endif ()
@ -206,6 +261,10 @@ set(_dep_list
#list(APPEND _dep_list "dep_libigl") #list(APPEND _dep_list "dep_libigl")
# endif() # endif()
if (DEP_MSAN)
list(APPEND _dep_list "dep_LLVM;dep_Mesa3D;dep_fontconfig;dep_Chromium_Libs")
endif ()
add_custom_target(deps ALL DEPENDS ${_dep_list}) add_custom_target(deps ALL DEPENDS ${_dep_list})
# Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands # Note: I'm not using any of the LOG_xxx options in ExternalProject_Add() commands

10
deps/GMP/GMP.cmake vendored
View File

@ -17,9 +17,15 @@ if (MSVC)
add_custom_target(dep_GMP SOURCES ${_output}) add_custom_target(dep_GMP SOURCES ${_output})
else () else ()
set(_gmp_ccflags "-O2 -DNDEBUG -fPIC -DPIC -Wall -Wmissing-prototypes -Wpointer-arith -pedantic -fomit-frame-pointer -fno-common") set(_gmp_ccflags "-O2 -DNDEBUG -fPIC -DPIC -Wall -Wmissing-prototypes -Wpointer-arith -pedantic -fomit-frame-pointer -fno-common")
set(_gmp_cxxflags "${_gmp_ccflags}")
set(_gmp_build_tgt "${CMAKE_SYSTEM_PROCESSOR}") set(_gmp_build_tgt "${CMAKE_SYSTEM_PROCESSOR}")
if (DEP_MSAN)
set(_gmp_ccflags "${_gmp_ccflags} ${MSAN_CMAKE_C_FLAGS}")
set(_gmp_cxxflags "${_gmp_cxxflags} ${MSAN_CMAKE_CXX_FLAGS} ${MSAN_CMAKE_LD_FLAGS} ${MSAN_CMAKE_RPATH}")
endif ()
if (APPLE) if (APPLE)
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
set(_gmp_build_tgt aarch64) set(_gmp_build_tgt aarch64)
@ -47,7 +53,7 @@ else ()
URL_HASH SHA256=eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c URL_HASH SHA256=eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c
DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/GMP DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/GMP
BUILD_IN_SOURCE ON BUILD_IN_SOURCE ON
CONFIGURE_COMMAND env "CFLAGS=${_gmp_ccflags}" "CXXFLAGS=${_gmp_ccflags}" ./configure ${_cross_compile_arg} --enable-shared=no --enable-cxx=yes --enable-static=yes "--prefix=${DESTDIR}/usr/local" ${_gmp_build_tgt} CONFIGURE_COMMAND env "CFLAGS=${_gmp_ccflags}" "CXXFLAGS=${_gmp_cxxflags}" ./configure ${_cross_compile_arg} --enable-shared=no --enable-cxx=yes --enable-static=yes "--prefix=${DESTDIR}/usr/local" ${_gmp_build_tgt}
BUILD_COMMAND make -j BUILD_COMMAND make -j
INSTALL_COMMAND make install INSTALL_COMMAND make install
) )

View File

@ -30,7 +30,7 @@ else ()
URL_HASH SHA256=cf4f4b2d80abb79e820e78c8077b6725bbbb4e8f41896783c899087be0e94068 URL_HASH SHA256=cf4f4b2d80abb79e820e78c8077b6725bbbb4e8f41896783c899087be0e94068
DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/MPFR DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/MPFR
BUILD_IN_SOURCE ON BUILD_IN_SOURCE ON
CONFIGURE_COMMAND env "CFLAGS=${_gmp_ccflags}" "CXXFLAGS=${_gmp_ccflags}" ./configure ${_cross_compile_arg} --prefix=${DESTDIR}/usr/local --enable-shared=no --enable-static=yes --with-gmp=${DESTDIR}/usr/local ${_gmp_build_tgt} CONFIGURE_COMMAND env "CFLAGS=${_gmp_ccflags}" "CXXFLAGS=${_gmp_cxxflags}" ./configure ${_cross_compile_arg} --prefix=${DESTDIR}/usr/local --enable-shared=no --enable-static=yes --with-gmp=${DESTDIR}/usr/local ${_gmp_build_tgt}
BUILD_COMMAND make -j BUILD_COMMAND make -j
INSTALL_COMMAND make install INSTALL_COMMAND make install
DEPENDS dep_GMP DEPENDS dep_GMP

View File

@ -0,0 +1,17 @@
if (DEP_MSAN_ORIGIN_TRACKING)
set(chromium_url https://www.googleapis.com/download/storage/v1/b/chromium-browser-msan/o/linux-release%2Fmsan-chained-origins-linux-release-812431.zip?alt=media)
set(chromium_url_hash b99c3e50ab936e44f6e5b4e28b7f8bab0b01912bcb068af258f366fe1e18a6f6)
else ()
set(chromium_url https://www.googleapis.com/download/storage/v1/b/chromium-browser-msan/o/linux-release%2Fmsan-no-origins-linux-release-812433.zip?alt=media)
set(chromium_url_hash cfacfe4c2c3ee284015b74ada493cb992d4f7ac82e6325d27384d18437738c4c)
endif ()
ExternalProject_Add(dep_Chromium_Libs
URL ${chromium_url}
URL_HASH SHA256=${chromium_url_hash}
DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Chromium_Libs
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} "-D_MSAN_COPY_FROM=./instrumented_libraries_prebuilt/msan/lib" "-D_MSAN_COPY_TO=${DESTDIR}/usr/lib" -P ${CMAKE_CURRENT_LIST_DIR}/copy_chromium_prebuilt_libraries.cmake
)

View File

@ -0,0 +1,86 @@
function(copy_chromium_prebuilt_libraries path_from path_to)
if (NOT ${ARGC} EQUAL 2)
message(FATAL_ERROR "Invalid argument count.")
endif()
set(chromium_libs_list
libatk-1.0
libatk-bridge-2.0
libatspi
libcairo
libcairo-gobject
libcairo-script-interpreter
libdbus-1
libdbus-glib-1
libdbusmenu-glib
libdbusmenu-gtk
libdbusmenu-gtk3
libdbusmenu-jsonloader
libffi
libfreetype
libgdk-3
libgdk_pixbuf-2.0
libgdk_pixbuf_xlib-2.0
libgio-2.0
libglib-2.0
libgobject-2.0
libgtk-3
libharfbuzz
libharfbuzz-gobject
libharfbuzz-icu
libjasper
libpango-1.0
libpangocairo-1.0
libpangoft2-1.0
libpangoxft-1.0
libpixman-1
libpng12
libsecret-1
libudev
libX11
libX11-xcb
libXau
libxcb
libXcomposite
libXcursor
libXdamage
libXdmcp
libXext
libXfixes
libXinerama
libXi
libXrandr
libXrender
libXss
libXtst)
set(chromium_libs_dirs_list
cairo
dbus-1.0
glib-2.0
gtk-2.0
gtk-3.0
udev)
foreach(chromium_lib ${chromium_libs_list})
file(GLOB chromium_lib_files "${path_from}/${chromium_lib}*")
if (NOT chromium_lib_files)
message(FATAL_ERROR "Library \"${chromium_lib}\" was not found.")
endif()
foreach(chromium_lib_file ${chromium_lib_files})
file(COPY ${chromium_lib_file} DESTINATION ${path_to})
message("Copying file: ${chromium_lib_file}.")
endforeach()
endforeach()
foreach(chromium_lib_dir ${chromium_libs_dirs_list})
file(GLOB lib_directory "${path_from}/${chromium_lib_dir}")
if (NOT lib_directory)
message(FATAL_ERROR "Library directory \"${chromium_lib_dir}\" was not found.")
endif()
file(COPY ${lib_directory} DESTINATION ${path_to})
message("Copying directory: ${lib_directory}.")
endforeach()
endfunction()
copy_chromium_prebuilt_libraries(${_MSAN_COPY_FROM} ${_MSAN_COPY_TO})

54
deps/MSan_Deps/LLVM/LLVM.cmake vendored Normal file
View File

@ -0,0 +1,54 @@
set(projectname LLVM)
set(_llvm_cmake_c_flags "-fPIC")
set(_llvm_cmake_cxx_flags "-nostdinc++ -isystem ${DESTDIR}/usr/local/include -isystem ${DESTDIR}/usr/local/include/c++/v1 -fPIC")
set(_llvm_cmake_exe_linker_flags "-stdlib=libc++ -Wl,--rpath=${DESTDIR}/usr/local/lib -L${DESTDIR}/usr/local/lib -fsanitize=memory -fPIC")
set(_llvm_cmake_shared_linker_flags "-stdlib=libc++ -Wl,--rpath=${DESTDIR}/usr/local/lib -L${DESTDIR}/usr/local/lib -fsanitize=memory -fPIC")
set(_llvm_cmake_module_linker_flags "-stdlib=libc++ -Wl,--rpath=${DESTDIR}/usr/local/lib -L${DESTDIR}/usr/local/lib -fsanitize=memory -fPIC")
# TODO: Build LLVM statically and link with Mesa 3D.
ExternalProject_Add(dep_LLVM
URL https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/llvm-project-12.0.1.src.tar.xz
URL_HASH SHA256=129cb25cd13677aad951ce5c2deb0fe4afc1e9d98950f53b51bdcfb5a73afa0e
DEPENDS dep_Libcxx
EXCLUDE_FROM_ALL ON
INSTALL_DIR ${DESTDIR}/usr/local
DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/LLVM
LIST_SEPARATOR | # Use the alternate list separator because by default all ; are replaced by space
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR}/usr/local
-DCMAKE_MODULE_PATH:STRING=${PROJECT_SOURCE_DIR}/../cmake/modules
-DCMAKE_PREFIX_PATH:STRING=${DESTDIR}/usr/local
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
-DCMAKE_TOOLCHAIN_FILE:STRING=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_BUILD_TYPE=Release
-DLLVM_USE_SANITIZER=MemoryWithOrigins
# -DLLVM_ENABLE_PROJECTS=clang|lld|llvm-config
-DLLVM_ENABLE_PROJECTS=LLVM|llvm-config
-DLLVM_ENABLE_LIBCXX=ON
# This forces to make shared library.
-DLLVM_BUILD_LLVM_DYLIB=ON
-DLLVM_LINK_LLVM_DYLIB=ON
-DLLVM_DYLIB_COMPONENTS=all
# -DLLVM_TARGETS_TO_BUILD=X86
-DLLVM_ENABLE_PIC=ON
-DCMAKE_C_FLAGS:STRING=${_llvm_cmake_c_flags}
-DCMAKE_CXX_FLAGS:STRING=${_llvm_cmake_cxx_flags}
-DCMAKE_EXE_LINKER_FLAGS:STRING=${_llvm_cmake_exe_linker_flags}
-DCMAKE_SHARED_LINKER_FLAGS:STRING=${_llvm_cmake_shared_linker_flags}
-DCMAKE_MODULE_LINKER_FLAGS:STRING=${_llvm_cmake_module_linker_flags}
SOURCE_SUBDIR llvm
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release --target LLVM llvm-config -- ${_build_j}
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config Release --target install-LLVM install-llvm-config install-llvm-headers
COMMAND ln -sfn "../local/lib/libLLVM.so" "${DESTDIR}/usr/lib/libLLVM.so"
COMMAND ln -sfn "../local/lib/libLLVM-12.so" "${DESTDIR}/usr/lib/libLLVM-12.so"
COMMAND ln -sfn "../local/lib/libLLVM-12.0.1.so" "${DESTDIR}/usr/lib/libLLVM-12.0.1.so"
)

29
deps/MSan_Deps/Libcxx/Libcxx.cmake vendored Normal file
View File

@ -0,0 +1,29 @@
set(_build_j "-j${NPROC}")
set(_build_j "-j${NPROC}")
ExternalProject_Add(dep_Libcxx
URL https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/llvm-project-12.0.1.src.tar.xz
URL_HASH SHA256=129cb25cd13677aad951ce5c2deb0fe4afc1e9d98950f53b51bdcfb5a73afa0e
EXCLUDE_FROM_ALL ON
INSTALL_DIR ${DESTDIR}/usr/local
DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Libcxx
LIST_SEPARATOR | # Use the alternate list separator because by default all ; are replaced by space
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR}/usr/local
-DCMAKE_MODULE_PATH:STRING=${PROJECT_SOURCE_DIR}/../cmake/modules
-DCMAKE_PREFIX_PATH:STRING=${DESTDIR}/usr/local
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
-DCMAKE_TOOLCHAIN_FILE:STRING=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_BUILD_TYPE=Release
-DLLVM_ENABLE_PROJECTS=libcxx|libcxxabi
-DLLVM_USE_SANITIZER=MemoryWithOrigins
SOURCE_SUBDIR llvm
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release --target cxx cxxabi -- ${_build_j}
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config Release --target install-cxx install-cxxabi
COMMAND ln -sfn "../local/lib/libc++.so" "${DESTDIR}/usr/lib/libc++.so"
COMMAND ln -sfn "../local/lib/libc++.so.1" "${DESTDIR}/usr/lib/libc++.so.1"
COMMAND ln -sfn "../local/lib/libc++.so.1.0" "${DESTDIR}/usr/lib/libc++.so.1.0"
COMMAND ln -sfn "../local/lib/libc++abi.so" "${DESTDIR}/usr/lib/libc++abi.so"
COMMAND ln -sfn "../local/lib/libc++abi.so.1" "${DESTDIR}/usr/lib/libc++abi.so.1"
COMMAND ln -sfn "../local/lib/libc++abi.so.1.0" "${DESTDIR}/usr/lib/libc++abi.so.1.0"
)

19
deps/MSan_Deps/Mesa3D/Mesa3D.cmake vendored Normal file
View File

@ -0,0 +1,19 @@
set(_mesa3d_cflags "-fsanitize=memory -stdlib=libc++ -fsanitize-recover=memory -fsanitize-blacklist=${CMAKE_CURRENT_LIST_DIR}/ignorelist.txt -I${DESTDIR}/usr/local/include -I${DESTDIR}/usr/local/include/c++/v1")
set(_mesa3d_cxxflags "-fsanitize=memory -stdlib=libc++ -fsanitize-recover=memory -fsanitize-blacklist=${CMAKE_CURRENT_LIST_DIR}/ignorelist.txt -I${DESTDIR}/usr/local/include -I${DESTDIR}/usr/local/include/c++/v1")
set(_mesa3d_ldflags "-fsanitize=memory -stdlib=libc++ -fsanitize-recover=memory -fsanitize-blacklist=${CMAKE_CURRENT_LIST_DIR}/ignorelist.txt -L${DESTDIR}/usr/local/lib -Wl,-rpath,${DESTDIR}/usr/local/lib")
set(_mesa3d_path "${DESTDIR}/usr/local/bin:$ENV{PATH}")
# We need to override PATH variable to make Meson find our build llvm-config and not use system one.
ExternalProject_Add(dep_Mesa3D
URL https://archive.mesa3d.org/mesa-21.3.3.tar.xz
URL_HASH SHA256=ad7f4613ea7c5d08d9fcb5025270199e6ceb9aa99fd72ee572b70342240a8121
DEPENDS dep_Libcxx dep_LLVM dep_Chromium_Libs
DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/Mesa3D
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND env "PATH=${_mesa3d_path}" "CFLAGS=${_mesa3d_cflags}" "CXXFLAGS=${_mesa3d_cxxflags}" "LDFLAGS=${_mesa3d_ldflags}" meson build_mesa -Dglx=gallium-xlib -Dgallium-drivers=swrast -Dplatforms=x11 -Ddri3=disabled "-Ddri-drivers=" "-Dvulkan-drivers=" -Db_sanitize=memory -Db_lundef=false -Dgles1=disabled -Dgles2=disabled -Dshared-glapi=disabled "-Dprefix=${DESTDIR}/usr/local" "-Dlibdir=${DESTDIR}/usr/local/lib"
BUILD_COMMAND ninja -C build_mesa install
INSTALL_COMMAND ln -sfn "../local/lib/libGL.so" "${DESTDIR}/usr/lib/libGL.so"
COMMAND ln -sfn "../local/lib/libGL.so.1" "${DESTDIR}/usr/lib/libGL.so.1"
COMMAND ln -sfn "../local/lib/libGL.so.1.5.0" "${DESTDIR}/usr/lib/libGL.so.1.5.0"
)

55
deps/MSan_Deps/Mesa3D/ignorelist.txt vendored Normal file
View File

@ -0,0 +1,55 @@
fun:single_output_color
fun:flush_spans
fun:subtriangle
fun:sp_setup_tri
fun:sp_vbuf_draw_arrays
fun:draw_pt_emit_linear
fun:emit
fun:fetch_pipeline_generic
fun:fetch_pipeline_linear_run
fun:vsplit_run_linear
fun:draw_pt_arrays
fun:draw_instances
fun:draw_vbo
fun:softpipe_draw_vbo
fun:_mesa_draw_arrays
fun:_mesa_DrawArrays
fun:setup_sort_vertices
fun:setup_tri_edges
fun:sp_setup_tri
fun:sp_vbuf_draw_arrays
fun:util_set_thread_affinity
fun:clamp_colors
fun:exec_run
fun:shade_quad
fun:shade_quads
fun:depth_test_quads_fallback
fun:blend_single_add_src_alpha_inv_src_alpha
fun:tgsi_exec_machine_setup_masks
fun:tgsi_exec_machine_run
fun:depth_test_quad
fun:util_format_r8g8b8a8_unorm_unpack_rgba_float
fun:sp_get_cached_tile_tex
fun:get_texel_2d
fun:sp_find_cached_tile_tex
fun:sp_get_cached_tile_tex
fun:compute_lambda_lod
fun:util_fast_log2
fun:img_filter_2d_linear
fun:sp_get_cache
fun:util_copy_rect
fun:util_format_unpack_rgba_rect
fun:u_clip_tile
fun:img_filter_2d_linear_repeat_POT
fun:micro_div
fun:img_filter_2d_ewa
fun:convert_quad_depth
fun:calc_fixed_position
fun:try_setup_line
fun:setup_fragcoord_coef
fun:clip_tri
fun:do_clip_tri
fun:emit_vertex
fun:cull_tri
fun:clip_line
fun:do_clip_line

View File

@ -0,0 +1,16 @@
set(_fontconfig_cflags "-fsanitize=memory -stdlib=libc++ -fsanitize-recover=memory -I${DESTDIR}/usr/local/include -I${DESTDIR}/usr/local/include/c++/v1")
set(_fontconfig_cxxflags "-fsanitize=memory -stdlib=libc++ -fsanitize-recover=memory -I${DESTDIR}/usr/local/include -I${DESTDIR}/usr/local/include/c++/v1")
set(_fontconfig_ldflags "-fsanitize=memory -stdlib=libc++ -fsanitize-recover=memory -L${DESTDIR}/usr/local/lib -Wl,-rpath,${DESTDIR}/usr/local/lib")
ExternalProject_Add(dep_fontconfig
URL https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.13.1.tar.gz
URL_HASH SHA256=9f0d852b39d75fc655f9f53850eb32555394f36104a044bb2b2fc9e66dbbfa7f
DEPENDS dep_Libcxx ${EXPAT_PKG}
DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/fontconfig
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND env "CFLAGS=${_fontconfig_cflags}" "CXXFLAGS=${_fontconfig_cxxflags}" "LDFLAGS=${_fontconfig_ldflags}" ./configure --disable-docs --disable-static "--sysconfdir=/etc" "--localstatedir=/var" "--prefix=${DESTDIR}/usr/local"
INSTALL_COMMAND make install-exec && cd fontconfig && make install-fontconfigincludeHEADERS
COMMAND ln -sfn "../local/lib/libfontconfig.so" "${DESTDIR}/usr/lib/libfontconfig.so"
COMMAND ln -sfn "../local/lib/libfontconfig.so.1" "${DESTDIR}/usr/lib/libfontconfig.so.1"
COMMAND ln -sfn "../local/lib/libfontconfig.so.1.12.0" "${DESTDIR}/usr/lib/libfontconfig.so.1.12.0"
)

View File

@ -0,0 +1,34 @@
function(install_msan_shared_libraries path_from path_to)
if (NOT ${ARGC} EQUAL 2)
message(FATAL_ERROR "Invalid argument count.")
endif()
set(msan_libs_list
libc++
libc++abi
libfontconfig
libGL
libLLVM)
foreach(msan_lib ${msan_libs_list})
file(GLOB msan_lib_files "${path_from}/${msan_lib}*")
if (NOT msan_lib_files)
message(FATAL_ERROR "Library \"${msan_lib}\" was not found.")
endif()
foreach(msan_lib_file ${msan_lib_files})
file(COPY ${msan_lib_file} DESTINATION ${path_to})
message("Copying file: ${msan_lib_file}.")
endforeach()
endforeach()
foreach(msan_lib_dir ${msan_libs_dirs_list})
file(GLOB lib_directory "${path_from}/${msan_lib_dir}")
if (NOT lib_directory)
message(FATAL_ERROR "Library directory \"${msan_lib_dir}\" was not found.")
endif()
file(COPY ${lib_directory} DESTINATION ${path_to})
message("Copying directory: ${lib_directory}.")
endforeach()
endfunction()
install_msan_shared_libraries(${_MSAN_COPY_FROM} ${_MSAN_COPY_TO})

View File

@ -30,6 +30,8 @@ ExternalProject_Add(dep_OpenSSL
no-ssl3-method no-ssl3-method
no-dynamic-engine no-dynamic-engine
-Wa,--noexecstack -Wa,--noexecstack
"${MSAN_CMAKE_C_FLAGS}"
"${MSAN_CMAKE_LD_FLAGS}"
BUILD_COMMAND make depend && make "-j${NPROC}" BUILD_COMMAND make depend && make "-j${NPROC}"
INSTALL_COMMAND make install_sw INSTALL_COMMAND make install_sw
) )

6
deps/PNG/PNG.cmake vendored
View File

@ -10,6 +10,10 @@ if (APPLE)
set(_patch_step PATCH_COMMAND ${PATCH_CMD} ${CMAKE_CURRENT_LIST_DIR}/PNG.patch) set(_patch_step PATCH_COMMAND ${PATCH_CMD} ${CMAKE_CURRENT_LIST_DIR}/PNG.patch)
endif () endif ()
if (NOT DEP_MSAN)
set(_png_prefix -DPNG_PREFIX=prusaslicer_)
endif ()
prusaslicer_add_cmake_project(PNG prusaslicer_add_cmake_project(PNG
# GIT_REPOSITORY https://github.com/glennrp/libpng.git # GIT_REPOSITORY https://github.com/glennrp/libpng.git
# GIT_TAG v1.6.35 # GIT_TAG v1.6.35
@ -20,7 +24,7 @@ prusaslicer_add_cmake_project(PNG
CMAKE_ARGS CMAKE_ARGS
-DPNG_SHARED=OFF -DPNG_SHARED=OFF
-DPNG_STATIC=ON -DPNG_STATIC=ON
-DPNG_PREFIX=prusaslicer_ ${_png_prefix}
-DPNG_TESTS=OFF -DPNG_TESTS=OFF
-DDISABLE_DEPENDENCY_TRACKING=OFF -DDISABLE_DEPENDENCY_TRACKING=OFF
${_disable_neon_extension} ${_disable_neon_extension}

View File

@ -4,6 +4,7 @@ prusaslicer_add_cmake_project(Qhull
URL_HASH SHA256=5287f5edd6a0372588f5d6640799086a4033d89d19711023ef8229dd9301d69b URL_HASH SHA256=5287f5edd6a0372588f5d6640799086a4033d89d19711023ef8229dd9301d69b
CMAKE_ARGS CMAKE_ARGS
-DINCLUDE_INSTALL_DIR=${CMAKE_INSTALL_INCLUDEDIR} -DINCLUDE_INSTALL_DIR=${CMAKE_INSTALL_INCLUDEDIR}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
) )
if (MSVC) if (MSVC)

View File

@ -9,12 +9,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(_wx_toolkit "-DwxBUILD_TOOLKIT=gtk${_gtk_ver}") set(_wx_toolkit "-DwxBUILD_TOOLKIT=gtk${_gtk_ver}")
endif() endif()
set(_wx_config_command "")
prusaslicer_add_cmake_project(wxWidgets prusaslicer_add_cmake_project(wxWidgets
# GIT_REPOSITORY "https://github.com/prusa3d/wxWidgets" # GIT_REPOSITORY "https://github.com/prusa3d/wxWidgets"
# GIT_TAG tm_cross_compile #${_wx_git_tag} # GIT_TAG tm_cross_compile #${_wx_git_tag}
URL https://github.com/prusa3d/wxWidgets/archive/73f029adfcc82fb3aa4b01220a013f716e57d110.zip URL https://github.com/prusa3d/wxWidgets/archive/73f029adfcc82fb3aa4b01220a013f716e57d110.zip
URL_HASH SHA256=c35fe0187db497b6a3f477e24ed5e307028657ff0c2554385810b6e7961ad2e4 URL_HASH SHA256=c35fe0187db497b6a3f477e24ed5e307028657ff0c2554385810b6e7961ad2e4
DEPENDS ${PNG_PKG} ${ZLIB_PKG} ${EXPAT_PKG} dep_TIFF dep_JPEG DEPENDS ${FONTCONFIG_PKG} ${PNG_PKG} ${ZLIB_PKG} ${EXPAT_PKG} dep_TIFF dep_JPEG
CMAKE_ARGS CMAKE_ARGS
-DwxBUILD_PRECOMP=ON -DwxBUILD_PRECOMP=ON
${_wx_toolkit} ${_wx_toolkit}

View File

@ -260,9 +260,15 @@ else ()
set(BIN_RESOURCES_DIR "${CMAKE_CURRENT_BINARY_DIR}/../resources") set(BIN_RESOURCES_DIR "${CMAKE_CURRENT_BINARY_DIR}/../resources")
endif () endif ()
add_custom_command(TARGET PrusaSlicer POST_BUILD add_custom_command(TARGET PrusaSlicer POST_BUILD
COMMAND ln -sfn "${SLIC3R_RESOURCES_DIR}" "${BIN_RESOURCES_DIR}" COMMAND ln -sfn "${SLIC3R_RESOURCES_DIR}" "${BIN_RESOURCES_DIR}"
COMMENT "Symlinking the resources directory into the build tree" COMMENT "Symlinking the resources directory into the build tree"
VERBATIM) VERBATIM)
if (SLIC3R_MSAN)
add_custom_command(TARGET PrusaSlicer POST_BUILD
COMMAND ln -sfn "${CMAKE_PREFIX_PATH}/../lib" "${CMAKE_CURRENT_BINARY_DIR}/../lib"
COMMENT "Symlinking the instrument library directory into the build tree"
VERBATIM)
endif ()
endif () endif ()
# Slic3r binary install target # Slic3r binary install target