diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 413866a667b..02ceeea274a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,6 @@ { "name": "OrcaSlicer", "image": "mcr.microsoft.com/devcontainers/cpp:ubuntu-20.04", - "runArgs": ["--env-file", "/tmp/devcontainer.env"], "features": { "ghcr.io/devcontainers/features/desktop-lite:1": { "password": "orca" @@ -11,14 +10,7 @@ "vscode": { "settings": { "cmake.configureArgs": [ - "-DSLIC3R_GTK=3", - "-DBBL_RELEASE_TO_PUBLIC=1", - "-DBBL_INTERNAL_TESTING=0", - "-DSLIC3R_STATIC=1", - "-DCMAKE_PREFIX_PATH=${workspaceFolder}/deps/build/destdir/usr/local" - ], - "cmake.buildToolArgs": [ - "-l${containerEnv:CORES}" + "-DBUILD_DEPS=ON" ] }, @@ -41,9 +33,6 @@ "onAutoForward": "ignore" }, - "initializeCommand": { - "Setup Temporary Env File": "echo \"CORES=`nproc --all`\" > /tmp/devcontainer.env" - }, "onCreateCommand": { "Set postCreate executable flag": "chmod +x .devcontainer/postCreate.sh" }, diff --git a/.github/workflows/build_check_cache.yml b/.github/workflows/build_check_cache.yml index f71cc9b2817..6ee0816cf44 100644 --- a/.github/workflows/build_check_cache.yml +++ b/.github/workflows/build_check_cache.yml @@ -32,11 +32,10 @@ jobs: env: underscore-arch: ${{ inputs.os == 'macos-14' && '_' || ''}}${{ inputs.os == 'macos-14' && inputs.arch || '' }} # if is macos, make a string that does "_{arch}", else output nothing dash-arch: ${{ inputs.os == 'macos-14' && '-' || ''}}${{ inputs.os == 'macos-14' && inputs.arch || '' }} # if is macos, make a string that does "-{arch}", else output nothing - dep-folder-name: ${{ (inputs.os == 'windows-latest' || inputs.os == 'macos-14') && 'OrcaSlicer_dep' || 'destdir' }} output-cmd: ${{ inputs.os == 'windows-latest' && '$env:GITHUB_OUTPUT' || '"$GITHUB_OUTPUT"'}} run: | echo cache-key=${{ inputs.os }}${{ env.dash-arch }}-cache-orcaslicer_deps-build-${{ hashFiles('deps/**') }} >> ${{ env.output-cmd }} - echo cache-path=${{ github.workspace }}/deps/build${{ env.underscore-arch }}/${{ env.dep-folder-name }}${{ env.underscore-arch }} >> ${{ env.output-cmd }} + echo cache-path=${{ github.workspace }}/deps/build${{ env.underscore-arch }}/OrcaSlicer_dep${{ env.underscore-arch }} >> ${{ env.output-cmd }} - name: load cache id: cache_deps diff --git a/.github/workflows/build_deps.yml b/.github/workflows/build_deps.yml index 6c0dc9479c5..aab63c8268c 100644 --- a/.github/workflows/build_deps.yml +++ b/.github/workflows/build_deps.yml @@ -66,11 +66,8 @@ jobs: working-directory: ${{ github.workspace }} run: | choco install strawberryperl - mkdir ${{ github.workspace }}/deps/build - mkdir ${{ github.workspace }}/deps/build/OrcaSlicer_dep .\build_release_vs2022.bat deps .\build_release_vs2022.bat pack - cd ${{ github.workspace }}/deps/build - name: Build on Mac ${{ inputs.arch }} if: inputs.os == 'macos-14' @@ -78,8 +75,6 @@ jobs: run: | brew install automake texinfo ninja libtool brew list - mkdir -p ${{ github.workspace }}/deps/build_${{ inputs.arch }} - mkdir -p ${{ github.workspace }}/deps/build_${{ inputs.arch }}/OrcaSlicer_dep_${{ inputs.arch }} brew uninstall --ignore-dependencies zstd ./build_release_macos.sh -dpx -a ${{ inputs.arch }} -t 10.15 -1 brew install zstd @@ -103,14 +98,9 @@ jobs: if: inputs.os == 'ubuntu-20.04' || inputs.os == 'ubuntu-24.04' working-directory: ${{ github.workspace }} run: | - mkdir -p ${{ github.workspace }}/deps/build - mkdir -p ${{ github.workspace }}/deps/build/destdir sudo ./BuildLinux.sh -ur sudo chown $USER -R ./ - ./BuildLinux.sh -dr - cd deps/build - tar -czvf OrcaSlicer_dep_ubuntu_$(date +"%Y%m%d").tar.gz destdir - + ./BuildLinux.sh -drp # Upload Artifacts - name: Upload Mac ${{ inputs.arch }} artifacts diff --git a/.github/workflows/build_orca.yml b/.github/workflows/build_orca.yml index ae855633d76..73f54b74728 100644 --- a/.github/workflows/build_orca.yml +++ b/.github/workflows/build_orca.yml @@ -83,8 +83,6 @@ jobs: run: | brew install tree ninja libtool brew list - mkdir -p ${{ github.workspace }}/deps/build_${{inputs.arch}} - mkdir -p ${{ github.workspace }}/deps/build_${{inputs.arch}}/OrcaSlicer_dep_${{inputs.arch}} tree ${{ github.workspace }}/deps/build_${{inputs.arch}}/OrcaSlicer_dep_${{inputs.arch}} - name: Build slicer mac diff --git a/.gitignore b/.gitignore index 3f66a360fde..2f1f6cdd500 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ Build Build.bat /build*/ -deps/build* +/deps/build*/ MYMETA.json MYMETA.yml _build @@ -13,15 +13,12 @@ MANIFEST.bak xs/MANIFEST.bak xs/assertlib* .init_bundle.ini -.vs/* +.vs/ local-lib /src/TAGS /.vscode/ -build-linux/* -deps/build*/* **/.DS_Store install_* -build_*/ SVG src/OrcaSlicer-doc/ .idea/ @@ -30,8 +27,7 @@ src/OrcaSlicer-doc/ **/process_full/ **/machine_full/ **/filament_full/ -/deps/DL_CACHE/ -/deps/DL_CACHE +DL_CACHE **/.flatpak-builder/ resources/profiles/user/default *.code-workspace diff --git a/BuildLinux.sh b/BuildLinux.sh index 28d84fb0462..44490878657 100755 --- a/BuildLinux.sh +++ b/BuildLinux.sh @@ -27,11 +27,13 @@ function check_available_memory_and_disk() { function usage() { echo "Usage: ./BuildLinux.sh [-1][-b][-c][-d][-i][-r][-s][-u]" echo " -1: limit builds to 1 core (where possible)" - echo " -b: build in debug mode" + echo " -b: build in Debug mode" + echo " -B: build in RelWithDebInfo mode" echo " -c: force a clean build" echo " -d: build deps (optional)" echo " -h: this help output" echo " -i: Generate appimage (optional)" + echo " -p: Pack dependencies (optional)" echo " -r: skip ram and disk checks (low ram compiling)" echo " -s: build orca-slicer (optional)" echo " -u: update and build dependencies (optional and need sudo)" @@ -39,35 +41,48 @@ function usage() { echo " and then './BuildLinux.sh -dsi'" } +BUILD_DIR="build" +BUILD_TYPE="Release" unset name -while getopts ":1bcdghirsu" opt; do +while getopts ":1bBcdhiprsu" opt; do case ${opt} in 1 ) export CMAKE_BUILD_PARALLEL_LEVEL=1 ;; b ) - BUILD_DEBUG="1" + BUILD_DIR="build-debug" + BUILD_TYPE="Debug" + ;; + B ) + BUILD_DIR="build-debinfo" + BUILD_TYPE="RelWithDebInfo" ;; c ) - CLEAN_BUILD=1 + CLEAN_BUILD="1" ;; d ) BUILD_DEPS="1" ;; - h ) usage + h ) + usage exit 0 ;; i ) BUILD_IMAGE="1" ;; + p ) + PACK_DEPS="1" + ;; r ) SKIP_RAM_CHECK="1" - ;; + ;; s ) BUILD_ORCA="1" ;; u ) - UPDATE_LIB="1" + export UPDATE_LIB="1" + ;; + * ) ;; esac done @@ -104,7 +119,6 @@ echo "Changing date in version..." # change date in version sed -i "s/+UNKNOWN/_$(date '+%F')/" version.inc } -echo "done" if ! [[ -n "${SKIP_RAM_CHECK}" ]] @@ -115,30 +129,14 @@ fi if [[ -n "${BUILD_DEPS}" ]] then echo "Configuring dependencies..." - BUILD_ARGS="-DDEP_WX_GTK3=ON" if [[ -n "${CLEAN_BUILD}" ]] then - rm -fr deps/build - fi - if [ ! -d "deps/build" ] - then - mkdir deps/build - fi - if [[ -n "${BUILD_DEBUG}" ]] - then - # have to build deps with debug & release or the cmake won't find everything it needs - if [ ! -d "deps/build/release" ] - then - mkdir deps/build/release - fi - cmake -S deps -B deps/build/release -G Ninja -DDESTDIR="${PWD}/deps/build/destdir" -DDEP_DOWNLOAD_DIR="${PWD}/deps/DL_CACHE" ${BUILD_ARGS} - cmake --build deps/build/release - BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug" + rm -fr deps/${BUILD_DIR} fi - echo "cmake -S deps -B deps/build -G Ninja ${BUILD_ARGS}" - cmake -S deps -B deps/build -G Ninja ${BUILD_ARGS} - cmake --build deps/build + echo "cmake -S deps -B deps/${BUILD_DIR} -G Ninja -DCMAKE_BUILD_TYPE=${BUILD_TYPE}" + cmake -S deps -B deps/${BUILD_DIR} -G Ninja -DCMAKE_BUILD_TYPE=${BUILD_TYPE} + cmake --build deps/${BUILD_DIR} fi @@ -147,46 +145,43 @@ then echo "Configuring OrcaSlicer..." if [[ -n "${CLEAN_BUILD}" ]] then - rm -fr build - fi - BUILD_ARGS="" - if [[ -n "${FOUND_GTK3_DEV}" ]] - then - BUILD_ARGS="-DSLIC3R_GTK=3" + rm -fr ${BUILD_DIR} fi - if [[ -n "${BUILD_DEBUG}" ]] - then - BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug -DBBL_INTERNAL_TESTING=1" - else - BUILD_ARGS="${BUILD_ARGS} -DBBL_RELEASE_TO_PUBLIC=1 -DBBL_INTERNAL_TESTING=0" - fi - echo -e "cmake -S . -B build -G Ninja -DCMAKE_PREFIX_PATH="${PWD}/deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}" - cmake -S . -B build -G Ninja \ - -DCMAKE_PREFIX_PATH="${PWD}/deps/build/destdir/usr/local" \ - -DSLIC3R_STATIC=1 \ - -DORCA_TOOLS=ON \ - ${BUILD_ARGS} - echo "done" + echo -e "cmake -S . -B ${BUILD_DIR} -G Ninja -DORCA_TOOLS=ON -DCMAKE_BUILD_TYPE=${BUILD_TYPE}" + cmake -S . -B ${BUILD_DIR} -G Ninja -DORCA_TOOLS=ON -DCMAKE_BUILD_TYPE=${BUILD_TYPE} + echo "Building OrcaSlicer ..." - cmake --build build --target OrcaSlicer + cmake --build ${BUILD_DIR} --target OrcaSlicer + echo "Building OrcaSlicer_profile_validator .." - cmake --build build --target OrcaSlicer_profile_validator + cmake --build ${BUILD_DIR} --target OrcaSlicer_profile_validator + ./run_gettext.sh - echo "done" fi -if [[ -e ${ROOT}/build/src/BuildLinuxImage.sh ]]; then +if [[ -n "${PACK_DEPS}" ]] +then + echo "Packing dependencies..." + if [ -d "deps/${BUILD_DIR}/OrcaSlicer_dep" ]; then + cd deps/${BUILD_DIR} + tar -czvf OrcaSlicer_dep_ubuntu_$(date +"%Y%m%d").tar.gz OrcaSlicer_dep + else + echo "The deps destination directory does not exist" + echo "Targeted destination directory: $(pwd)/deps/${BUILD_DIR}/OrcaSlicer_dep" + fi +fi + +if [[ -e ${ROOT}/${BUILD_DIR}/src/BuildLinuxImage.sh ]]; then # Give proper permissions to script -chmod 755 ${ROOT}/build/src/BuildLinuxImage.sh +chmod 755 ${ROOT}/${BUILD_DIR}/src/BuildLinuxImage.sh -echo "[9/9] Generating Linux app..." - pushd build +echo "Generating Linux app..." + pushd ${BUILD_DIR} if [[ -n "${BUILD_IMAGE}" ]] then - ${ROOT}/build/src/BuildLinuxImage.sh -i + ${ROOT}/${BUILD_DIR}/src/BuildLinuxImage.sh -i else - ${ROOT}/build/src/BuildLinuxImage.sh + ${ROOT}/${BUILD_DIR}/src/BuildLinuxImage.sh fi popd -echo "done" fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 197694e0208..f3b833b5833 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 3.13) -if (APPLE) - # if CMAKE_OSX_DEPLOYMENT_TARGET is not set, set it to 11.3 - if (NOT CMAKE_OSX_DEPLOYMENT_TARGET) - set(CMAKE_OSX_DEPLOYMENT_TARGET "11.3" CACHE STRING "Minimum OS X deployment version" FORCE) - endif () - message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}") +message(STATUS "CMake version: ${CMAKE_VERSION}") +message(STATUS "CMake generator: ${CMAKE_GENERATOR}") + +# Setting CMAKE_OSX_ARCHITECTURES needs to be done before calling project() +if (APPLE AND NOT DEFINED CMAKE_OSX_ARCHITECTURES) + set(CMAKE_OSX_ARCHITECTURES ${CMAKE_HOST_SYSTEM_PROCESSOR} CACHE STRING "" FORCE) + message(STATUS "CMAKE_OSX_ARCHITECTURES was not set manually. Setting to the host's native architecture (${CMAKE_HOST_SYSTEM_PROCESSOR})") endif () project(OrcaSlicer) @@ -14,48 +15,107 @@ include("version.inc") include(GNUInstallDirs) include(CMakeDependentOption) +if (DEFINED ENV{SLIC3R_STATIC}) + set(SLIC3R_STATIC_INITIAL $ENV{SLIC3R_STATIC}) +else () + set(SLIC3R_STATIC_INITIAL 1) +endif () + +# Backward compatibility for old CMake versions +if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_VERSION VERSION_LESS "3.25") + set(LINUX ON CACHE BOOL "" FORCE) +endif () + +# Set options and initialize variables +option(SLIC3R_STATIC "Compile OrcaSlicer with static libraries (Boost, TBB, glew)" ${SLIC3R_STATIC_INITIAL}) +option(SLIC3R_GUI "Compile OrcaSlicer with GUI components (OpenGL, wxWidgets)" 1) +option(SLIC3R_FHS "Assume OrcaSlicer is to be installed in a FHS directory structure" 0) +option(SLIC3R_WX_STABLE "Build against wxWidgets stable (3.0) as oppsed to dev (3.1) on Linux" 0) +option(SLIC3R_PROFILE "Compile OrcaSlicer with an invasive Shiny profiler" 0) +option(SLIC3R_PCH "Use precompiled headers" 1) +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_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0) +option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) +# Proposal for C++ unit tests and sandboxes +option(SLIC3R_BUILD_SANDBOXES "Build development sandboxes" OFF) +option(SLIC3R_BUILD_TESTS "Build unit tests" OFF) +option(ORCA_TOOLS "Build Orca tools" OFF) +option(BUILD_DEPS "Build dependencies" OFF) +option(CLEAN_DEPS "Clean build directory dependencies. Only takes effect if also building deps." OFF) +option(FORCE_DEPS "Force build dependencies even if there are no changes. CLEAN_DEPS takes priority. Only takes effect if also building deps." OFF) +option(BUILD_DEPS_QUIET "Don't output the logs from building deps" OFF) +# If SLIC3R_FHS is enabled, forcibly disable desktop integration during runtime. +CMAKE_DEPENDENT_OPTION(SLIC3R_DESKTOP_INTEGRATION "Allow performing desktop integration during runtime" 1 "NOT SLIC3R_FHS" 0) + +set(OPENVDB_FIND_MODULE_PATH "" CACHE PATH "Path to OpenVDB installation's find modules.") +set(SLIC3R_GTK "3" CACHE STRING "GTK version to use with wxWidgets on Linux") +set(IS_CROSS_COMPILE FALSE) +set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "") # Disable deprecation warnings from dependencies built using old CMake versions +set(CGAL_DATA_DIR ".") # Prevent warning from CGAL regarding data dir not being set. Orca does not use CGAL's data dir + +# Enable C++17 language standard. +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +if (POLICY CMP0167) # FindBoost deprecated + # If required boost is set to at least 1.70, this policy should be set to NEW + cmake_policy(SET CMP0167 OLD) + set(CMAKE_POLICY_DEFAULT_CMP0167 OLD) +endif () + set(SLIC3R_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") file(TO_NATIVE_PATH "${SLIC3R_RESOURCES_DIR}" SLIC3R_RESOURCES_DIR_WIN) -if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "No build type selected, default to Release") - set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE) -endif() +get_filename_component(BIN_DIR_NAME ${CMAKE_BINARY_DIR} NAME) +message(STATUS "CMAKE_BINARY_DIR: ${BIN_DIR_NAME}") +set(BIN_DIR_NAME ${BIN_DIR_NAME} CACHE STRING "" FORCE) -if(DEFINED ENV{SLIC3R_STATIC}) - set(SLIC3R_STATIC_INITIAL $ENV{SLIC3R_STATIC}) -else() - if (MSVC OR MINGW OR APPLE) - set(SLIC3R_STATIC_INITIAL 1) - else() - set(SLIC3R_STATIC_INITIAL 0) - endif() +# Set the default build type to Release if not specified. +if (NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type selected, default to Release") + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE) endif() -option(SLIC3R_STATIC "Compile OrcaSlicer with static libraries (Boost, TBB, glew)" ${SLIC3R_STATIC_INITIAL}) -option(SLIC3R_GUI "Compile OrcaSlicer with GUI components (OpenGL, wxWidgets)" 1) -option(SLIC3R_FHS "Assume OrcaSlicer is to be installed in a FHS directory structure" 0) -option(SLIC3R_WX_STABLE "Build against wxWidgets stable (3.0) as oppsed to dev (3.1) on Linux" 0) -option(SLIC3R_PROFILE "Compile OrcaSlicer with an invasive Shiny profiler" 0) -option(SLIC3R_PCH "Use precompiled headers" 1) -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_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0) -option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) -# 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) - -set(OPENVDB_FIND_MODULE_PATH "" CACHE PATH "Path to OpenVDB installation's find modules.") +if(NOT DEFINED BBL_RELEASE_TO_PUBLIC) + if (CMAKE_BUILD_TYPE STREQUAL "Release") + set(BBL_RELEASE_TO_PUBLIC 1) + else () + set(BBL_RELEASE_TO_PUBLIC 0) + endif () +endif() -set(SLIC3R_GTK "2" CACHE STRING "GTK version to use with wxWidgets on Linux") +# Set compiler flags +if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + set(GNU_C TRUE) +endif () +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(GNU TRUE) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CLANG TRUE) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + set(APPLECLANG TRUE) +endif () +if (CLANG OR APPLECLANG) + set(CLANG_VARIANT TRUE) +endif () -set(IS_CROSS_COMPILE FALSE) +if (APPLE) # Set macOS target and determine if we are cross-compiling + # if CMAKE_OSX_DEPLOYMENT_TARGET is not set, set it to 11.3 + if (NOT CMAKE_OSX_DEPLOYMENT_TARGET) + set(CMAKE_OSX_DEPLOYMENT_TARGET "11.3" CACHE STRING "Minimum OS X deployment version" FORCE) + endif () + message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}") -if (APPLE) set(CMAKE_FIND_FRAMEWORK LAST) set(CMAKE_FIND_APPBUNDLE LAST) - list(FIND CMAKE_OSX_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR} _arch_idx) - if (CMAKE_OSX_ARCHITECTURES AND _arch_idx LESS 0) + list(LENGTH CMAKE_OSX_ARCHITECTURES _arch_len) + if (_arch_len GREATER 1) + message(FATAL_ERROR "OrcaSlicer only supports building for one architecture at a time. Please make sure only one architecture is specified in CMAKE_OSX_ARCHITECTURES") + elseif (_arch_len EQUAL 1) + list(GET CMAKE_OSX_ARCHITECTURES 0 MACOS_ARCH) + endif () + if (NOT "${MACOS_ARCH}" STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR}) set(IS_CROSS_COMPILE TRUE) endif () if (CMAKE_MACOSX_BUNDLE) @@ -64,17 +124,11 @@ if (APPLE) SET(CMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.softfever3d.orca-slicer") message(STATUS "Orca: IS_CROSS_COMPILE: ${IS_CROSS_COMPILE}") -endif () - -# Proposal for C++ unit tests and sandboxes -option(SLIC3R_BUILD_SANDBOXES "Build development sandboxes" OFF) -option(SLIC3R_BUILD_TESTS "Build unit tests" OFF) -option(ORCA_TOOLS "Build Orca tools" OFF) - -if (IS_CROSS_COMPILE) - message("Detected cross compilation setup. Tests and encoding checks will be forcedly disabled!") - set(SLIC3R_PERL_XS OFF CACHE BOOL "" FORCE) - set(SLIC3R_BUILD_TESTS OFF CACHE BOOL "" FORCE) + if (IS_CROSS_COMPILE) + message(STATUS "Detected cross compilation setup. Tests and encoding checks will be forcedly disabled!") + set(SLIC3R_PERL_XS OFF CACHE BOOL "" FORCE) + set(SLIC3R_BUILD_TESTS OFF CACHE BOOL "" FORCE) + endif () endif () # Print out the SLIC3R_* cache options @@ -94,63 +148,83 @@ if(SLIC3R_DESKTOP_INTEGRATION) add_definitions(-DSLIC3R_DESKTOP_INTEGRATION) endif () -if (MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL Clang) - set(IS_CLANG_CL TRUE) - - # clang-cl can interpret SYSTEM header paths if -imsvc is used - set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-imsvc") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + message(STATUS "Automatically setting CMAKE_INSTALL_PREFIX") + message(STATUS "Default: ${CMAKE_INSTALL_PREFIX}") + set_property(CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_BINARY_DIR}/OrcaSlicer") +endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall \ - -Wno-old-style-cast -Wno-reserved-id-macro -Wno-c++98-compat-pedantic") +if ("${DEP_BUILD_DIR}" STREQUAL "") + set(DEP_BUILD_DIR "${CMAKE_SOURCE_DIR}/deps/${BIN_DIR_NAME}" CACHE PATH "Path to dependencies build directory" FORCE) + message(STATUS "DEP_BUILD_DIR: ${DEP_BUILD_DIR} (generated automatically and saved to cache)") + set(AUTOGENERATED_DEP_BUILD_DIR ${DEP_BUILD_DIR} CACHE PATH "Provides the last autogenerated DEP_BUILD_DIR" FORCE) else () - set(IS_CLANG_CL FALSE) + message(STATUS "DEP_BUILD_DIR: ${DEP_BUILD_DIR} (from cache or command line)") endif () -if (MSVC) - if (SLIC3R_MSVC_COMPILE_PARALLEL AND NOT IS_CLANG_CL) - add_compile_options(/MP) + +if ("${CMAKE_PREFIX_PATH}" STREQUAL "" OR "${CMAKE_PREFIX_PATH}" STREQUAL "${AUTOGENERATED_PREFIX_PATH}") + if (DEFINED AUTOGENERATED_DEP_BUILD_DIR AND NOT "${DEP_BUILD_DIR}" STREQUAL "${AUTOGENERATED_DEP_BUILD_DIR}") + message(STATUS "CMAKE_PREFIX_PATH is being re-generated due to DEP_BUILD_DIR being manually updated") + set(REGEN_DESTDIR TRUE) + unset(AUTOGENERATED_DEP_BUILD_DIR CACHE) endif () - # /bigobj (Increase Number of Sections in .Obj file) - # error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm90' or greater - # Generate symbols at every build target, even for the release. - add_compile_options(-bigobj -Zm520 /Zi) - # Disable STL4007: Many result_type typedefs and all argument_type, first_argument_type, and second_argument_type typedefs are deprecated in C++17. - #FIXME Remove this line after eigen library adapts to the new C++17 adaptor rules. - add_compile_options(-D_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING) - # Disable warnings on conversion from unsigned to signed (possible loss of data) - # C4244: 'conversion' conversion from 'type1' to 'type2', possible loss of data. An integer type is converted to a smaller integer type. - # C4267: The compiler detected a conversion from size_t to a smaller type. - add_compile_options(/wd4244 /wd4267) - # Disable warnings on comparison of unsigned and signed - # C4018: signed/unsigned mismatch - add_compile_options(/wd4018) + if (LINUX AND (NOT DEFINED USE_OLD_DESTDIR_PREV OR USE_OLD_DESTDIR_PREV) AND EXISTS "${DEP_BUILD_DIR}/destdir/usr/local" AND NOT EXISTS "${DEP_BUILD_DIR}/OrcaSlicer_dep/usr/local") + set(USE_OLD_DESTDIR TRUE) + endif () + if (LINUX AND NOT USE_OLD_DESTDIR AND USE_OLD_DESTDIR_PREV) + set(REGEN_DESTDIR TRUE) + endif () +elseif () + if (DEFINED AUTOGENERATED_DEP_BUILD_DIR AND BUILD_DEPS) + message(WARNING "CMAKE_PREFIX_PATH was manually set. Make sure that DEP_BUILD_DIR is also set to the correct location.") + endif () + unset(AUTOGENERATED_PREFIX_PATH CACHE) endif () -if (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 15) - add_compile_definitions(BOOST_NO_CXX98_FUNCTION_BASE _HAS_AUTO_PTR_ETC=0) -endif() -if (MINGW) - add_compile_options(-Wa,-mbig-obj) +# Display and check CMAKE_PREFIX_PATH +if ("${CMAKE_PREFIX_PATH}" STREQUAL "" OR REGEN_DESTDIR) + if (USE_OLD_DESTDIR) # backward compatibility for old directory name + set(CMAKE_PREFIX_PATH "${DEP_BUILD_DIR}/destdir/usr/local" CACHE PATH "Path to dependencies" FORCE) + message(WARNING "You are using an old directory name for dependencies that is being deprecated. " + "Please rename \"destdir\" to \"OrcaSlicer_dep\" or remove the destdir directory and rebuild. " + "The current \"destdir\" directory will be used until then.") + else () + set(CMAKE_PREFIX_PATH "${DEP_BUILD_DIR}/OrcaSlicer_dep") + if (APPLE) + set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}_${CMAKE_OSX_ARCHITECTURES}") + endif () + set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}/usr/local" CACHE PATH "Path to dependencies install directory" FORCE) + endif () + message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH} (generated automatically and saved to cache)") + set(PREFIX_PATH_CHECK ${CMAKE_PREFIX_PATH}) + set(AUTOGENERATED_PREFIX_PATH ${CMAKE_PREFIX_PATH} CACHE STRING "Provides the last autogenerated CMAKE_PREFIX_PATH" FORCE) + unset(REGEN_DESTDIR CACHE) +else () + message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH} (from cache or command line)") + set(PREFIX_PATH_CHECK ${CMAKE_PREFIX_PATH}) +endif () + +if (LINUX) + set(USE_OLD_DESTDIR_PREV ${USE_OLD_DESTDIR} CACHE STRING "Indicates if the old destdir was used during the previous configuration" FORCE) endif () -if (NOT MSVC) - # ARMs (Raspberry PI) use an unsigned char by default. Let's make it consistent for OrcaSlicer on all platforms. - add_compile_options(-fsigned-char) +if ("${DEP_DESTDIR}" STREQUAL "") + cmake_path(SET DEP_DESTDIR NORMALIZE "${CMAKE_PREFIX_PATH}/../..") endif () -# Display and check CMAKE_PREFIX_PATH -message(STATUS "SLIC3R_STATIC: ${SLIC3R_STATIC}") -if (NOT "${CMAKE_PREFIX_PATH}" STREQUAL "") - message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH} (from cache or command line)") - set(PREFIX_PATH_CHECK ${CMAKE_PREFIX_PATH}) -elseif (NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "") +if (APPLE AND CMAKE_MACOSX_RPATH AND "${CMAKE_INSTALL_RPATH}" STREQUAL "") + set(CMAKE_INSTALL_RPATH ${CMAKE_PREFIX_PATH}) +endif () + +# the CMAKE_PREFIX_PATH environment variable is separate from the CMAKE_PREFIX_PATH cache variable and provides additional paths to search for libraries. +if (NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "") message(STATUS "CMAKE_PREFIX_PATH: $ENV{CMAKE_PREFIX_PATH} (from environment)") - set(PREFIX_PATH_CHECK $ENV{CMAKE_PREFIX_PATH}) -else () - message(STATUS "CMAKE_PREFIX_PATH: (default)") + list(APPEND PREFIX_PATH_CHECK $ENV{CMAKE_PREFIX_PATH}) endif () +# Check all directories in CMAKE_PREFIX_PATH variables foreach (DIR ${PREFIX_PATH_CHECK}) if (NOT EXISTS "${DIR}") message(WARNING "CMAKE_PREFIX_PATH element doesn't exist: ${DIR}") @@ -162,24 +236,65 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/) message(STATUS "PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}") message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}") -enable_testing () - -# Enable C++17 language standard. -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +if (BUILD_DEPS) + include("deps/autobuild.cmake") +endif () +# leaving these in cache could impact the next build +unset(CLEAN_DEPS CACHE) +unset(FORCE_DEPS CACHE) -if(NOT WIN32) - # Add DEBUG flags to debug builds. - add_compile_options("$<$:-DDEBUG>") -endif() +enable_testing() # To be able to link libslic3r with the Perl XS module. # Once we get rid of Perl and libslic3r is linked statically, we can get rid of -fPIC set(CMAKE_POSITION_INDEPENDENT_CODE ON) -# WIN10SDK_PATH is used to point CMake to the WIN10 SDK installation directory. -# We pick it from environment if it is not defined in another way if(WIN32) + if (MSVC) + if (CLANG) + # clang-cl can interpret SYSTEM header paths if -imsvc is used + set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-imsvc") + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall \ + -Wno-old-style-cast -Wno-reserved-id-macro -Wno-c++98-compat-pedantic") + elseif (SLIC3R_MSVC_COMPILE_PARALLEL) + add_compile_options(/MP) + endif () + # /bigobj (Increase Number of Sections in .Obj file) + # error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm90' or greater + # Generate symbols at every build target, even for the release. + add_compile_options(-bigobj -Zm520 /Zi) + # Disable STL4007: Many result_type typedefs and all argument_type, first_argument_type, and second_argument_type typedefs are deprecated in C++17. + #FIXME Remove this line after eigen library adapts to the new C++17 adaptor rules. + add_compile_options(-D_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING) + # Disable warnings on conversion from unsigned to signed (possible loss of data) + # C4244: 'conversion' conversion from 'type1' to 'type2', possible loss of data. An integer type is converted to a smaller integer type. + # C4267: The compiler detected a conversion from size_t to a smaller type. + add_compile_options(/wd4244 /wd4267) + # Disable warnings on comparison of unsigned and signed + # C4018: signed/unsigned mismatch + add_compile_options(/wd4018) + # Add compile option, ignore warning C4305 (truncation from type conversion) + add_compile_options(/wd4305) + # BOOST_ALL_NO_LIB: Avoid the automatic linking of Boost libraries on Windows. Rather rely on explicit linking. + add_definitions(-DBOOST_ALL_NO_LIB -DBOOST_USE_WINAPI_VERSION=0x602 -DBOOST_SYSTEM_USE_UTF8 ) + # Force the source code encoding to UTF-8. See OrcaSlicer GH pull request #5583 + add_compile_options("$<$:/utf-8>") + add_compile_options("$<$:/utf-8>") + else () + # ARMs (Raspberry PI) use an unsigned char by default. Let's make it consistent for OrcaSlicer on all platforms. + add_compile_options(-fsigned-char) + endif () + + if (MINGW) + add_compile_options(-Wa,-mbig-obj) + endif () + + # Windows specific definitions + add_definitions(-D_USE_MATH_DEFINES -D_WIN32 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS) + + # WIN10SDK_PATH is used to point CMake to the WIN10 SDK installation directory. + # We pick it from environment if it is not defined in another way if(NOT DEFINED WIN10SDK_PATH) if(DEFINED ENV{WIN10SDK_PATH}) set(WIN10SDK_PATH "$ENV{WIN10SDK_PATH}") @@ -190,44 +305,53 @@ if(WIN32) if (EXISTS "${WIN10SDK_PATH}/winrt/windows.graphics.printing3d.h") set(WIN10SDK_INCLUDE_PATH "${WIN10SDK_PATH}") else() - message("WIN10SDK_PATH is invalid: ${WIN10SDK_PATH}") - message("${WIN10SDK_PATH}/winrt/windows.graphics.printing3d.h was not found") - message("STL fixing by the Netfabb service will not be compiled") + message(WARNING "WIN10SDK_PATH is invalid: ${WIN10SDK_PATH}") + message(WARNING "${WIN10SDK_PATH}/winrt/windows.graphics.printing3d.h was not found") unset(WIN10SDK_PATH) endif() else() # Try to use the default Windows 10 SDK path. - set(WIN10SDK_INCLUDE_PATH "$ENV{WindowsSdkDir}/Include/$ENV{WindowsSDKVersion}") + if (DEFINED ENV{WindowsSdkDir} AND DEFINED ENV{WindowsSDKVersion}) + set(WIN10SDK_INCLUDE_PATH "$ENV{WindowsSdkDir}/Include/$ENV{WindowsSDKVersion}") + else () + set(WIN10SDK_INCLUDE_PATH "C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0") + endif () if (NOT EXISTS "${WIN10SDK_INCLUDE_PATH}/winrt/windows.graphics.printing3d.h") - message("${WIN10SDK_INCLUDE_PATH}/winrt/windows.graphics.printing3d.h was not found") - message("STL fixing by the Netfabb service will not be compiled") + message(WARNING "${WIN10SDK_INCLUDE_PATH}/winrt/windows.graphics.printing3d.h was not found") unset(WIN10SDK_INCLUDE_PATH) endif() endif() if(WIN10SDK_INCLUDE_PATH) - message("Building with Win10 Netfabb STL fixing service support") + message(STATUS "Building with Win10 Netfabb STL fixing service support") add_definitions(-DHAS_WIN10SDK) include_directories("${WIN10SDK_INCLUDE_PATH}") else() - message("Building without Win10 Netfabb STL fixing service support") + message(STATUS "Building without Win10 Netfabb STL fixing service support") endif() +else() + # Add DEBUG flags to debug builds. + add_compile_options("$<$:-DDEBUG>") endif() if (APPLE) - message("OS X SDK Path: ${CMAKE_OSX_SYSROOT}") + message(STATUS "OS X SDK Path: ${CMAKE_OSX_SYSROOT}") if (CMAKE_OSX_DEPLOYMENT_TARGET) - message("OS X Deployment Target: ${CMAKE_OSX_DEPLOYMENT_TARGET}") + message(STATUS "OS X Deployment Target: ${CMAKE_OSX_DEPLOYMENT_TARGET}") else () - message("OS X Deployment Target: (default)") + message(STATUS "OS X Deployment Target: (default)") endif () + + if (APPLECLANG AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 15) + add_compile_definitions(BOOST_NO_CXX98_FUNCTION_BASE _HAS_AUTO_PTR_ETC=0) + endif() endif () -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +if (LINUX) find_package(PkgConfig REQUIRED) if (CMAKE_VERSION VERSION_LESS "3.1") # Workaround for an old CMake, which does not understand CMAKE_CXX_STANDARD. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${CMAKE_CXX_STANDARD}") endif() # Boost on Raspberry-Pi does not link to pthreads. @@ -238,12 +362,12 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux") include_directories(${DBUS_INCLUDE_DIRS}) endif() -if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX) +if (GNU) # Adding -fext-numeric-literals to enable GCC extensions on definitions of quad float literals, which are required by Boost. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fext-numeric-literals" ) endif() -if (NOT MSVC AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) +if (NOT MSVC AND (GNU OR CLANG_VARIANT)) if (NOT MINGW) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) endif () @@ -270,18 +394,18 @@ if (NOT MSVC AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMP # removes LOTS of extraneous Eigen warnings (GCC only supports it since 6.1) # https://eigen.tuxfamily.org/bz/show_bug.cgi?id=1221 - if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0) + if(CLANG_VARIANT OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0) add_compile_options(-Wno-ignored-attributes) # Tamas: Eigen include dirs are marked as SYSTEM endif() # Clang reports legacy OpenGL calls as deprecated. Turn off the warning for now # to reduce the clutter, we know about this one. It should be reenabled after # we finally get rid of the deprecated code. - if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + if(CLANG) add_compile_options(-Wno-deprecated-declarations) endif() - if (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang" AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 15) + if (APPLECLANG AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 15) add_compile_options(-Wno-error=enum-constexpr-conversion) endif() @@ -289,19 +413,18 @@ if (NOT MSVC AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMP # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66943 or # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431 # We will turn the warning of for GCC for now: - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + if(GNU) # GCC generates loads of -Wunknown-pragmas when compiling igl. The fix is not easy due to a bug in gcc, see # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66943 or # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431 # We will turn the warning of for GCC for now: add_compile_options(-Wno-unknown-pragmas) - endif() - # Bit of a hack for flatpak building: compress the debug info with zstd to save space in CI - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 13.0) - add_compile_options(-gz=zstd) + # Bit of a hack for flatpak building: compress the debug info with zstd to save space in CI + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 13.0) + add_compile_options(-gz=zstd) + endif() endif() - endif() if (SLIC3R_ASAN) @@ -318,21 +441,13 @@ if (SLIC3R_ASAN) add_compile_definitions(_DISABLE_STRING_ANNOTATION=1 _DISABLE_VECTOR_ANNOTATION=1) endif () - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + if (GNU) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan") endif () -endif () - -if (APPLE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=partial-availability -Werror=unguarded-availability -Werror=unguarded-availability-new") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=partial-availability -Werror=unguarded-availability -Werror=unguarded-availability-new") endif () -if(MSVC) -# 添加编译选项,忽略警告 C4305 (格式转换截断) -add_compile_options(/wd4305) -endif() - # Where all the bundled libraries reside? set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set(LIBDIR_BIN ${CMAKE_CURRENT_BINARY_DIR}/src) @@ -346,24 +461,13 @@ include_directories(${LIBDIR_BIN}/platform) # For ligigl include_directories(${LIBDIR}/libigl) -if(WIN32) - add_definitions(-D_USE_MATH_DEFINES -D_WIN32 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS) - if(MSVC) - # BOOST_ALL_NO_LIB: Avoid the automatic linking of Boost libraries on Windows. Rather rely on explicit linking. - add_definitions(-DBOOST_ALL_NO_LIB -DBOOST_USE_WINAPI_VERSION=0x602 -DBOOST_SYSTEM_USE_UTF8 ) - # Force the source code encoding to UTF-8. See OrcaSlicer GH pull request #5583 - add_compile_options("$<$:/utf-8>") - add_compile_options("$<$:/utf-8>") - endif(MSVC) -endif(WIN32) - +## Generic definitions add_definitions(-DwxUSE_UNICODE -D_UNICODE -DUNICODE -DWXINTL_NO_GETTEXT_MACRO) - # Disable unsafe implicit wxString to const char* / std::string and vice versa. This implicit conversion breaks the UTF-8 encoding quite often. add_definitions(-DwxNO_UNSAFE_WXSTRING_CONV) if (SLIC3R_PROFILE) - message("OrcaSlicer will be built with a Shiny invasive profiler") + message(STATUS "OrcaSlicer will be built with a Shiny invasive profiler") add_definitions(-DSLIC3R_PROFILE) endif () @@ -468,13 +572,7 @@ find_package(ZLIB REQUIRED) target_link_libraries(libcurl INTERFACE ZLIB::ZLIB) # Fixing curl's cmake config script bugs -if (NOT WIN32) - # Required by libcurl - #find_package(ZLIB REQUIRED) - #target_link_libraries(libcurl INTERFACE ZLIB::ZLIB) - #find_package(Libssh2 REQUIRED) - #target_link_libraries(libcurl INTERFACE Libssh2::libssh2) -else() +if (WIN32) target_link_libraries(libcurl INTERFACE crypt32) endif() @@ -484,12 +582,12 @@ if (SLIC3R_STATIC AND NOT SLIC3R_STATIC_EXCLUDE_CURL) # On other systems, libcurl is linked statically if SLIC3R_STATIC is set. target_compile_definitions(libcurl INTERFACE CURL_STATICLIB) endif() - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + if (LINUX) # As of now, our build system produces a statically linked libcurl, # which links the OpenSSL library dynamically. find_package(OpenSSL REQUIRED) - message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") - message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") + message(STATUS "OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") + message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}") target_include_directories(libcurl INTERFACE ${OPENSSL_INCLUDE_DIR}) target_link_libraries(libcurl INTERFACE ${OPENSSL_LIBRARIES}) endif() @@ -529,7 +627,7 @@ set(OpenGL_GL_PREFERENCE "LEGACY") find_package(OpenGL REQUIRED) set(GLEW_ROOT "${CMAKE_PREFIX_PATH}") -message("GLEW_ROOT: ${GLEW_ROOT}") +message(STATUS "GLEW_ROOT: ${GLEW_ROOT}") # Find glew or use bundled version if (SLIC3R_STATIC AND NOT SLIC3R_STATIC_EXCLUDE_GLEW) set(GLEW_USE_STATIC_LIBS ON) @@ -637,13 +735,13 @@ function(orcaslicer_copy_dlls target config postfix output_dlls) if (_alt_out_dir) set (_out_dir "${_alt_out_dir}") - message ("set out_dir to _alt_out_dir: ${_out_dir}") + message (STATUS "set out_dir to _alt_out_dir: ${_out_dir}") elseif (_is_multi) set(_out_dir "${CMAKE_CURRENT_BINARY_DIR}/${config}") - message ("set out_dir to CMAKE_CURRENT_BINARY_DIR/config: ${_out_dir}") + message (STATUS "set out_dir to CMAKE_CURRENT_BINARY_DIR/config: ${_out_dir}") else () set(_out_dir "${CMAKE_CURRENT_BINARY_DIR}") - message ("set out_dir to CMAKE_CURRENT_BINARY_DIR: ${_out_dir}") + message (STATUS "set out_dir to CMAKE_CURRENT_BINARY_DIR: ${_out_dir}") endif () file(COPY ${TOP_LEVEL_PROJECT_DIR}/deps/GMP/gmp/lib/win${_bits}/libgmp-10.dll diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000000..d7158a90808 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,142 @@ +{ + "version": 4, + "cmakeMinimumRequired": {"major": 3, "minor": 23 }, + "include": [ + "cmake/presets/Linux.json", + "cmake/presets/macOS.json", + "cmake/presets/Windows.json", + "cmake/presets/base.json" + ], + "configurePresets": [ + { + "name": "linux-release", + "displayName": "Linux Release Configure", + "inherits": [ + "linux-base", + "base-release" + ] + }, + { + "name": "linux-relwithdebinfo", + "displayName": "Linux RelWithDebInfo Configure", + "inherits": [ + "linux-base", + "base-relwithdebinfo" + ] + }, + { + "name": "linux-debug", + "displayName": "Linux Debug Configure", + "inherits": [ + "linux-base", + "base-debug" + ] + }, + { + "name": "macos-x64-release", + "displayName": "macOS x64 Release Configure", + "inherits": [ + "macos-base-x64", + "base-release" + ] + }, + { + "name": "macos-x64-relwithdebinfo", + "displayName": "macOS x64 RelWithDebInfo Configure", + "inherits": [ + "macos-base-x64", + "base-relwithdebinfo" + ] + }, + { + "name": "macos-arm64-release", + "displayName": "macOS ARM64 Release Configure", + "inherits": [ + "macos-base-arm64", + "base-release" + ] + }, + { + "name": "macos-arm64-relwithdebinfo", + "displayName": "macOS ARM64 RelWithDebInfo Configure", + "inherits": [ + "macos-base-arm64", + "base-relwithdebinfo" + ] + }, + { + "name": "windows-release", + "displayName": "Windows Release Configure", + "inherits": [ + "windows-base", + "base-release" + ] + }, + { + "name": "windows-relwithdebinfo", + "displayName": "Windows RelWithDebInfo Configure", + "inherits": [ + "windows-base", + "base-relwithdebinfo" + ] + } + ], + "buildPresets": [ + { + "name": "linux-release", + "displayName": "Linux Release Build", + "inherits": "linux-base-build", + "configurePreset": "linux-release" + }, + { + "name": "linux-relwithdebinfo", + "displayName": "Linux RelWithDebInfo Build", + "inherits": "linux-base-build", + "configurePreset": "linux-relwithdebinfo" + }, + { + "name": "linux-debug", + "displayName": "Linux Debug Build", + "inherits": "linux-base-build", + "configurePreset": "linux-debug" + }, + { + "name": "macos-x64-release", + "displayName": "macOS x64 Release Build", + "inherits": "macos-base-build", + "configurePreset": "macos-x64-release" + }, + { + "name": "macos-x64-relwithdebinfo", + "displayName": "macOS x64 RelWithDebInfo Build", + "inherits": "macos-base-build", + "configurePreset": "macos-x64-relwithdebinfo" + }, + { + "name": "macos-arm64-release", + "displayName": "macOS ARM64 Release Build", + "inherits": "macos-base-build", + "configurePreset": "macos-arm64-release" + }, + { + "name": "macos-arm64-relwithdebinfo", + "displayName": "macOS ARM64 RelWithDebInfo Build", + "inherits": "macos-base-build", + "configurePreset": "macos-arm64-relwithdebinfo" + }, + { + "name": "windows-release", + "displayName": "Windows Release Build", + "inherits": "windows-base-build", + "configurePreset": "windows-release", + "configuration": "Release" + }, + { + "name": "windows-relwithdebinfo", + "displayName": "Windows RelWithDebInfo Build", + "inherits": "windows-base-build", + "configurePreset": "windows-relwithdebinfo", + "configuration": "RelWithDebInfo" + } + ] +} \ No newline at end of file diff --git a/build_release.bat b/build_release.bat index f0e5eef5e75..9bde0cf994c 100644 --- a/build_release.bat +++ b/build_release.bat @@ -1,50 +1,2 @@ -set WP=%CD% - -set debug=OFF -set debuginfo=OFF -if "%1"=="debug" set debug=ON -if "%2"=="debug" set debug=ON -if "%1"=="debuginfo" set debuginfo=ON -if "%2"=="debuginfo" set debuginfo=ON -if "%debug%"=="ON" ( - set build_type=Debug - set build_dir=build-dbg -) else ( - if "%debuginfo%"=="ON" ( - set build_type=RelWithDebInfo - set build_dir=build-dbginfo - ) else ( - set build_type=Release - set build_dir=build - ) -) -echo build type set to %build_type% - -cd deps -mkdir %build_dir% -cd %build_dir% -set DEPS=%CD%/OrcaSlicer_dep -if "%1"=="slicer" ( - GOTO :slicer -) -echo "building deps.." - -echo cmake ../ -G "Visual Studio 16 2019" -A x64 -DDESTDIR="%CD%/OrcaSlicer_dep" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% -cmake ../ -G "Visual Studio 16 2019" -A x64 -DDESTDIR="%CD%/OrcaSlicer_dep" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% -cmake --build . --config %build_type% --target deps -- -m - -if "%1"=="deps" exit /b 0 - -:slicer -echo "building Orca Slicer..." -cd %WP% -mkdir %build_dir% -cd %build_dir% - -echo cmake .. -G "Visual Studio 16 2019" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -cmake .. -G "Visual Studio 16 2019" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0" -cmake --build . --config %build_type% --target ALL_BUILD -- -m -cd .. -call run_gettext.bat -cd %build_dir% -cmake --build . --target install --config %build_type% +@echo off +call build_release_vs2022.bat vs2019 %* \ No newline at end of file diff --git a/build_release_macos.sh b/build_release_macos.sh index 38a360ed2d7..c9a49f12b4a 100755 --- a/build_release_macos.sh +++ b/build_release_macos.sh @@ -3,7 +3,7 @@ set -e set -o pipefail -while getopts ":dpa:snt:xbc:h" opt; do +while getopts ":dpa:snt:xbc:h1" opt; do case "${opt}" in d ) export BUILD_TARGET="deps" @@ -85,6 +85,23 @@ if [ -z "$OSX_DEPLOYMENT_TARGET" ]; then export OSX_DEPLOYMENT_TARGET="11.3" fi +case ${BUILD_CONFIG} in +Release ) + export BUILD_DIR_NAME="build" + ;; +RelWithDebInfo ) + export BUILD_DIR_NAME="build-dbginfo" + ;; +Debug ) + export BUILD_DIR_NAME="build-debug" + ;; +* ) + echo Invalid build config \""${BUILD_CONFIG}"\". Valid options are Release, RelWithDebInfo, and Debug + exit 1 + ;; +esac +BUILD_DIR_NAME=$BUILD_DIR_NAME"_"$ARCH + echo "Build params:" echo " - ARCH: $ARCH" echo " - BUILD_CONFIG: $BUILD_CONFIG" @@ -107,10 +124,7 @@ echo # fi PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -PROJECT_BUILD_DIR="$PROJECT_DIR/build_$ARCH" -DEPS_DIR="$PROJECT_DIR/deps" -DEPS_BUILD_DIR="$DEPS_DIR/build_$ARCH" -DEPS="$DEPS_BUILD_DIR/OrcaSlicer_dep_$ARCH" +DESTDIR="deps/$BUILD_DIR_NAME/OrcaSlicer_dep_$ARCH" # Fix for Multi-config generators if [ "$SLICER_CMAKE_GENERATOR" == "Xcode" ]; then @@ -123,28 +137,28 @@ function build_deps() { echo "Building deps..." ( set -x - mkdir -p "$DEPS" - cd "$DEPS_BUILD_DIR" - if [ "1." != "$BUILD_ONLY". ]; then - cmake .. \ + if [ -z "$BUILD_ONLY" ]; then + cmake -S deps -B "deps/$BUILD_DIR_NAME" \ -G "${DEPS_CMAKE_GENERATOR}" \ - -DDESTDIR="$DEPS" \ - -DOPENSSL_ARCH="darwin64-${ARCH}-cc" \ -DCMAKE_BUILD_TYPE="$BUILD_CONFIG" \ -DCMAKE_OSX_ARCHITECTURES:STRING="${ARCH}" \ -DCMAKE_OSX_DEPLOYMENT_TARGET="${OSX_DEPLOYMENT_TARGET}" fi - cmake --build . --config "$BUILD_CONFIG" --target deps + cmake --build "deps/$BUILD_DIR_NAME" --config "$BUILD_CONFIG" --target deps ) } function pack_deps() { echo "Packing deps..." ( - set -x - mkdir -p "$DEPS" - cd "$DEPS_BUILD_DIR" - tar -zcvf "OrcaSlicer_dep_mac_${ARCH}_$(date +"%Y%m%d").tar.gz" "OrcaSlicer_dep_$ARCH" + if [ -d "$DESTDIR" ]; then + set -x + cd "$DESTDIR/.." + tar -zcvf "OrcaSlicer_dep_mac_${ARCH}_$(date +"%Y%m%d").tar.gz" "OrcaSlicer_dep_$ARCH" + else + echo "The deps destination directory does not exist" + echo "Targeted destination directory: $(pwd)/$DESTDIR" + fi ) } @@ -152,22 +166,16 @@ function build_slicer() { echo "Building slicer..." ( set -x - mkdir -p "$PROJECT_BUILD_DIR" - cd "$PROJECT_BUILD_DIR" - if [ "1." != "$BUILD_ONLY". ]; then - cmake .. \ + if [ -z "$BUILD_ONLY" ]; then + cmake . -B "${BUILD_DIR_NAME}" \ -G "${SLICER_CMAKE_GENERATOR}" \ - -DBBL_RELEASE_TO_PUBLIC=1 \ - -DCMAKE_PREFIX_PATH="$DEPS/usr/local" \ - -DCMAKE_INSTALL_PREFIX="$PWD/OrcaSlicer" \ -DCMAKE_BUILD_TYPE="$BUILD_CONFIG" \ -DCMAKE_MACOSX_RPATH=ON \ - -DCMAKE_INSTALL_RPATH="${DEPS}/usr/local" \ -DCMAKE_MACOSX_BUNDLE=ON \ -DCMAKE_OSX_ARCHITECTURES="${ARCH}" \ -DCMAKE_OSX_DEPLOYMENT_TARGET="${OSX_DEPLOYMENT_TARGET}" fi - cmake --build . --config "$BUILD_CONFIG" --target "$SLICER_BUILD_TARGET" + cmake --build "${BUILD_DIR_NAME}" --config "$BUILD_CONFIG" --target "$SLICER_BUILD_TARGET" ) echo "Verify localization with gettext..." @@ -178,7 +186,7 @@ function build_slicer() { echo "Fix macOS app package..." ( - cd "$PROJECT_BUILD_DIR" + cd "$BUILD_DIR_NAME" mkdir -p OrcaSlicer cd OrcaSlicer # remove previously built app @@ -205,6 +213,8 @@ function build_slicer() { # zip -FSr OrcaSlicer${ver}_Mac_${ARCH}.zip OrcaSlicer.app } +cd "$PROJECT_DIR" + case "${BUILD_TARGET}" in all) build_deps @@ -217,11 +227,11 @@ case "${BUILD_TARGET}" in build_slicer ;; *) - echo "Unknown target: $BUILD_TARGET. Available targets: deps, slicer, all." + echo "Unknown target: $BUILD_TARGET. Available targets: deps, slicer, all" exit 1 ;; esac -if [ "1." == "$PACK_DEPS". ]; then +if [ -n "$PACK_DEPS" ]; then pack_deps fi diff --git a/build_release_vs2022.bat b/build_release_vs2022.bat index 76e8c14f0c2..735ca14e46b 100644 --- a/build_release_vs2022.bat +++ b/build_release_vs2022.bat @@ -1,9 +1,44 @@ -@REM OcarSlicer build script for Windows +@REM OrcaSlicer build script for Windows @echo off set WP=%CD% +set build_type=Release +set build_dir=build +set debug=OFF +set debuginfo=OFF +set generator="Visual Studio 17 2022" + +@REM Credit to this StackOverflow answer: https://stackoverflow.com/a/3661082 +:GETOPTS + if /I "%1" == "deps" set deps=ON + if /I "%1" == "slicer" set slicer=ON + if /I "%1" == "debug" ( + set debug=ON + set build_type=Debug + set build_dir=build-dbg + ) + if /I "%1" == "debuginfo" ( + set debuginfo=ON + set build_type=RelWithDebInfo + set build_dir=build-dbginfo + ) + if /I "%1" == "pack" set pack=ON + if /I "%1" == "vs2019" set generator="Visual Studio 16 2019" + if /I "%1" == "killbuild" ( + taskkill /F /IM cl.exe + taskkill /F /IM MSBuild.exe + exit /b 0 + ) + shift +if not "%1" == "" goto GETOPTS + +if "%deps%"=="ON" if "%slicer%"=="ON" ( + set deps=OFF + set slicer=OFF +) + @REM Pack deps -if "%1"=="pack" ( +if "%pack%"=="ON" ( setlocal ENABLEDELAYEDEXPANSION cd %WP%/deps/build for /f "tokens=2-4 delims=/ " %%a in ('date /t') do set build_date=%%c%%b%%a @@ -13,55 +48,47 @@ if "%1"=="pack" ( exit /b 0 ) -set debug=OFF -set debuginfo=OFF -if "%1"=="debug" set debug=ON -if "%2"=="debug" set debug=ON -if "%1"=="debuginfo" set debuginfo=ON -if "%2"=="debuginfo" set debuginfo=ON -if "%debug%"=="ON" ( - set build_type=Debug - set build_dir=build-dbg -) else ( - if "%debuginfo%"=="ON" ( - set build_type=RelWithDebInfo - set build_dir=build-dbginfo - ) else ( - set build_type=Release - set build_dir=build - ) -) -echo build type set to %build_type% +echo Build type set to %build_type% -setlocal DISABLEDELAYEDEXPANSION -cd deps -mkdir %build_dir% -cd %build_dir% -set DEPS=%CD%/OrcaSlicer_dep +setlocal DISABLEDELAYEDEXPANSION -if "%1"=="slicer" ( +if "%slicer%"=="ON" ( GOTO :slicer ) -echo "building deps.." -echo on -cmake ../ -G "Visual Studio 17 2022" -A x64 -DDESTDIR="%DEPS%" -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% -cmake --build . --config %build_type% --target deps -- -m -@echo off +echo "Building Orca Slicer deps..." + +set command=cmake -S deps -B deps/%build_dir% -G %generator% -A x64 -DCMAKE_BUILD_TYPE=%build_type% -DDEP_DEBUG=%debug% -DORCA_INCLUDE_DEBUG_INFO=%debuginfo% +echo Configuring deps with the following command: %command% +%command% +if %errorlevel% neq 0 exit /b %errorlevel% + +set command=cmake --build deps/%build_dir% --config %build_type% --target deps -- -m +echo Building deps with the following command: %command% +%command% +if %errorlevel% neq 0 exit /b %errorlevel% + + +if "%deps%"=="ON" exit /b 0 -if "%1"=="deps" exit /b 0 :slicer -echo "building Orca Slicer..." -cd %WP% -mkdir %build_dir% -cd %build_dir% - -echo on -cmake .. -G "Visual Studio 17 2022" -A x64 -DBBL_RELEASE_TO_PUBLIC=1 -DCMAKE_PREFIX_PATH="%DEPS%/usr/local" -DCMAKE_INSTALL_PREFIX="./OrcaSlicer" -DCMAKE_BUILD_TYPE=%build_type% -DWIN10SDK_PATH="%WindowsSdkDir%Include\%WindowsSDKVersion%\" -cmake --build . --config %build_type% --target ALL_BUILD -- -m -@echo off -cd .. +echo Building Orca Slicer... + +set command=cmake . -B %build_dir% -G %generator% -A x64 -DCMAKE_BUILD_TYPE=%build_type% +echo Configuring Orca Slicer with the following command: %command% +%command% +if %errorlevel% neq 0 exit /b %errorlevel% + +set command=cmake --build %build_dir% --config %build_type% --target ALL_BUILD -- -m +echo Building Orca Slicer with the following command: %command% +%command% +if %errorlevel% neq 0 exit /b %errorlevel% + +echo Calling run_gettext.bat call run_gettext.bat -cd %build_dir% -cmake --build . --target install --config %build_type% + +set command=cmake --build %build_dir% --target install --config %build_type% +echo Installing Orca Slicer with the following command: %command% +%command% +if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/cmake/modules/FindNLopt.cmake b/cmake/modules/FindNLopt.cmake index 912ce8d30a3..d5ab8ec420c 100644 --- a/cmake/modules/FindNLopt.cmake +++ b/cmake/modules/FindNLopt.cmake @@ -28,7 +28,7 @@ if(NOT NLopt_DIR) set(NLopt_FOUND TRUE) - set(_NLopt_LIB_NAMES "nlopt") + set(_NLopt_LIB_NAMES "nlopt" "nloptd") find_library(NLopt_LIBS NAMES ${_NLopt_LIB_NAMES}) if(NOT NLopt_LIBS) diff --git a/cmake/presets/Linux.json b/cmake/presets/Linux.json new file mode 100644 index 00000000000..c9fbbafe2df --- /dev/null +++ b/cmake/presets/Linux.json @@ -0,0 +1,27 @@ +{ + "version": 4, + "configurePresets": [ + { + "name": "linux-base", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + }, + "generator": "Ninja" + } + ], + "buildPresets": [ + { + "name": "linux-base-build", + "targets": "all", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + } + ] +} \ No newline at end of file diff --git a/cmake/presets/Windows.json b/cmake/presets/Windows.json new file mode 100644 index 00000000000..28091fb465f --- /dev/null +++ b/cmake/presets/Windows.json @@ -0,0 +1,38 @@ +{ + "version": 4, + "configurePresets": [ + { + "name": "windows-base", + "hidden": true, + "generator": "Visual Studio 17 2022", + "architecture": "x64", + "vendor": { + "jetbrains.com/clion": { + "toolchain": "Visual Studio" + } + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "windows-base-2019", + "hidden": true, + "generator": "Visual Studio 16 2019" + } + ], + "buildPresets": [ + { + "name": "windows-base-build", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + }, + "targets": "ALL_BUILD" + } + ] +} \ No newline at end of file diff --git a/cmake/presets/base.json b/cmake/presets/base.json new file mode 100644 index 00000000000..25942574d92 --- /dev/null +++ b/cmake/presets/base.json @@ -0,0 +1,31 @@ +{ + "version": 4, + "configurePresets": [ + { + "name": "base-release", + "hidden": true, + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "base-relwithdebinfo", + "inherits": "base-release", + "hidden": true, + "binaryDir": "${sourceDir}/build-dbginfo", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "base-debug", + "inherits": "base-release", + "hidden": true, + "binaryDir": "${sourceDir}/build-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + } + ] +} \ No newline at end of file diff --git a/cmake/presets/macOS.json b/cmake/presets/macOS.json new file mode 100644 index 00000000000..9c397b99210 --- /dev/null +++ b/cmake/presets/macOS.json @@ -0,0 +1,48 @@ +{ + "version": 4, + "configurePresets": [ + { + "name": "macos-base", + "hidden": true, + "generator": "Xcode", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + }, + "cacheVariables": { + "CMAKE_MACOSX_BUNDLE": true, + "CMAKE_MACOSX_RPATH": true, + "CMAKE_OSX_DEPLOYMENT_TARGET": "10.15" + } + }, + { + "name": "macos-base-x64", + "inherits": "macos-base", + "hidden": true, + "cacheVariables": { + "CMAKE_OSX_ARCHITECTURES": "x86_64" + } + }, + { + "name": "macos-base-arm64", + "inherits": "macos-base", + "hidden": true, + "cacheVariables": { + "CMAKE_OSX_ARCHITECTURES": "arm64" + } + } + ], + "buildPresets": [ + { + "name": "macos-base-build", + "targets": "all", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + } + ] +} \ No newline at end of file diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 4bd3470d441..e562c52e90a 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -20,7 +20,16 @@ # therefore, unfortunatelly, the installation cannot be copied/moved elsewhere without re-installing wxWidgets. # -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.13) + +# Backward compatibility for old CMake versions +if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_VERSION VERSION_LESS "3.25") + set(LINUX ON CACHE BOOL "" FORCE) +endif () + +set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "") # Disable deprecation warnings from dependencies built using old CMake versions +set(CMAKE_INSTALL_MESSAGE "NEVER") # Disable printing "Installing" or "Up-to-date" when running the install step + if (APPLE) # if CMAKE_OSX_DEPLOYMENT_TARGET is not set, set it to 11.3 if (NOT CMAKE_OSX_DEPLOYMENT_TARGET) @@ -40,12 +49,48 @@ if (NPROC EQUAL 0) set(NPROC 1) endif () -set(DESTDIR "${CMAKE_CURRENT_BINARY_DIR}/destdir" CACHE PATH "Destination directory") -set(DEP_DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/../DL_CACHE CACHE PATH "Path for downloaded source packages.") +set(DEP_DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/DL_CACHE CACHE PATH "Path for downloaded source packages.") set(FLATPAK FALSE CACHE BOOL "Toggles various build settings for flatpak, like /usr/local in DESTDIR or not building wxwidgets") + + +if ("${DESTDIR}" STREQUAL "" OR "${DESTDIR}" STREQUAL "${AUTOGENERATED_DESTDIR}") + if (LINUX AND (NOT DEFINED USE_OLD_DESTDIR_PREV OR USE_OLD_DESTDIR_PREV) AND EXISTS "${CMAKE_BINARY_DIR}/destdir/usr/local" AND NOT EXISTS "${CMAKE_BINARY_DIR}/OrcaSlicer_dep/usr/local") + set(USE_OLD_DESTDIR TRUE) + endif () + if (NOT USE_OLD_DESTDIR AND USE_OLD_DESTDIR_PREV) + set(REGEN_DESTDIR TRUE) + endif () +else () + unset(AUTOGENERATED_DESTDIR CACHE) +endif () + +if ("${DESTDIR}" STREQUAL "" OR REGEN_DESTDIR) + if (USE_OLD_DESTDIR) # backward compatibility for old directory name + set(DESTDIR "${CMAKE_BINARY_DIR}/destdir" CACHE PATH "Path to dependencies" FORCE) + message(WARNING "You are using an old directory name for dependencies that is being deprecated. " + "Please rename \"destdir\" to \"OrcaSlicer_dep\" or remove the destdir directory and rebuild. " + "The current \"destdir\" directory will be used until then.") + else () + set(DESTDIR "${CMAKE_BINARY_DIR}/OrcaSlicer_dep") + if (APPLE) + set(DESTDIR "${DESTDIR}_${CMAKE_OSX_ARCHITECTURES}") + endif () + set(DESTDIR "${DESTDIR}" CACHE PATH "Path to dependencies install directory" FORCE) + endif () + message(STATUS "DESTDIR: ${DESTDIR} (generated automatically and saved to cache)") + set(AUTOGENERATED_DESTDIR ${DESTDIR} CACHE STRING "Provides the last autogenerated destdir" FORCE) + unset(REGEN_DESTDIR CACHE) +else () + message(STATUS "DESTDIR: ${DESTDIR} (from cache or command line)") +endif () + if (NOT FLATPAK) set(DESTDIR "${DESTDIR}/usr/local/") -endif() +endif () + +if (LINUX) + set(USE_OLD_DESTDIR_PREV ${USE_OLD_DESTDIR} CACHE STRING "Indicates if the old destdir was used during the previous configuration" FORCE) +endif () get_property(_is_multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) @@ -54,8 +99,11 @@ if (_is_multi) option(ORCA_INCLUDE_DEBUG_INFO "Includes debug information in a release build (like RelWithDebInfo) in a way that works with multi-configuration generators and incompatible dependencies. DEP_DEBUG option takes priority over this." OFF) endif () -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - option(DEP_WX_GTK3 "Build wxWidgets against GTK3" OFF) +if(LINUX) + option(DEP_WX_GTK3 "Build wxWidgets against GTK3" ON) + if(POLICY CMP0135) # DOWNLOAD_EXTRACT_TIMESTAMP + cmake_policy(SET CMP0135 OLD) + endif() else() if(POLICY CMP0135) # DOWNLOAD_EXTRACT_TIMESTAMP cmake_policy(SET CMP0135 NEW) @@ -67,9 +115,13 @@ set(IS_CROSS_COMPILE FALSE) if (APPLE) set(CMAKE_FIND_FRAMEWORK LAST) set(CMAKE_FIND_APPBUNDLE LAST) - list(FIND CMAKE_OSX_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR} _arch_idx) - message(STATUS "prusaslicer_add_cmake_project for Apple") - if (CMAKE_OSX_ARCHITECTURES AND _arch_idx LESS 0) + list(LENGTH CMAKE_OSX_ARCHITECTURES _arch_len) + if (_arch_len GREATER 1) + message(FATAL_ERROR "OrcaSlicer only supports building for one architecture at a time. Please make sure only one architecture is specified in CMAKE_OSX_ARCHITECTURES") + elseif (_arch_len EQUAL 1) + list(GET CMAKE_OSX_ARCHITECTURES 0 MACOS_ARCH) + endif () + if (NOT "${MACOS_ARCH}" STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR}) message(STATUS "prusaslicer_add_cmake_project for Apple crosscompiling") set(IS_CROSS_COMPILE TRUE) set(CMAKE_CXX_COMPILER_ID "Clang") @@ -77,6 +129,8 @@ if (APPLE) set(_cmake_osx_arch -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHS}) set(_cmake_args_osx_arch CMAKE_ARGS -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHS}) message(STATUS "Detect Cross-compilation. Will build for target ${CMAKE_OSX_ARCHS}" ) + else () + message(STATUS "prusaslicer_add_cmake_project for Apple") endif () endif () @@ -87,16 +141,17 @@ endif () # Slic3r compiles with a different version which will cause runtime errors. # option(DEP_BUILD_IGL_STATIC "Build IGL as a static library. Might cause link errors and increase binary size." OFF) -message(STATUS "OrcaSlicer deps DESTDIR: ${DESTDIR}") message(STATUS "OrcaSlicer dowload dir for source packages: ${DEP_DOWNLOAD_DIR}") -message(STATUS "OrcaSlicer deps debug build: ${DEP_DEBUG}") +if (_is_multi) + message(STATUS "OrcaSlicer deps debug build: ${DEP_DEBUG}") +endif () find_package(Git REQUIRED) # The default command line for patching. Only works for newer set(PATCH_CMD ${GIT_EXECUTABLE} apply --verbose --ignore-space-change --whitespace=fix) -if (NOT _is_multi AND NOT CMAKE_BUILD_TYPE) +if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) message(STATUS "Forcing CMAKE_BUILD_TYPE to Release as it was not specified.") endif () @@ -120,7 +175,7 @@ function(orcaslicer_add_cmake_project projectname) set(_build_j "/m") endif () -if (NOT IS_CROSS_COMPILE OR NOT APPLE) +if (APPLE AND IS_CROSS_COMPILE) ExternalProject_Add( dep_${projectname} EXCLUDE_FROM_ALL ON @@ -129,34 +184,25 @@ if (NOT IS_CROSS_COMPILE OR NOT APPLE) ${_gen} CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR} - -DCMAKE_MODULE_PATH:STRING=${PROJECT_SOURCE_DIR}/../cmake/modules -DCMAKE_PREFIX_PATH:STRING=${DESTDIR} - -DCMAKE_DEBUG_POSTFIX:STRING=d - -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} - -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} - -DCMAKE_TOOLCHAIN_FILE:STRING=${CMAKE_TOOLCHAIN_FILE} -DBUILD_SHARED_LIBS:BOOL=OFF + -DCMAKE_INSTALL_MESSAGE:STRING=${CMAKE_INSTALL_MESSAGE} ${_cmake_osx_arch} "${_configs_line}" ${DEP_CMAKE_OPTS} ${P_ARGS_CMAKE_ARGS} ${P_ARGS_UNPARSED_ARGUMENTS} BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release -- ${_build_j} - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config Release + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config Release ) -elseif(FLATPAK) - # the only reason this is here is because of the HACK at the bottom for ci - # - # note for future devs: shared libs may actually create a size reduction - # but orcaslicer_deps tends to get really funny regarding linking after that (notably boost) - # so, as much as I would like to use that, it's not happening +else () # Windows, Linux, and non-crosscompiled macOS ExternalProject_Add( - dep_${projectname} - EXCLUDE_FROM_ALL ON - INSTALL_DIR ${DESTDIR} - DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/${projectname} - ${_gen} - CMAKE_ARGS + dep_${projectname} + EXCLUDE_FROM_ALL ON + INSTALL_DIR ${DESTDIR} + DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/${projectname} + ${_gen} + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR} -DCMAKE_MODULE_PATH:STRING=${PROJECT_SOURCE_DIR}/../cmake/modules -DCMAKE_PREFIX_PATH:STRING=${DESTDIR} @@ -165,38 +211,35 @@ elseif(FLATPAK) -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} -DCMAKE_TOOLCHAIN_FILE:STRING=${CMAKE_TOOLCHAIN_FILE} -DBUILD_SHARED_LIBS:BOOL=OFF + -DCMAKE_INSTALL_MESSAGE:STRING=${CMAKE_INSTALL_MESSAGE} ${_cmake_osx_arch} "${_configs_line}" ${DEP_CMAKE_OPTS} ${P_ARGS_CMAKE_ARGS} - ${P_ARGS_UNPARSED_ARGUMENTS} - BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release -- ${_build_j} - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config Release - # HACK: save space after each compile job, because CI - # reasoning: cmake changes directory after this command, so just keep only the folders - # so that it can navigate out - COMMAND find "${CMAKE_BINARY_DIR}/dep_${projectname}-prefix/" -type f -delete - ) -else() - ExternalProject_Add( - dep_${projectname} - EXCLUDE_FROM_ALL ON - INSTALL_DIR ${DESTDIR} - DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/${projectname} - ${_gen} - CMAKE_ARGS - -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR} - -DCMAKE_PREFIX_PATH:STRING=${DESTDIR} - -DBUILD_SHARED_LIBS:BOOL=OFF - ${_cmake_osx_arch} - "${_configs_line}" - ${DEP_CMAKE_OPTS} - ${P_ARGS_CMAKE_ARGS} - ${P_ARGS_UNPARSED_ARGUMENTS} - BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release -- ${_build_j} - INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config Release + ${P_ARGS_UNPARSED_ARGUMENTS} + BUILD_COMMAND ${CMAKE_COMMAND} --build . --config Release -- ${_build_j} + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config Release ) + # note for future devs: shared libs may actually create a size reduction + # but orcaslicer_deps tends to get really funny regarding linking after that (notably boost) + # so, as much as I would like to use that, it's not happening + + # Free up space during flatpak builds to prevent running out of space during CI/CD + if (FLATPAK) + ExternalProject_Add_Step(dep_${projectname} free_download_space + DEPENDEES download # do after download + COMMENT "Freeing Space: Removing source archive" + WORKING_DIRECTORY ${DEP_DOWNLOAD_DIR} + COMMAND ${CMAKE_COMMAND} -E rm -r ${projectname} + ) + ExternalProject_Add_Step(dep_${projectname} free_build_space + DEPENDEES install # do after install + COMMENT "Freeing Space: Removing source and build files" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/dep_${projectname}-prefix/src + COMMAND ${CMAKE_COMMAND} -E rm -rf dep_${projectname} dep_${projectname}-build + ) + endif () endif() endfunction(orcaslicer_add_cmake_project) diff --git a/deps/CURL/CURL.cmake b/deps/CURL/CURL.cmake index a5ae1b9d00c..8facc41e845 100644 --- a/deps/CURL/CURL.cmake +++ b/deps/CURL/CURL.cmake @@ -37,7 +37,7 @@ elseif (APPLE) -DCURL_CA_PATH:STRING=none ) -elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") +elseif(LINUX) set(_curl_platform_flags ${_curl_platform_flags} diff --git a/deps/FREETYPE/FREETYPE.cmake b/deps/FREETYPE/FREETYPE.cmake index f30671ff2c3..783dbc73fcd 100644 --- a/deps/FREETYPE/FREETYPE.cmake +++ b/deps/FREETYPE/FREETYPE.cmake @@ -4,7 +4,7 @@ else() set(library_build_shared "0") endif() -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(LINUX) set(_ft_disable_zlib "-D FT_DISABLE_ZLIB=FALSE") else() set(_ft_disable_zlib "-D FT_DISABLE_ZLIB=TRUE") diff --git a/deps/GLFW/GLFW.cmake b/deps/GLFW/GLFW.cmake index 81967910339..d4111e1dd71 100644 --- a/deps/GLFW/GLFW.cmake +++ b/deps/GLFW/GLFW.cmake @@ -6,7 +6,7 @@ else() set(_build_static ON) endif() -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(LINUX) set(_glfw_use_wayland "-DGLFW_USE_WAYLAND=ON") else() set(_glfw_use_wayland "-DGLFW_USE_WAYLAND=FF") diff --git a/deps/GMP/GMP.cmake b/deps/GMP/GMP.cmake index 4f79a657316..4a1ae00f6ee 100644 --- a/deps/GMP/GMP.cmake +++ b/deps/GMP/GMP.cmake @@ -2,8 +2,8 @@ set(_srcdir ${CMAKE_CURRENT_LIST_DIR}/gmp) if (MSVC) - set(_output ${DESTDIR}/include/gmp.h - ${DESTDIR}/lib/libgmp-10.lib + set(_output ${DESTDIR}/include/gmp.h + ${DESTDIR}/lib/libgmp-10.lib ${DESTDIR}/bin/libgmp-10.dll) add_custom_command( @@ -39,7 +39,7 @@ else () set(_gmp_ccflags "${_gmp_ccflags} -mmacosx-version-min=${DEP_OSX_TARGET}") set(_gmp_build_tgt "--build=${_gmp_build_arch}-apple-darwin") endif() - elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + elseif(LINUX) if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") set(_gmp_ccflags "${_gmp_ccflags} -march=armv7-a") # Works on RPi-4 set(_gmp_build_tgt armv7) @@ -59,9 +59,9 @@ else () URL https://github.com/SoftFever/OrcaSlicer_deps/releases/download/gmp-6.2.1/gmp-6.2.1.tar.bz2 URL_HASH SHA256=eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/GMP - 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}" ${_gmp_build_tgt} - BUILD_COMMAND make -j - INSTALL_COMMAND make install + BUILD_IN_SOURCE ON + CONFIGURE_COMMAND env "CFLAGS=${_gmp_ccflags}" "CXXFLAGS=${_gmp_ccflags}" "LIBTOOLFLAGS=--silent" ./configure ${_cross_compile_arg} --enable-shared=no --enable-cxx=yes --enable-static=yes --enable-silent-rules "--prefix=${DESTDIR}" ${_gmp_build_tgt} + BUILD_COMMAND make -j -s + INSTALL_COMMAND make -s install ) endif () diff --git a/deps/JPEG/JPEG.cmake b/deps/JPEG/JPEG.cmake index 82b0ca5565f..29aa8d3fed9 100644 --- a/deps/JPEG/JPEG.cmake +++ b/deps/JPEG/JPEG.cmake @@ -1,4 +1,4 @@ -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(LINUX) if (JPEG_VERSION STREQUAL "6") message("Using Jpeg Lib 62") set(jpeg_flag "") diff --git a/deps/MPFR/MPFR.cmake b/deps/MPFR/MPFR.cmake index 1161a1ca6e9..453dc32fa64 100644 --- a/deps/MPFR/MPFR.cmake +++ b/deps/MPFR/MPFR.cmake @@ -3,7 +3,7 @@ set(_srcdir ${CMAKE_CURRENT_LIST_DIR}/mpfr) if (MSVC) set(_output ${DESTDIR}/include/mpfr.h ${DESTDIR}/include/mpf2mpfr.h - ${DESTDIR}/lib/libmpfr-4.lib + ${DESTDIR}/lib/libmpfr-4.lib ${DESTDIR}/bin/libmpfr-4.dll) add_custom_command( @@ -29,10 +29,10 @@ else () URL_HASH SHA256=b9df93635b20e4089c29623b19420c4ac848a1b29df1cfd59f26cab0d2666aa0 DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/MPFR BUILD_IN_SOURCE ON - CONFIGURE_COMMAND autoreconf -f -i && - env "CFLAGS=${_gmp_ccflags}" "CXXFLAGS=${_gmp_ccflags}" ./configure ${_cross_compile_arg} --prefix=${DESTDIR} --enable-shared=no --enable-static=yes --with-gmp=${DESTDIR} ${_gmp_build_tgt} - BUILD_COMMAND make -j - INSTALL_COMMAND make install + CONFIGURE_COMMAND autoreconf -f -i && + env "CFLAGS=${_gmp_ccflags}" "CXXFLAGS=${_gmp_ccflags}" ./configure ${_cross_compile_arg} --prefix=${DESTDIR} --enable-shared=no --enable-static=yes --enable-silent-rules --with-gmp=${DESTDIR} ${_gmp_build_tgt} + BUILD_COMMAND make -j -s + INSTALL_COMMAND make -s install DEPENDS dep_GMP ) endif () diff --git a/deps/OpenEXR/OpenEXR.cmake b/deps/OpenEXR/OpenEXR.cmake index dd754d3a383..28d474c8974 100644 --- a/deps/OpenEXR/OpenEXR.cmake +++ b/deps/OpenEXR/OpenEXR.cmake @@ -11,12 +11,9 @@ if (APPLE AND IS_CROSS_COMPILE) set(_openexr_arch ${CMAKE_OSX_ARCHITECTURES}) set(_cmake_openexr_arch -DCMAKE_OSX_ARCHITECTURES:STRING=${_openexr_arch}) endif() - ExternalProject_Add(dep_OpenEXR - EXCLUDE_FROM_ALL ON + orcaslicer_add_cmake_project(OpenEXR URL https://github.com/AcademySoftwareFoundation/openexr/archive/refs/tags/v2.5.5.zip URL_HASH SHA256=0307a3d7e1fa1e77e9d84d7e9a8694583fbbbfd50bdc6884e2c96b8ef6b902de - INSTALL_DIR ${DESTDIR} - DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/OpenEXR ${_openxr_list_sep} CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR} @@ -30,7 +27,7 @@ if (APPLE AND IS_CROSS_COMPILE) ) else() -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +if (LINUX) set(_patch_cmd ${PATCH_CMD} ${CMAKE_CURRENT_LIST_DIR}/0001-OpenEXR-GCC13.patch) else () set(_patch_cmd "") diff --git a/deps/OpenSSL/OpenSSL.cmake b/deps/OpenSSL/OpenSSL.cmake index 45f82ec5890..f458864749f 100644 --- a/deps/OpenSSL/OpenSSL.cmake +++ b/deps/OpenSSL/OpenSSL.cmake @@ -8,15 +8,15 @@ else() if(WIN32) set(_cross_arch "VC-WIN64A") elseif(APPLE) - set(_cross_arch "darwin64-arm64-cc") + set(_cross_arch "darwin64-${MACOS_ARCH}-cc") endif() endif() if(WIN32) set(_conf_cmd perl Configure ) set(_cross_comp_prefix_line "") - set(_make_cmd nmake) - set(_install_cmd nmake install_sw ) + set(_make_cmd nmake /S) + set(_install_cmd nmake /S install_sw) else() if(APPLE) set(_conf_cmd export MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} && ./Configure -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}) @@ -24,8 +24,8 @@ else() set(_conf_cmd "./config") endif() set(_cross_comp_prefix_line "") - set(_make_cmd make -j${NPROC}) - set(_install_cmd make -j${NPROC} install_sw) + set(_make_cmd make -j${NPROC} -s) + set(_install_cmd make -j${NPROC} -s install_sw) if (CMAKE_CROSSCOMPILING) set(_cross_comp_prefix_line "--cross-compile-prefix=${TOOLCHAIN_PREFIX}-") diff --git a/deps/TIFF/TIFF.cmake b/deps/TIFF/TIFF.cmake index 01d72428b97..76e00d3b684 100644 --- a/deps/TIFF/TIFF.cmake +++ b/deps/TIFF/TIFF.cmake @@ -1,23 +1,18 @@ find_package(OpenGL QUIET REQUIRED) if (APPLE) - message(STATUS "Compiling TIFF for macos ${CMAKE_SYSTEM_VERSION}.") - orcaslicer_add_cmake_project(TIFF - URL https://gitlab.com/libtiff/libtiff/-/archive/v4.3.0/libtiff-v4.3.0.zip - URL_HASH SHA256=4fca1b582c88319f3ad6ecd5b46320eadaf5eb4ef6f6c32d44caaae4a03d0726 - DEPENDS ${ZLIB_PKG} ${PNG_PKG} dep_JPEG - CMAKE_ARGS - -Dlzma:BOOL=OFF - -Dwebp:BOOL=OFF - -Djbig:BOOL=OFF - -Dzstd:BOOL=OFF - -Dlibdeflate:BOOL=OFF - -Dpixarlog:BOOL=OFF - ) -else() - orcaslicer_add_cmake_project(TIFF - URL https://gitlab.com/libtiff/libtiff/-/archive/v4.1.0/libtiff-v4.1.0.zip - URL_HASH SHA256=c56edfacef0a60c0de3e6489194fcb2f24c03dbb550a8a7de5938642d045bd32 + set(URL "https://gitlab.com/libtiff/libtiff/-/archive/v4.3.0/libtiff-v4.3.0.zip") + set(HASH "SHA256=4fca1b582c88319f3ad6ecd5b46320eadaf5eb4ef6f6c32d44caaae4a03d0726") + set(_extra_args -Dlibdeflate:BOOL=OFF) +else () + set(URL "https://gitlab.com/libtiff/libtiff/-/archive/v4.1.0/libtiff-v4.1.0.zip") + set(HASH "SHA256=c56edfacef0a60c0de3e6489194fcb2f24c03dbb550a8a7de5938642d045bd32") + unset(_extra_args) +endif () + +orcaslicer_add_cmake_project(TIFF + URL ${URL} + URL_HASH ${HASH} DEPENDS ${ZLIB_PKG} ${PNG_PKG} dep_JPEG CMAKE_ARGS -Dlzma:BOOL=OFF @@ -25,9 +20,8 @@ else() -Djbig:BOOL=OFF -Dzstd:BOOL=OFF -Dpixarlog:BOOL=OFF + ${_extra_args} ) -endif() - diff --git a/deps/autobuild.cmake b/deps/autobuild.cmake new file mode 100644 index 00000000000..fc6876ddde1 --- /dev/null +++ b/deps/autobuild.cmake @@ -0,0 +1,147 @@ +if (CLEAN_DEPS) + message(STATUS "Cleaning dependencies and rebuilding") + file(REMOVE_RECURSE ${DEP_BUILD_DIR}) +elseif (FORCE_DEPS) + message(STATUS "Forcing rebuild of dependencies") + set(_needs_build TRUE) +endif () + +find_package(Git REQUIRED QUIET) + +# if there is already info about the last build, read it +if (EXISTS ${DEP_BUILD_DIR}/DEPS_BUILD_INFO.info) + file(STRINGS ${DEP_BUILD_DIR}/DEPS_BUILD_INFO.info HASH_LIST) + if (HASH_LIST) + list(GET HASH_LIST 1 _parsed_last_commit) + list(GET HASH_LIST 2 _parsed_last_uncommitted_md5) + endif () +else () + message(STATUS "No previous build info found") +endif () + +# get the diff of the dependencies folder +execute_process( + COMMAND ${GIT_EXECUTABLE} --no-pager diff -w deps + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE _cmd_deps_diff + RESULT_VARIABLE _cmd_deps_diff_res +) + +# get the hash of the last commit to the dependencies folder +execute_process( + COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%H deps + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE _cmd_last_commit + RESULT_VARIABLE _cmd_last_commit_res +) + +# check for errors while running the commands +if (NOT _cmd_deps_diff_res EQUAL 0) + message(FATAL_ERROR "Failed to get status for deps") +elseif (NOT _cmd_last_commit_res EQUAL 0) + message(FATAL_ERROR "Failed to get last commit date for deps") +endif () + +# check the results and determine if a build is needed +if (NOT _parsed_last_commit STREQUAL _cmd_last_commit) + message(STATUS "Last commit for deps has changed") + set(_needs_build TRUE) +endif () +if (NOT _cmd_deps_diff STREQUAL "") + string(MD5 _deps_diff_md5 "${_cmd_deps_diff}") + if (NOT _parsed_last_uncommitted_md5 STREQUAL _deps_diff_md5) + message(STATUS "Uncommitted changes made to deps folder") + set(_needs_build TRUE) + endif () +endif () + +if (_needs_build) + message(STATUS "Dependencies have been updated. Rebuilding") +elseif (NOT EXISTS ${DEP_BUILD_DIR}) + if (NOT CLEAN_DEPS) + message(STATUS "Build directory for dependencies does not exist. Rebuilding") + endif () +else () + message(STATUS "Dependencies are up to date. Skipping build") + return() +endif () + +set (_output_quiet "") +if (BUILD_DEPS_QUIET) + set (_output_quiet OUTPUT_QUIET) +endif () + +set(_gen_arg "") +if (CMAKE_GENERATOR) + set (_gen_arg "-G${CMAKE_GENERATOR}") +endif () + +set(_configure_args "") + +if (CMAKE_C_COMPILER) + list(APPEND _configure_args "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}") +endif () + +if (CMAKE_CXX_COMPILER) + list(APPEND _configure_args "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}") +endif () + +if (CMAKE_TOOLCHAIN_FILE) + list(APPEND _configure_args "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") +endif () + +# Generic args +list(APPEND _configure_args "-DDESTDIR=${DEP_DESTDIR}" "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}") + +if (APPLE) + list(APPEND _configure_args "-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}" + "-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}" + "-DOPENSSL_ARCH=darwin64-${CMAKE_OSX_ARCHITECTURES}-cc" + ) +elseif (WIN32) + list(APPEND _configure_args "-A x64") + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + list(APPEND _configure_args "-DDEP_DEBUG=ON") + elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + list(APPEND _configure_args "-DORCA_INCLUDE_DEBUG_INFO=ON") + endif () +elseif (LINUX) + if(NOT SLIC3R_GTK EQUAL "3") + list(APPEND _configure_args "-DDEP_WX_GTK3=OFF") + endif() +endif () + +message(STATUS "Configuring dependencies with the following command: ${CMAKE_COMMAND} ${_gen_arg} -B ${DEP_BUILD_DIR} ${_configure_args}") + +execute_process( + COMMAND ${CMAKE_COMMAND} "${_gen_arg}" -B ${DEP_BUILD_DIR} ${_configure_args} + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + ${_output_quiet} + ERROR_VARIABLE _deps_configure_output + RESULT_VARIABLE _deps_configure_result +) + +if (_deps_configure_result EQUAL 0) + message(STATUS "Building dependencies with the following command: ${CMAKE_COMMAND} --build . --target deps --config ${CMAKE_BUILD_TYPE} -- ${_compiler_args}") + execute_process( + COMMAND ${CMAKE_COMMAND} --build . --target deps --config ${CMAKE_BUILD_TYPE} -- ${_compiler_args} + WORKING_DIRECTORY ${DEP_BUILD_DIR} + ${_output_quiet} + ERROR_VARIABLE _deps_build_output + RESULT_VARIABLE _deps_build_result + ) + if (NOT _deps_build_result EQUAL 0) + message(FATAL_ERROR "Dependency build failed with output:\n${_deps_build_output}") + else () + message(STATUS "Dependencies built successfully") + endif () +else () + message(FATAL_ERROR "Dependency configure failed with output:\n${_deps_configure_output}") +endif () + +# write current commit info to file +message(STATUS "Writing deps build status to ${DEP_BUILD_DIR}/DEPS_BUILD_INFO.info") +file(WRITE ${DEP_BUILD_DIR}/DEPS_BUILD_INFO.info + "This file is used to determine if dependencies need to be rebuilt. Do not edit\n" + "${_cmd_last_commit}\n" + "${_deps_diff_md5}\n") \ No newline at end of file diff --git a/deps/wxWidgets/wxWidgets.cmake b/deps/wxWidgets/wxWidgets.cmake index 1097e6cfc0f..d92fa880390 100644 --- a/deps/wxWidgets/wxWidgets.cmake +++ b/deps/wxWidgets/wxWidgets.cmake @@ -1,7 +1,7 @@ set(_wx_toolkit "") set(_wx_private_font "-DwxUSE_PRIVATE_FONTS=1") -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") +if(LINUX) set(_gtk_ver 2) if (DEP_WX_GTK3) diff --git a/linux.d/arch b/linux.d/arch index bae4c06e993..2be1e19f209 100644 --- a/linux.d/arch +++ b/linux.d/arch @@ -1,3 +1,4 @@ +#!/bin/bash # these are the Arch Linux specific build functions FOUND_GTK3=$(pacman -Q gtk3) diff --git a/linux.d/clear-linux-os b/linux.d/clear-linux-os index 9453ddcce59..5ef8ba3516c 100644 --- a/linux.d/clear-linux-os +++ b/linux.d/clear-linux-os @@ -1,3 +1,4 @@ +#!/bin/bash # these are the Clear Linux specific build functions FOUND_GTK3=$(ls /usr/lib64/libgtk-3.so.* 2>/dev/null | tail -n 1 || true) diff --git a/linux.d/debian b/linux.d/debian index 796f2ab1005..71a7f6c9896 100644 --- a/linux.d/debian +++ b/linux.d/debian @@ -1,3 +1,4 @@ +#!/bin/bash FOUND_GTK3=$(dpkg -l libgtk* | grep gtk-3) REQUIRED_DEV_PACKAGES=( diff --git a/linux.d/fedora b/linux.d/fedora index 3a34072891e..9a83a400c0d 100644 --- a/linux.d/fedora +++ b/linux.d/fedora @@ -1,3 +1,4 @@ +#!/bin/bash FOUND_GTK3=$(rpm -qa | grep -P '^gtk3' || true) REQUIRED_DEV_PACKAGES=( diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8133c2b06a3..6300ec7df58 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,7 +41,7 @@ if (SLIC3R_GUI) endif() endif() - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + if (LINUX) set (wxWidgets_CONFIG_OPTIONS "--toolkit=gtk${SLIC3R_GTK}") if (SLIC3R_WX_STABLE) find_package(wxWidgets 3.0 REQUIRED COMPONENTS base core adv html gl aui net media webview) diff --git a/src/hidapi/CMakeLists.txt b/src/hidapi/CMakeLists.txt index f3045466e1c..5a0f703b167 100644 --- a/src/hidapi/CMakeLists.txt +++ b/src/hidapi/CMakeLists.txt @@ -12,7 +12,7 @@ include_directories(include) add_library(hidapi STATIC ${HIDAPI_IMPL}) -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +if (LINUX) # Don't link the udev library, as there are two versions out there (libudev.so.0, libudev.so.1), so they are linked explicitely. # target_link_libraries(hidapi udev) target_link_libraries(hidapi dl) diff --git a/src/minilzo/CMakeLists.txt b/src/minilzo/CMakeLists.txt index d23e8714723..cdf4118bdcd 100644 --- a/src/minilzo/CMakeLists.txt +++ b/src/minilzo/CMakeLists.txt @@ -10,7 +10,7 @@ add_library(minilzo_static STATIC lzoconf.h ) -if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU") +if(GNU_C) target_compile_definitions(minilzo_static PRIVATE _GNU_SOURCE) endif() diff --git a/src/miniz/CMakeLists.txt b/src/miniz/CMakeLists.txt index 04d562b764e..cebc092301c 100644 --- a/src/miniz/CMakeLists.txt +++ b/src/miniz/CMakeLists.txt @@ -8,7 +8,7 @@ add_library(miniz_static STATIC miniz.h ) -if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU") +if(GNU_C) target_compile_definitions(miniz_static PRIVATE _GNU_SOURCE) endif() diff --git a/src/platform/unix/BuildLinuxImage.sh.in b/src/platform/unix/BuildLinuxImage.sh.in index 96cf25bc141..d0fc5e92f95 100644 --- a/src/platform/unix/BuildLinuxImage.sh.in +++ b/src/platform/unix/BuildLinuxImage.sh.in @@ -1,7 +1,6 @@ #!/bin/bash export ROOT=$(echo $ROOT | grep . || pwd) -export NCORES=`nproc --all` while getopts ":ih" opt; do case ${opt} in @@ -12,28 +11,27 @@ while getopts ":ih" opt; do echo " -i: Generate Appimage (optional)" exit 0 ;; + * ) + ;; esac done -echo -n "[9/9] Generating Linux app..." -#{ - # create directory and copy into it - if [ -d "package" ] - then - rm -rf package/* - rm -rf package/.* 2&>/dev/null - else - mkdir package - fi - mkdir package/bin +echo "Generating Linux app data..." +# create directory and copy into it +if [ -d "package" ] +then + rm -rf package/* + rm -rf package/.* 2&>/dev/null +else + mkdir package +fi +mkdir package/bin - # copy Resources - cp -Rf ../resources package/resources - cp -f src/@SLIC3R_APP_CMD@ package/bin/@SLIC3R_APP_CMD@ - # remove unneeded po from resources - ## find package/resources/localization -name "*.po" -type f -delete ## FIXME: DD - do we need this? +# copy Resources +cp -Rf ../resources package/resources +cp -f src/@SLIC3R_APP_CMD@ package/bin/@SLIC3R_APP_CMD@ - # create bin +# create bin cat << EOF >@SLIC3R_APP_CMD@ #!/bin/bash DIR=\$(readlink -f "\$0" | xargs dirname) @@ -46,17 +44,15 @@ export LC_ALL=C exec "\$DIR/bin/@SLIC3R_APP_CMD@" "\$@" EOF - chmod ug+x @SLIC3R_APP_CMD@ - cp -f @SLIC3R_APP_CMD@ package/@SLIC3R_APP_CMD@ - pushd package +chmod ug+x @SLIC3R_APP_CMD@ +cp -f @SLIC3R_APP_CMD@ package/@SLIC3R_APP_CMD@ +pushd package tar -cvf ../@SLIC3R_APP_KEY@.tar . &>/dev/null - popd -#} &> $ROOT/Build.log # Capture all command output -echo "done" +popd if [[ -n "$BUILD_IMAGE" ]] then -echo -n "Creating Appimage for distribution..." +echo "Creating Appimage for distribution..." #{ pushd package chmod +x ../build_appimage.sh @@ -64,5 +60,4 @@ echo -n "Creating Appimage for distribution..." popd mv package/"@SLIC3R_APP_KEY@_Linux_V@SoftFever_VERSION@.AppImage" "@SLIC3R_APP_KEY@_Linux_V@SoftFever_VERSION@.AppImage" #} &> $ROOT/Build.log # Capture all command output -echo "done" fi diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 87d93965784..436cf5b2083 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -616,7 +616,7 @@ target_link_libraries(libslic3r_gui libslic3r cereal::cereal imgui imguizmo mini if (MSVC) target_link_libraries(libslic3r_gui Setupapi.lib) -elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") +elseif (LINUX) FIND_LIBRARY(WAYLAND_SERVER_LIBRARIES NAMES wayland-server) FIND_LIBRARY(WAYLAND_EGL_LIBRARIES NAMES wayland-egl) FIND_LIBRARY(WAYLAND_CLIENT_LIBRARIES NAMES wayland-client) diff --git a/version.inc b/version.inc index 41bac127ee7..3b015d30012 100644 --- a/version.inc +++ b/version.inc @@ -4,12 +4,6 @@ set(SLIC3R_APP_NAME "OrcaSlicer") set(SLIC3R_APP_KEY "OrcaSlicer") -if(NOT DEFINED BBL_RELEASE_TO_PUBLIC) -set(BBL_RELEASE_TO_PUBLIC "1") -endif() -if(NOT DEFINED BBL_INTERNAL_TESTING) -set(BBL_INTERNAL_TESTING "0") -endif() set(SoftFever_VERSION "2.2.0-beta") string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" SoftFever_VERSION_MATCH ${SoftFever_VERSION})