From 19314922bff54bfcf6312055d4e93420978b0e8d Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 4 Mar 2022 16:49:49 +0100 Subject: [PATCH 01/24] Use StandardProjectSettings These allow for a uniform way of handling rpath, threads etc. Contributes to CURA-8640 --- CMakeLists.txt | 27 +- cmake/SIPMacros.cmake | 16 +- cmake/StandardProjectSettings.cmake | 367 ++++++++++++++++++++++++++++ 3 files changed, 393 insertions(+), 17 deletions(-) create mode 100644 cmake/StandardProjectSettings.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 428de5f..b8dc3dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,13 @@ -# Copyright (c) 2020 Ultimaker B.V. +# Copyright (c) 2022 Ultimaker B.V. # pynest2d is released under the terms of the LGPLv3 or higher. project(pynest2d) cmake_minimum_required(VERSION 3.18) # Lowest version it's been tested with. +include(cmake/StandardProjectSettings.cmake) +AssureOutOfSourceBuilds() list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - if(NOT DEFINED Python_VERSION) set(Python_VERSION 3.10 @@ -25,6 +25,15 @@ find_package(SIP REQUIRED 6.5.0) find_package(libnest2d REQUIRED) # The library we're creating bindings for. add_library(pynest2d INTERFACE) +set_project_standards(pynest2d) +use_threads(pynest2d) +set_rpath(TARGETS + pynest2d + PATHS + "$<$:usr/bin>" + "$<$:usr/bin/lib>" + "$<$:../lib>" + RELATIVE) target_include_directories(pynest2d INTERFACE @@ -32,20 +41,8 @@ target_include_directories(pynest2d $ ) -# Use C++17 Standard -message(STATUS "Setting C++17 support with extensions off and standard required") -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD_REQUIRED ON) target_compile_features(pynest2d INTERFACE cxx_std_17) -if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") - if (APPLE) - message(STATUS "Compiling ${project_name} against libc++") - target_compile_options(pynest2d INTERFACE "-stdlib=libc++") - endif() -endif() - find_package(Threads) find_package(clipper) find_package(NLopt) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 912c839..e36d080 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -50,8 +50,8 @@ function(add_sip_module MODULE_TARGET) # create the target library and link all the files (generated and user specified message(STATUS "SIP: Linking the interface target against the shared library") set(sip_sources "${sip_c}" "${sip_cpp}") - if(usr_src) - list(sip_sources APPEND "${usr_src}") + if(${usr_src}) + list(APPEND sip_sources "${usr_src}") endif() add_library("sip_${MODULE_TARGET}" SHARED ${sip_sources}) @@ -61,6 +61,18 @@ function(add_sip_module MODULE_TARGET) set_target_properties("sip_${MODULE_TARGET}" PROPERTIES SUFFIX ${ext}) set_target_properties("sip_${MODULE_TARGET}" PROPERTIES OUTPUT_NAME "${MODULE_TARGET}") + # Make sure all rpaths are set from the INTERFACE target + get_target_property(_SKIP_BUILD_RPATH ${MODULE_TARGET} SKIP_BUILD_RPATH) + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES SKIP_BUILD_RPATH "${_SKIP_BUILD_RPATH}") + get_target_property(_BUILD_WITH_INSTALL_RPATH ${MODULE_TARGET} BUILD_WITH_INSTALL_RPATH) + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES BUILD_WITH_INSTALL_RPATH "${_BUILD_WITH_INSTALL_RPATH}") + get_target_property(_INSTALL_RPATH_USE_LINK_PATH ${MODULE_TARGET} INSTALL_RPATH_USE_LINK_PATH) + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES INSTALL_RPATH_USE_LINK_PATH "${_INSTALL_RPATH_USE_LINK_PATH}") + get_target_property(_MACOSX_RPATH ${MODULE_TARGET} MACOSX_RPATH) + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES MACOSX_RPATH "${_MACOSX_RPATH}") + get_target_property(_INSTALL_RPATH ${MODULE_TARGET} INSTALL_RPATH) + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES INSTALL_RPATH "${_INSTALL_RPATH}") + # Add the custom command to (re-)generate the files and mark them as dirty. This allows the user to actually work # on the sip definition files without having to reconfigure the complete project. add_custom_command( diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake new file mode 100644 index 0000000..cca13d9 --- /dev/null +++ b/cmake/StandardProjectSettings.cmake @@ -0,0 +1,367 @@ +include(GNUInstallDirs) # Standard install dirs + +# Uniform how we define BUILD_STATIC or BUILD_SHARED_LIBS (common practice) +if(DEFINED BUILD_STATIC) + if(DEFINED BUILD_SHARED_LIBS) + if(${BUILD_SHARED_LIBS} AND ${BUILD_STATIC}) + message(FATAL_ERROR "Conflicting arguments for BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} and BUILD_STATIC=${BUILD_STATIC}") + endif() + else() + set(BUILD_SHARED_LIBS NOT ${BUILD_STATIC}) + endif() +else() + if(NOT DEFINED BUILD_SHARED_LIBS) + set(BUILD_SHARED_LIBS ON) + endif() +endif() +message(STATUS "Setting BUILD_SHARED_LIBS to ${BUILD_SHARED_LIBS}") + +# Set a default build type if none was specified +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE + Release + CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui, ccmake + set_property( + CACHE CMAKE_BUILD_TYPE + PROPERTY STRINGS + "Debug" + "Release" + "MinSizeRel" + "RelWithDebInfo") +endif() + +# Generate compile_commands.json to make it easier to work with clang based tools +message(STATUS "Generating compile commands to ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +option(ENABLE_IPO "Enable Interprocedural Optimization, aka Link Time Optimization (LTO)" ON) +if(ENABLE_IPO) + include(CheckIPOSupported) + check_ipo_supported( + RESULT + result + OUTPUT + output) + if(result) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) + else() + message(SEND_ERROR "IPO is not supported: ${output}") + endif() +endif() + +if (NOT MSVC) + # Compile with the -fPIC options if supported + if(DEFINED POSITION_INDEPENDENT_CODE) # Use the user/Conan set value + message(STATUS "Using POSITION_INDEPENDENT_CODE: ${POSITION_INDEPENDENT_CODE}") + else() + set(POSITION_INDEPENDENT_CODE ON) # Defaults to on + message(STATUS "Setting POSITION_INDEPENDENT_CODE: ${POSITION_INDEPENDENT_CODE}") + endif() +else() + # Set Visual Studio flags MD/MDd or MT/MTd + if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY) + if(BUILD_STATIC OR NOT BUILD_SHARED_LIBS) + message(STATUS "Setting MT/MTd flags") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + else() + message(STATUS "Setting MD/MDd flags") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + endif() + endif() +endif() + +# Use C++17 Standard +message(STATUS "Setting C++17 support with extensions off and standard required") +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Set common project options for the target +function(set_project_standards project_name) + get_target_property(type ${project_name} TYPE) + if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + option(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF) + if(ENABLE_BUILD_WITH_TIME_TRACE) + message(STATUS "Enabling time tracing for ${project_name}") + if (${type} STREQUAL "INTERFACE_LIBRARY") + add_compile_definitions(${project_name} INTERFACE -ftime-trace) + else() + add_compile_definitions(${project_name} PRIVATE -ftime-trace) + endif() + endif() + if (APPLE) + message(STATUS "Compiling ${project_name} against libc++") + if (${type} STREQUAL "INTERFACE_LIBRARY") + target_compile_options(${project_name} INTERFACE "-stdlib=libc++") + else() + target_compile_options(${project_name} PRIVATE "-stdlib=libc++") + endif() + endif() + endif() +endfunction() + +function(set_rpath) + # Sets the RPATHS for targets (Linux and Windows, these can either be absolute paths or relative to the executable + # Usage: + # set_rpath(TARGETS + # PATHS + # RELATIVE) + # if the RELATIVE option is used the paths will be specified from either $ORIGIN on Linux or @executable_path on Mac + set(options RELATIVE) + set(oneValueArgs ) + set(multiValueArgs TARGETS PATHS) + cmake_parse_arguments(SET_RPATH "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + foreach(_target IN ITEMS ${SET_RPATH_TARGETS}) + message(STATUS "Setting SKIP_BUILD_RPATH for target ${_target} to FALSE") + set_target_properties(${_target} PROPERTIES SKIP_BUILD_RPATH FALSE) + message(STATUS "Setting BUILD_WITH_INSTALL_RPATH for target ${_target} to FALSE") + set_target_properties(${_target} PROPERTIES BUILD_WITH_INSTALL_RPATH FALSE) + message(STATUS "Setting INSTALL_RPATH_USE_LINK_PATH for target ${_target} to TRUE") + set_target_properties(${_target} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) + if(APPLE) + message(STATUS "Setting MACOSX_RPATH for target ${_target}") + set_target_properties(${_target} PROPERTIES MACOSX_RPATH ON) + endif() + if(SET_RPATH_RELATIVE) + list(PREPEND SET_RPATH_PATHS "") + if(APPLE) + list(TRANSFORM SET_RPATH_PATHS PREPEND "@executable_path/") + else(LINUX) + list(TRANSFORM SET_RPATH_PATHS PREPEND "\$ORIGIN/") + endif() + endif() + set_target_properties(${_target} PROPERTIES INSTALL_RPATH "${SET_RPATH_PATHS}") + message(STATUS "Setting install RPATH for target ${_target} to ${SET_RPATH_PATHS}") + endforeach() +endfunction() + +# Ultimaker uniform Python linking method +function(use_python project_name) + find_package(Python REQUIRED) + get_target_property(type ${project_name} TYPE) + if(${type} STREQUAL "INTERFACE_LIBRARY") + target_link_libraries(${project_name} INTERFACE Python::Python) + else() + target_link_libraries(${project_name} PRIVATE Python::Python) + endif() + message(STATUS "Linking and building ${project_name} against Python ${Python_VERSION}") +endfunction() + +# Ultimaker uniform Thread linking method +function(use_threads project_name) + message(STATUS "Enabling threading support for ${project_name}") + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) + set(THREADS_PREFER_PTHREAD_FLAG TRUE) + find_package(Threads) + get_target_property(type ${project_name} TYPE) + if (${type} STREQUAL "INTERFACE_LIBRARY") + target_link_libraries(${project_name} INTERFACE Threads::Threads) + else() + target_link_libraries(${project_name} PRIVATE Threads::Threads) + endif() +endfunction() + +# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md +function(set_project_warnings project_name) + message(STATUS "Setting warnings for ${project_name}") + set(MSVC_WARNINGS + /W4 # Baseline reasonable warnings + /w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data + /w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data + /w14263 # 'function': member function does not override any base class virtual member function + /w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not + # be destructed correctly + /w14287 # 'operator': unsigned/negative constant mismatch + /we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside + # the for-loop scope + /w14296 # 'operator': expression is always 'boolean_value' + /w14311 # 'variable': pointer truncation from 'type1' to 'type2' + /w14545 # expression before comma evaluates to a function which is missing an argument list + /w14546 # function call before comma missing argument list + /w14547 # 'operator': operator before comma has no effect; expected operator with side-effect + /w14549 # 'operator': operator before comma has no effect; did you intend 'operator'? + /w14555 # expression has no effect; expected expression with side- effect + /w14619 # pragma warning: there is no warning number 'number' + /w14640 # Enable warning on thread un-safe static member initialization + /w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior. + /w14905 # wide string literal cast to 'LPSTR' + /w14906 # string literal cast to 'LPWSTR' + /w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied + /permissive- # standards conformance mode for MSVC compiler. + ) + + set(CLANG_WARNINGS + -Wall + -Wextra # reasonable and standard + -Wshadow # warn the user if a variable declaration shadows one from a parent context + -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps + # catch hard to track down memory errors + -Wold-style-cast # warn for c-style casts + -Wcast-align # warn for potential performance problem casts + -Wunused # warn on anything being unused + -Woverloaded-virtual # warn if you overload (not override) a virtual function + -Wpedantic # warn if non-standard C++ is used + -Wconversion # warn on type conversions that may lose data + -Wsign-conversion # warn on sign conversions + -Wnull-dereference # warn if a null dereference is detected + -Wdouble-promotion # warn if float is implicit promoted to double + -Wformat=2 # warn on security issues around functions that format output (ie printf) + ) + + set(GCC_WARNINGS + ${CLANG_WARNINGS} + -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist + -Wduplicated-cond # warn if if / else chain has duplicated conditions + -Wduplicated-branches # warn if if / else branches have duplicated code + -Wlogical-op # warn about logical operations being used where bitwise were probably wanted + -Wuseless-cast # warn if you perform a cast to the same type + ) + + if(MSVC) + set(PROJECT_WARNINGS ${MSVC_WARNINGS}) + elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + set(PROJECT_WARNINGS ${CLANG_WARNINGS}) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(PROJECT_WARNINGS ${GCC_WARNINGS}) + else() + message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") + endif() + + get_target_property(type ${project_name} TYPE) + if (${type} STREQUAL "INTERFACE_LIBRARY") + target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}) + else() + target_compile_options(${project_name} PRIVATE ${PROJECT_WARNINGS}) + endif() +endfunction() + +# This function will prevent in-source builds +function(AssureOutOfSourceBuilds) + # make sure the user doesn't play dirty with symlinks + get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) + get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) + + # disallow in-source builds + if("${srcdir}" STREQUAL "${bindir}") + message("######################################################") + message("Warning: in-source builds are disabled") + message("Please create a separate build directory and run cmake from there") + message("######################################################") + message(FATAL_ERROR "Quitting configuration") + endif() +endfunction() + +option(ALLOW_IN_SOURCE_BUILD "Allow building in your source folder. Strongly discouraged" OFF) +if(NOT ALLOW_IN_SOURCE_BUILD) + assureoutofsourcebuilds() +endif() + +function(enable_sanitizers project_name) + + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" FALSE) + + if(ENABLE_COVERAGE) + target_compile_options(${project_name} INTERFACE --coverage -O0 -g) + target_link_libraries(${project_name} INTERFACE --coverage) + endif() + + set(SANITIZERS "") + + option(ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" FALSE) + if(ENABLE_SANITIZER_ADDRESS) + list(APPEND SANITIZERS "address") + endif() + + option(ENABLE_SANITIZER_LEAK "Enable leak sanitizer" FALSE) + if(ENABLE_SANITIZER_LEAK) + list(APPEND SANITIZERS "leak") + endif() + + option(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "Enable undefined behavior sanitizer" FALSE) + if(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR) + list(APPEND SANITIZERS "undefined") + endif() + + option(ENABLE_SANITIZER_THREAD "Enable thread sanitizer" FALSE) + if(ENABLE_SANITIZER_THREAD) + if("address" IN_LIST SANITIZERS OR "leak" IN_LIST SANITIZERS) + message(WARNING "Thread sanitizer does not work with Address and Leak sanitizer enabled") + else() + list(APPEND SANITIZERS "thread") + endif() + endif() + + option(ENABLE_SANITIZER_MEMORY "Enable memory sanitizer" FALSE) + if(ENABLE_SANITIZER_MEMORY AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + if("address" IN_LIST SANITIZERS + OR "thread" IN_LIST SANITIZERS + OR "leak" IN_LIST SANITIZERS) + message(WARNING "Memory sanitizer does not work with Address, Thread and Leak sanitizer enabled") + else() + list(APPEND SANITIZERS "memory") + endif() + endif() + + list( + JOIN + SANITIZERS + "," + LIST_OF_SANITIZERS) + + endif() + + if(LIST_OF_SANITIZERS) + if(NOT + "${LIST_OF_SANITIZERS}" + STREQUAL + "") + target_compile_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) + target_link_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) + endif() + endif() + +endfunction() + +option(ENABLE_CPPCHECK "Enable static analysis with cppcheck" OFF) +option(ENABLE_CLANG_TIDY "Enable static analysis with clang-tidy" OFF) +option(ENABLE_INCLUDE_WHAT_YOU_USE "Enable static analysis with include-what-you-use" OFF) + +if(ENABLE_CPPCHECK) + find_program(CPPCHECK cppcheck) + if(CPPCHECK) + message(STATUS "Using cppcheck") + set(CMAKE_CXX_CPPCHECK + ${CPPCHECK} + --suppress=missingInclude + --enable=all + --inline-suppr + --inconclusive + -i + ${CMAKE_SOURCE_DIR}/imgui/lib) + else() + message(WARNING "cppcheck requested but executable not found") + endif() +endif() + +if(ENABLE_CLANG_TIDY) + find_program(CLANGTIDY clang-tidy) + if(CLANGTIDY) + message(STATUS "Using clang-tidy") + set(CMAKE_CXX_CLANG_TIDY ${CLANGTIDY} -extra-arg=-Wno-unknown-warning-option) + else() + message(WARNING "clang-tidy requested but executable not found") + endif() +endif() + +if(ENABLE_INCLUDE_WHAT_YOU_USE) + find_program(INCLUDE_WHAT_YOU_USE include-what-you-use) + if(INCLUDE_WHAT_YOU_USE) + message(STATUS "Using include-what-you-use") + set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${INCLUDE_WHAT_YOU_USE}) + else() + message(WARNING "include-what-you-use requested but executable not found") + endif() +endif() \ No newline at end of file From a449418be6615ad9001928aee660bf4999beaad3 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 4 Mar 2022 18:56:14 +0100 Subject: [PATCH 02/24] Added relative rpath to lib from site-packages Although not needed at run-time, it is needed for freeze time, such that cx-freeze can find it. Contributes to CURA-8640 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8dc3dd..cbd2e23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ set_rpath(TARGETS "$<$:usr/bin>" "$<$:usr/bin/lib>" "$<$:../lib>" + "../../" RELATIVE) target_include_directories(pynest2d From 107dd4804a92f6709308fa02d0acbd1e4d311e42 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Tue, 8 Mar 2022 13:11:43 +0100 Subject: [PATCH 03/24] Also use relative loader for rpath Contributes to CURA-8640 --- cmake/StandardProjectSettings.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index cca13d9..3d43287 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -127,7 +127,10 @@ function(set_rpath) if(SET_RPATH_RELATIVE) list(PREPEND SET_RPATH_PATHS "") if(APPLE) + set(loader_path "${SET_RPATH_PATHS}") + list(TRANSFORM loader_path PREPEND "@loader_path/") list(TRANSFORM SET_RPATH_PATHS PREPEND "@executable_path/") + list(APPEND SET_RPATH_PATHS ${loader_path}) else(LINUX) list(TRANSFORM SET_RPATH_PATHS PREPEND "\$ORIGIN/") endif() From 044588cbd2559ca942f620b4fe566adc3dac2fbe Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Tue, 8 Mar 2022 14:31:16 +0100 Subject: [PATCH 04/24] Also add the ../Resources/lib/ ../lib is an symlink to ../Resources/lib/ Contributes to CURA-8640 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbd2e23..a1623b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ set_rpath(TARGETS "$<$:usr/bin>" "$<$:usr/bin/lib>" "$<$:../lib>" + "$<$:../Resources/lib>" "../../" RELATIVE) From 2c014f5cbe224c1cb63d7e98ae92c28df4ebc286 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 24 Mar 2022 10:01:35 +0100 Subject: [PATCH 05/24] Use same FindClipper cmake module as libnest2d Contributes to CURA-8640 --- CMakeLists.txt | 4 +- cmake/FindClipper.cmake | 88 +++++++++++++++++++++++++++++++++++++++++ cmake/Findclipper.cmake | 88 ----------------------------------------- 3 files changed, 90 insertions(+), 90 deletions(-) create mode 100644 cmake/FindClipper.cmake delete mode 100644 cmake/Findclipper.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a1623b4..4b1bdac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,9 +46,9 @@ target_include_directories(pynest2d target_compile_features(pynest2d INTERFACE cxx_std_17) find_package(Threads) -find_package(clipper) +find_package(Clipper) find_package(NLopt) -target_link_libraries(pynest2d INTERFACE libnest2d::libnest2d Python::Python Threads::Threads clipper::clipper NLopt::nlopt) +target_link_libraries(pynest2d INTERFACE libnest2d::libnest2d Python::Python Threads::Threads Clipper::Clipper NLopt::nlopt) add_sip_module(pynest2d) install_sip_module(pynest2d) \ No newline at end of file diff --git a/cmake/FindClipper.cmake b/cmake/FindClipper.cmake new file mode 100644 index 0000000..e640b1d --- /dev/null +++ b/cmake/FindClipper.cmake @@ -0,0 +1,88 @@ +# Find Clipper library (http://www.angusj.com/delphi/clipper.php). +# The following variables are set +# +# CLIPPER_FOUND +# CLIPPER_INCLUDE_DIRS +# CLIPPER_LIBRARIES +# +# It searches the environment variable $CLIPPER_PATH automatically. + +unset(CLIPPER_FOUND CACHE) +unset(CLIPPER_INCLUDE_DIRS CACHE) +unset(CLIPPER_LIBRARIES CACHE) +unset(CLIPPER_LIBRARIES_RELEASE CACHE) +unset(CLIPPER_LIBRARIES_DEBUG CACHE) + +if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug)") + set(CLIPPER_BUILD_TYPE DEBUG) +else() + set(CLIPPER_BUILD_TYPE RELEASE) +endif() + +FIND_PATH(CLIPPER_INCLUDE_DIRS clipper.hpp + $ENV{CLIPPER_PATH} + $ENV{CLIPPER_PATH}/cpp/ + $ENV{CLIPPER_PATH}/include/ + $ENV{CLIPPER_PATH}/include/polyclipping/ + ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/include/ + ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/include/polyclipping/ + ${CMAKE_PREFIX_PATH}/include/polyclipping + ${CMAKE_PREFIX_PATH}/include/ + /opt/local/include/ + /opt/local/include/polyclipping/ + /usr/local/include/ + /usr/local/include/polyclipping/ + /usr/include + /usr/include/polyclipping/) + +set(LIB_SEARCHDIRS + $ENV{CLIPPER_PATH} + $ENV{CLIPPER_PATH}/cpp/ + $ENV{CLIPPER_PATH}/cpp/build/ + $ENV{CLIPPER_PATH}/lib/ + $ENV{CLIPPER_PATH}/lib/polyclipping/ + ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/lib/ + ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/lib/polyclipping/ + ${CMAKE_PREFIX_PATH}/lib/ + ${CMAKE_PREFIX_PATH}/lib/polyclipping/ + /opt/local/lib/ + /opt/local/lib/polyclipping/ + /usr/local/lib/ + /usr/local/lib/polyclipping/ + /usr/lib/polyclipping + ) + +set(_deb_postfix "d") + +FIND_LIBRARY(CLIPPER_LIBRARIES_RELEASE polyclipping ${LIB_SEARCHDIRS}) +FIND_LIBRARY(CLIPPER_LIBRARIES_DEBUG polyclipping${_deb_postfix} ${LIB_SEARCHDIRS}) + +if(CLIPPER_LIBRARIES_${CLIPPER_BUILD_TYPE}) + set(CLIPPER_LIBRARIES "${CLIPPER_LIBRARIES_${CLIPPER_BUILD_TYPE}}") +else() + set(CLIPPER_LIBRARIES "${CLIPPER_LIBRARIES_RELEASE}") +endif() + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Clipper + "Clipper library cannot be found. Consider set CLIPPER_PATH environment variable" + CLIPPER_INCLUDE_DIRS + CLIPPER_LIBRARIES) + +MARK_AS_ADVANCED( + CLIPPER_INCLUDE_DIRS + CLIPPER_LIBRARIES) + +if(CLIPPER_FOUND) + add_library(Clipper::Clipper UNKNOWN IMPORTED) + set_target_properties(Clipper::Clipper PROPERTIES IMPORTED_LOCATION ${CLIPPER_LIBRARIES}) + set_target_properties(Clipper::Clipper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CLIPPER_INCLUDE_DIRS}) + if(CLIPPER_LIBRARIES_RELEASE AND CLIPPER_LIBRARIES_DEBUG) + set_target_properties(Clipper::Clipper PROPERTIES + IMPORTED_LOCATION_DEBUG ${CLIPPER_LIBRARIES_DEBUG} + IMPORTED_LOCATION_RELWITHDEBINFO ${CLIPPER_LIBRARIES_RELEASE} + IMPORTED_LOCATION_RELEASE ${CLIPPER_LIBRARIES_RELEASE} + IMPORTED_LOCATION_MINSIZEREL ${CLIPPER_LIBRARIES_RELEASE} + ) + endif() +endif() diff --git a/cmake/Findclipper.cmake b/cmake/Findclipper.cmake deleted file mode 100644 index 3e67e47..0000000 --- a/cmake/Findclipper.cmake +++ /dev/null @@ -1,88 +0,0 @@ -#Find Clipper library (http://www.angusj.com/delphi/clipper.php). -#The following variables are set -# -#CLIPPER_FOUND -#CLIPPER_INCLUDE_DIRS -#CLIPPER_LIBRARIES -# -#It searches the environment variable $CLIPPER_PATH automatically. - -unset(CLIPPER_FOUND CACHE) -unset(CLIPPER_INCLUDE_DIRS CACHE) -unset(CLIPPER_LIBRARIES CACHE) -unset(CLIPPER_LIBRARIES_RELEASE CACHE) -unset(CLIPPER_LIBRARIES_DEBUG CACHE) - -if($ EQUAL "debug") - set(CLIPPER_BUILD_TYPE DEBUG) -else() - set(CLIPPER_BUILD_TYPE RELEASE) -endif() - -find_path(CLIPPER_INCLUDE_DIRS clipper.hpp - ${clipper_PACKAGE_FOLDER}/include - $ENV{CLIPPER_PATH} - $ENV{CLIPPER_PATH}/cpp/ - $ENV{CLIPPER_PATH}/include/ - $ENV{CLIPPER_PATH}/include/polyclipping/ - ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/include/ - ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/include/polyclipping/ - ${CMAKE_PREFIX_PATH}/include/polyclipping - ${CMAKE_PREFIX_PATH}/include/ - /opt/local/include/ - /opt/local/include/polyclipping/ - /usr/local/include/ - /usr/local/include/polyclipping/ - /usr/include - /usr/include/polyclipping/ -) - -set(LIB_SEARCHDIRS - ${clipper_PACKAGE_FOLDER}/lib - $ENV{CLIPPER_PATH} - $ENV{CLIPPER_PATH}/cpp/ - $ENV{CLIPPER_PATH}/cpp/build/ - $ENV{CLIPPER_PATH}/lib/ - $ENV{CLIPPER_PATH}/lib/polyclipping/ - ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/lib/ - ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/lib/polyclipping/ - ${CMAKE_PREFIX_PATH}/lib/ - ${CMAKE_PREFIX_PATH}/lib/polyclipping/ - /opt/local/lib/ - /opt/local/lib/polyclipping/ - /usr/local/lib/ - /usr/local/lib/polyclipping/ - /usr/lib/polyclipping -) - -set(_deb_postfix "d") - -find_library(CLIPPER_LIBRARIES_RELEASE polyclipping ${LIB_SEARCHDIRS}) -find_library(CLIPPER_LIBRARIES_DEBUG polyclipping${_deb_postfix} ${LIB_SEARCHDIRS}) - -if(CLIPPER_LIBRARIES_${CLIPPER_BUILD_TYPE}) - set(CLIPPER_LIBRARIES "${CLIPPER_LIBRARIES_${CLIPPER_BUILD_TYPE}}") -else() - set(CLIPPER_LIBRARIES "${CLIPPER_LIBRARIES_RELEASE}") -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(clipper - "Clipper library cannot be found. Consider set CLIPPER_PATH environment variable" - CLIPPER_INCLUDE_DIRS - CLIPPER_LIBRARIES -) - -mark_as_advanced(CLIPPER_INCLUDE_DIRS CLIPPER_LIBRARIES) - -if(CLIPPER_FOUND) - add_library(clipper::clipper INTERFACE IMPORTED) - if(CLIPPER_LIBRARIES) - set_property(TARGET clipper::clipper - PROPERTY INTERFACE_LINK_LIBRARIES - ${CLIPPER_LIBRARIES} APPEND) - endif() - set_property(TARGET clipper::clipper - PROPERTY INTERFACE_INCLUDE_DIRECTORIES - ${CLIPPER_INCLUDE_DIRS} APPEND) -endif() From 9f5ec6dc6fc8f379a56b112e3bd245f1305f3806 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 30 Mar 2022 04:36:23 +0200 Subject: [PATCH 06/24] Allow external def of sip-build executable Contributes to CURA-8640 --- cmake/FindSIP.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/FindSIP.cmake b/cmake/FindSIP.cmake index f519890..828e82d 100644 --- a/cmake/FindSIP.cmake +++ b/cmake/FindSIP.cmake @@ -26,10 +26,10 @@ -IF(SIP_VERSION) +IF(SIP_VERSION OR SIP_BUILD_EXECUTABLE) # Already in cache, be silent SET(SIP_FOUND TRUE) -ELSE(SIP_VERSION) +ELSE() FIND_FILE(_find_sip_py FindSIP.py PATHS ${CMAKE_MODULE_PATH} NO_CMAKE_FIND_ROOT_PATH) @@ -59,7 +59,7 @@ ELSE(SIP_VERSION) ENDIF(SIP_FIND_REQUIRED) ENDIF(SIP_FOUND) -ENDIF(SIP_VERSION) +ENDIF() include(${CMAKE_SOURCE_DIR}/cmake/SIPMacros.cmake) ADD_DEFINITIONS(-DSIP_VERSION=0x${SIP_VERSION}) From ad5c27ea92674c18c03f702a88eae3ab64d7a239 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Wed, 30 Mar 2022 04:48:50 +0200 Subject: [PATCH 07/24] COnsistent naming of cmake targets with Conan Contributes to CURA-8640 --- CMakeLists.txt | 16 ++++++++++++---- cmake/{FindClipper.cmake => Findclipper.cmake} | 8 ++++---- 2 files changed, 16 insertions(+), 8 deletions(-) rename cmake/{FindClipper.cmake => Findclipper.cmake} (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b1bdac..aa44d67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,8 +17,16 @@ endif() if(APPLE) set(Python_FIND_FRAMEWORK NEVER) endif() -find_package(Python ${Python_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development) -message(STATUS "Linking and building ${project_name} against Python ${Python_VERSION}") +find_package(cpython ${Python_VERSION} QUIET COMPONENTS Interpreter) +if(NOT TARGET cpython::python) + find_package(Python ${Python_VERSION} EXACT REQUIRED COMPONENTS Interpreter) +else() + add_library(Python::Python ALIAS cpython::python) + set(Python_SITEARCH "${CMAKE_INSTALL_PREFIX}/lib/python3.10/site-packages") + set(Python_EXECUTABLE ${cpython_PACKAGE_FOLDER_RELEASE}/bin/python3) + set($ENV{PYTHONPATH} ${Python_SITEARCH}) +endif() +message(STATUS "Using Python ${Python_VERSION}") find_package(SIP REQUIRED 6.5.0) @@ -46,9 +54,9 @@ target_include_directories(pynest2d target_compile_features(pynest2d INTERFACE cxx_std_17) find_package(Threads) -find_package(Clipper) +find_package(clipper) find_package(NLopt) -target_link_libraries(pynest2d INTERFACE libnest2d::libnest2d Python::Python Threads::Threads Clipper::Clipper NLopt::nlopt) +target_link_libraries(pynest2d INTERFACE libnest2d::libnest2d Python::Python Threads::Threads clipper::clipper NLopt::nlopt) add_sip_module(pynest2d) install_sip_module(pynest2d) \ No newline at end of file diff --git a/cmake/FindClipper.cmake b/cmake/Findclipper.cmake similarity index 92% rename from cmake/FindClipper.cmake rename to cmake/Findclipper.cmake index e640b1d..221f798 100644 --- a/cmake/FindClipper.cmake +++ b/cmake/Findclipper.cmake @@ -74,11 +74,11 @@ MARK_AS_ADVANCED( CLIPPER_LIBRARIES) if(CLIPPER_FOUND) - add_library(Clipper::Clipper UNKNOWN IMPORTED) - set_target_properties(Clipper::Clipper PROPERTIES IMPORTED_LOCATION ${CLIPPER_LIBRARIES}) - set_target_properties(Clipper::Clipper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CLIPPER_INCLUDE_DIRS}) + add_library(clipper::clipper UNKNOWN IMPORTED) + set_target_properties(clipper::clipper PROPERTIES IMPORTED_LOCATION ${CLIPPER_LIBRARIES}) + set_target_properties(clipper::clipper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CLIPPER_INCLUDE_DIRS}) if(CLIPPER_LIBRARIES_RELEASE AND CLIPPER_LIBRARIES_DEBUG) - set_target_properties(Clipper::Clipper PROPERTIES + set_target_properties(clipper::clipper PROPERTIES IMPORTED_LOCATION_DEBUG ${CLIPPER_LIBRARIES_DEBUG} IMPORTED_LOCATION_RELWITHDEBINFO ${CLIPPER_LIBRARIES_RELEASE} IMPORTED_LOCATION_RELEASE ${CLIPPER_LIBRARIES_RELEASE} From 8e7dbd63aecb70b73f6ba33e36884ecbc84675b0 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Wed, 30 Mar 2022 04:56:09 +0200 Subject: [PATCH 08/24] fixed missing boost header Contributes to CURA-8640 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa44d67..62c5731 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,7 @@ target_compile_features(pynest2d INTERFACE cxx_std_17) find_package(Threads) find_package(clipper) find_package(NLopt) -target_link_libraries(pynest2d INTERFACE libnest2d::libnest2d Python::Python Threads::Threads clipper::clipper NLopt::nlopt) +target_link_libraries(pynest2d INTERFACE libnest2d::libnest2d Python::Python Threads::Threads clipper::clipper NLopt::nlopt boost::boost) add_sip_module(pynest2d) install_sip_module(pynest2d) \ No newline at end of file From 961dabf47c5e1ee04924cbab85bcd42dd1ab7358 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Wed, 30 Mar 2022 04:57:28 +0200 Subject: [PATCH 09/24] fixed missing boost header Contributes to CURA-8640 --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62c5731..3a12bb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ target_compile_features(pynest2d INTERFACE cxx_std_17) find_package(Threads) find_package(clipper) find_package(NLopt) +find_package(boost) target_link_libraries(pynest2d INTERFACE libnest2d::libnest2d Python::Python Threads::Threads clipper::clipper NLopt::nlopt boost::boost) add_sip_module(pynest2d) From 3d8c7672a37679a1ca389b210cfaf1cb3e8dd2cd Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Apr 2022 16:25:55 +0200 Subject: [PATCH 10/24] Fix setting environment variable We don't want to set a new variable with as name the current PYTHONPATH. We want to set the PYTHONPATH itself. Contributes to issue CURA-8640. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a12bb2..e4a4f76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ else() add_library(Python::Python ALIAS cpython::python) set(Python_SITEARCH "${CMAKE_INSTALL_PREFIX}/lib/python3.10/site-packages") set(Python_EXECUTABLE ${cpython_PACKAGE_FOLDER_RELEASE}/bin/python3) - set($ENV{PYTHONPATH} ${Python_SITEARCH}) + set(ENV{PYTHONPATH} ${Python_SITEARCH}) endif() message(STATUS "Using Python ${Python_VERSION}") @@ -60,4 +60,4 @@ find_package(boost) target_link_libraries(pynest2d INTERFACE libnest2d::libnest2d Python::Python Threads::Threads clipper::clipper NLopt::nlopt boost::boost) add_sip_module(pynest2d) -install_sip_module(pynest2d) \ No newline at end of file +install_sip_module(pynest2d) From dc10a0924186aa2413b566a8fa547b9e2dee45e7 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Mon, 4 Apr 2022 13:56:32 +0200 Subject: [PATCH 11/24] Allow setting PYTHONPATH as CMake arg Contributes to CURA-8640 --- cmake/SIPMacros.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index e36d080..10b9989 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -21,7 +21,7 @@ function(add_sip_module MODULE_TARGET) message(STATUS "SIP: Generating source files") execute_process( - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=$ENV{PYTHONPATH}${env_path_sep}${CMAKE_CURRENT_BINARY_DIR}" ${SIP_BUILD_EXECUTABLE} ${SIP_ARGS} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${PYTHONPATH}${env_path_sep}$ENV{PYTHONPATH}${env_path_sep}${CMAKE_CURRENT_BINARY_DIR}" ${SIP_BUILD_EXECUTABLE} ${SIP_ARGS} COMMAND_ECHO STDOUT WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ ) From ea7750fb79ef3df5f98f4c66765187c2ba371bc0 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Mon, 4 Apr 2022 14:16:06 +0200 Subject: [PATCH 12/24] Also use the PYTHONPATH on the regenerate stage Contributes to CURA-8640 --- cmake/SIPMacros.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 10b9989..b90f038 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -77,7 +77,7 @@ function(add_sip_module MODULE_TARGET) # on the sip definition files without having to reconfigure the complete project. add_custom_command( TARGET "sip_${MODULE_TARGET}" - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=$ENV{PYTHONPATH}${env_path_sep}${CMAKE_CURRENT_BINARY_DIR}" ${SIP_BUILD_EXECUTABLE} ${SIP_ARGS} + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${PYTHONPATH}${env_path_sep}$ENV{PYTHONPATH}${env_path_sep}${CMAKE_CURRENT_BINARY_DIR}" ${SIP_BUILD_EXECUTABLE} ${SIP_ARGS} COMMAND ${CMAKE_COMMAND} -E touch ${_sip_output_files} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ MAIN_DEPENDENCY ${MODULE_SIP} From 74a34dce31ef60642f46feaf3a65895286dd4ffb Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Mon, 4 Apr 2022 14:24:22 +0200 Subject: [PATCH 13/24] Use dev component for Python Contributes to CURA-8640 --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4a4f76..841033f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,16 +17,16 @@ endif() if(APPLE) set(Python_FIND_FRAMEWORK NEVER) endif() -find_package(cpython ${Python_VERSION} QUIET COMPONENTS Interpreter) -if(NOT TARGET cpython::python) - find_package(Python ${Python_VERSION} EXACT REQUIRED COMPONENTS Interpreter) +find_package(cpython ${Python_VERSION} QUIET COMPONENTS Interpreter Development) +if(NOT TARGET cpython::cpython) + find_package(Python ${Python_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development) else() add_library(Python::Python ALIAS cpython::python) set(Python_SITEARCH "${CMAKE_INSTALL_PREFIX}/lib/python3.10/site-packages") set(Python_EXECUTABLE ${cpython_PACKAGE_FOLDER_RELEASE}/bin/python3) set(ENV{PYTHONPATH} ${Python_SITEARCH}) endif() -message(STATUS "Using Python ${Python_VERSION}") +message(STATUS "Linking and building ${project_name} against Python ${Python_VERSION}") find_package(SIP REQUIRED 6.5.0) From fa33ba0058999786b5bb5e8597cc9d509f95fad1 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Mon, 4 Apr 2022 16:53:12 +0200 Subject: [PATCH 14/24] Use conanfile.txt Contributes to CURA-8640 --- CMakeLists.txt | 1 + cmake/conan.cmake | 34 ++++++++++++++++++++++++++++++++++ conanfile.txt | 11 +++++++++++ 3 files changed, 46 insertions(+) create mode 100644 cmake/conan.cmake create mode 100644 conanfile.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 841033f..634cde8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(pynest2d) cmake_minimum_required(VERSION 3.18) # Lowest version it's been tested with. include(cmake/StandardProjectSettings.cmake) +include(cmake/conan.cmake) AssureOutOfSourceBuilds() list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") diff --git a/cmake/conan.cmake b/cmake/conan.cmake new file mode 100644 index 0000000..974f5b6 --- /dev/null +++ b/cmake/conan.cmake @@ -0,0 +1,34 @@ +if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") + message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") + file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.0/conan.cmake" + "${CMAKE_BINARY_DIR}/conan.cmake" + EXPECTED_HASH SHA256=65fc3508c91bf201f5472d28b21259e02b6f975a2917be457412ab7a87906c1e + TLS_VERIFY ON) +endif() +include(${CMAKE_BINARY_DIR}/conan.cmake) + +# === Project specific === + +conan_config_install(ITEM https://github.com/ultimaker/conan-config.git TYPE git VERIFY_SSL True) +conan_check(VERSION 1.46.0 REQUIRED) + +conan_cmake_run( + BASIC_SETUP + CONANFILE + conanfile.txt + GENERATORS + VirtualRunEnv + VirtualBuildEnv + CMakeDeps + CMakeToolchain + json + PROFILE + cura_release.jinja + BUILD + missing + ) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND EXISTS "${CMAKE_BINARY_DIR}/conan_toolchain.cmake") + include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake) + set(CMAKE_TOOLCHAIN_FILE ${CMAKE_BINARY_DIR}/conan_toolchain.cmake) +endif() \ No newline at end of file diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..b96c277 --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,11 @@ +[requires] +nlopt/2.7.0 +clipper/6.4.2 +boost/1.70.0 + +[generators] +virtualrunenv +CMakeDeps +CMakeToolchain + +[options] From 35a41bba636b3ad413df78a305015f538c7fbbb1 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Tue, 5 Apr 2022 10:15:30 +0200 Subject: [PATCH 15/24] Allow local site-packages path Contributes to CURA-8640 --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 634cde8..eecea8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,4 +61,8 @@ find_package(boost) target_link_libraries(pynest2d INTERFACE libnest2d::libnest2d Python::Python Threads::Threads clipper::clipper NLopt::nlopt boost::boost) add_sip_module(pynest2d) -install_sip_module(pynest2d) +if(Python_SITELIB_LOCAL) + install_sip_module(pynest2d ${Python_SITELIB_LOCAL}) +else() + install_sip_module(pynest2d) +endif() From a7aa90fd6e59f4833dbe161d156b4379ba130869 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Tue, 5 Apr 2022 10:45:16 +0200 Subject: [PATCH 16/24] Use Libnest2D as namespace for cmake find module Contributes to CURA-8640 --- CMakeLists.txt | 2 +- cmake/FindNLopt.cmake | 94 --------------------------------------- cmake/Findclipper.cmake | 88 ------------------------------------ cmake/Findlibnest2d.cmake | 65 --------------------------- 4 files changed, 1 insertion(+), 248 deletions(-) delete mode 100644 cmake/FindNLopt.cmake delete mode 100644 cmake/Findclipper.cmake delete mode 100644 cmake/Findlibnest2d.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index eecea8d..ab8b820 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ message(STATUS "Linking and building ${project_name} against Python ${Python_VER find_package(SIP REQUIRED 6.5.0) -find_package(libnest2d REQUIRED) # The library we're creating bindings for. +find_package(Libnest2D REQUIRED) # The library we're creating bindings for. add_library(pynest2d INTERFACE) set_project_standards(pynest2d) diff --git a/cmake/FindNLopt.cmake b/cmake/FindNLopt.cmake deleted file mode 100644 index d7b4ba4..0000000 --- a/cmake/FindNLopt.cmake +++ /dev/null @@ -1,94 +0,0 @@ -#Find NLopt library. -#The following variables are set -# -#NLopt_FOUND -#NLopt_INCLUDE_DIRS -#NLopt_LIBRARIES -# -#It searches the environment variable $NLopt_PATH automatically. - -unset(NLopt_FOUND CACHE) -unset(NLopt_INCLUDE_DIRS CACHE) -unset(NLopt_LIBRARIES CACHE) -unset(NLopt_LIBRARIES_RELEASE CACHE) -unset(NLopt_LIBRARIES_DEBUG CACHE) - -if($ EQUAL "debug") - set(NLopt_BUILD_TYPE DEBUG) -else() - set(NLopt_BUILD_TYPE RELEASE) -endif() - -find_path(NLopt_INCLUDE_DIRS nlopt.hpp - ${NLopt_PACKAGE_FOLDER}/include - $ENV{NLopt_PATH} - $ENV{NLopt_PATH}/cpp/ - $ENV{NLopt_PATH}/include/ - ${CMAKE_PREFIX_PATH}/include/nlopt - ${CMAKE_PREFIX_PATH}/include/ - /opt/local/include/ - /opt/local/include/nlopt/ - /usr/local/include/ - /usr/local/include/nlopt/ - /usr/include - /usr/include/nlopt/ -) - -set(LIB_SEARCHDIRS - ${NLopt_PACKAGE_FOLDER}/lib - $ENV{NLopt_PATH} - $ENV{NLopt_PATH}/cpp/ - $ENV{NLopt_PATH}/cpp/build/ - $ENV{NLopt_PATH}/lib/ - $ENV{NLopt_PATH}/lib/nlopt/ - ${CMAKE_PREFIX_PATH}/lib/ - ${CMAKE_PREFIX_PATH}/lib/nlopt/ - /opt/local/lib/ - /opt/local/lib/nlopt/ - /usr/local/lib/ - /usr/local/lib/nlopt/ - /usr/lib/nlopt -) - -set(_deb_postfix "d") - -find_library(NLopt_LIBRARIES_RELEASE nlopt ${LIB_SEARCHDIRS}) -find_library(NLopt_LIBRARIES_DEBUG nlopt${_deb_postfix} ${LIB_SEARCHDIRS}) - -if(NLopt_LIBRARIES_${NLopt_BUILD_TYPE}) - set(NLopt_LIBRARIES "${NLopt_LIBRARIES_${NLopt_BUILD_TYPE}}") -else() - set(NLopt_LIBRARIES "${NLopt_LIBRARIES_RELEASE}") -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(NLopt - "NLopt library cannot be found. Consider set NLopt_PATH environment variable" - NLopt_INCLUDE_DIRS - NLopt_LIBRARIES -) - -mark_as_advanced(NLopt_INCLUDE_DIRS NLopt_LIBRARIES) - -if(NLopt_FOUND) - add_library(NLopt::nlopt INTERFACE IMPORTED) - set_property(TARGET NLopt::nlopt - PROPERTY INTERFACE_INCLUDE_DIRECTORIES - ${NLopt_INCLUDE_DIRS} APPEND) - if(NLopt_LIBRARIES) - set_property(TARGET NLopt::nlopt - PROPERTY INTERFACE_LINK_LIBRARIES - ${NLopt_LIBRARIES} APPEND) - endif() - - set_target_properties(NLopt::nlopt PROPERTIES IMPORTED_LOCATION ${NLopt_LIBRARIES}) - set_target_properties(NLopt::nlopt PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${NLopt_INCLUDE_DIRS}) - if(NLopt_LIBRARIES_RELEASE AND NLopt_LIBRARIES_DEBUG) - set_target_properties(NLopt::nlopt PROPERTIES - IMPORTED_LOCATION_DEBUG ${NLopt_LIBRARIES_DEBUG} - IMPORTED_LOCATION_RELWITHDEBINFO ${NLopt_LIBRARIES_RELEASE} - IMPORTED_LOCATION_RELEASE ${NLopt_LIBRARIES_RELEASE} - IMPORTED_LOCATION_MINSIZEREL ${NLopt_LIBRARIES_RELEASE} - ) - endif() -endif() diff --git a/cmake/Findclipper.cmake b/cmake/Findclipper.cmake deleted file mode 100644 index 221f798..0000000 --- a/cmake/Findclipper.cmake +++ /dev/null @@ -1,88 +0,0 @@ -# Find Clipper library (http://www.angusj.com/delphi/clipper.php). -# The following variables are set -# -# CLIPPER_FOUND -# CLIPPER_INCLUDE_DIRS -# CLIPPER_LIBRARIES -# -# It searches the environment variable $CLIPPER_PATH automatically. - -unset(CLIPPER_FOUND CACHE) -unset(CLIPPER_INCLUDE_DIRS CACHE) -unset(CLIPPER_LIBRARIES CACHE) -unset(CLIPPER_LIBRARIES_RELEASE CACHE) -unset(CLIPPER_LIBRARIES_DEBUG CACHE) - -if(CMAKE_BUILD_TYPE MATCHES "(Debug|DEBUG|debug)") - set(CLIPPER_BUILD_TYPE DEBUG) -else() - set(CLIPPER_BUILD_TYPE RELEASE) -endif() - -FIND_PATH(CLIPPER_INCLUDE_DIRS clipper.hpp - $ENV{CLIPPER_PATH} - $ENV{CLIPPER_PATH}/cpp/ - $ENV{CLIPPER_PATH}/include/ - $ENV{CLIPPER_PATH}/include/polyclipping/ - ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/include/ - ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/include/polyclipping/ - ${CMAKE_PREFIX_PATH}/include/polyclipping - ${CMAKE_PREFIX_PATH}/include/ - /opt/local/include/ - /opt/local/include/polyclipping/ - /usr/local/include/ - /usr/local/include/polyclipping/ - /usr/include - /usr/include/polyclipping/) - -set(LIB_SEARCHDIRS - $ENV{CLIPPER_PATH} - $ENV{CLIPPER_PATH}/cpp/ - $ENV{CLIPPER_PATH}/cpp/build/ - $ENV{CLIPPER_PATH}/lib/ - $ENV{CLIPPER_PATH}/lib/polyclipping/ - ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/lib/ - ${PROJECT_SOURCE_DIR}/python/pymesh/third_party/lib/polyclipping/ - ${CMAKE_PREFIX_PATH}/lib/ - ${CMAKE_PREFIX_PATH}/lib/polyclipping/ - /opt/local/lib/ - /opt/local/lib/polyclipping/ - /usr/local/lib/ - /usr/local/lib/polyclipping/ - /usr/lib/polyclipping - ) - -set(_deb_postfix "d") - -FIND_LIBRARY(CLIPPER_LIBRARIES_RELEASE polyclipping ${LIB_SEARCHDIRS}) -FIND_LIBRARY(CLIPPER_LIBRARIES_DEBUG polyclipping${_deb_postfix} ${LIB_SEARCHDIRS}) - -if(CLIPPER_LIBRARIES_${CLIPPER_BUILD_TYPE}) - set(CLIPPER_LIBRARIES "${CLIPPER_LIBRARIES_${CLIPPER_BUILD_TYPE}}") -else() - set(CLIPPER_LIBRARIES "${CLIPPER_LIBRARIES_RELEASE}") -endif() - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Clipper - "Clipper library cannot be found. Consider set CLIPPER_PATH environment variable" - CLIPPER_INCLUDE_DIRS - CLIPPER_LIBRARIES) - -MARK_AS_ADVANCED( - CLIPPER_INCLUDE_DIRS - CLIPPER_LIBRARIES) - -if(CLIPPER_FOUND) - add_library(clipper::clipper UNKNOWN IMPORTED) - set_target_properties(clipper::clipper PROPERTIES IMPORTED_LOCATION ${CLIPPER_LIBRARIES}) - set_target_properties(clipper::clipper PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CLIPPER_INCLUDE_DIRS}) - if(CLIPPER_LIBRARIES_RELEASE AND CLIPPER_LIBRARIES_DEBUG) - set_target_properties(clipper::clipper PROPERTIES - IMPORTED_LOCATION_DEBUG ${CLIPPER_LIBRARIES_DEBUG} - IMPORTED_LOCATION_RELWITHDEBINFO ${CLIPPER_LIBRARIES_RELEASE} - IMPORTED_LOCATION_RELEASE ${CLIPPER_LIBRARIES_RELEASE} - IMPORTED_LOCATION_MINSIZEREL ${CLIPPER_LIBRARIES_RELEASE} - ) - endif() -endif() diff --git a/cmake/Findlibnest2d.cmake b/cmake/Findlibnest2d.cmake deleted file mode 100644 index 61b6262..0000000 --- a/cmake/Findlibnest2d.cmake +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright (c) 2022 Ultimaker B.V. -# pynest2d is released under the terms of the LGPLv3 or higher. - -# This script finds libnest2d on your computer. -# -# The output of this script is the following variables: -# - LIBNEST2D_INCLUDE_DIR: The include directory for libnest2d. - -find_package(PkgConfig) # To easily find files on your computer. - -# First try with packageconfig to get a beginning of an idea where to search. -pkg_check_modules(PC_LIBNEST2D QUIET libnest2d) - -if(NOT TARGET libnest2d::libnest2d) - add_library(libnest2d::libnest2d INTERFACE IMPORTED) -endif() - -find_path(libnest2d_INCLUDE_DIRS NAMES libnest2d/libnest2d.hpp HINTS - ${libnest2d_PACKAGE_FOLDER}/include - ${PC_LIBNEST2D_INCLUDE_DIRS} - ${PC_LIBNEST2D_INCLUDE_DIRS}/libnest2d - ${CMAKE_PREFIX_PATH}/include/ - ${CMAKE_PREFIX_PATH}/include/libnest2d - /opt/local/include/ - /opt/local/include/libnest2d/ - /usr/local/include/ - /usr/local/include/libnest2d/ - /usr/include - /usr/include/libnest2d/ -) -set_property(TARGET libnest2d::libnest2d - PROPERTY INTERFACE_INCLUDE_DIRECTORIES - ${libnest2d_INCLUDE_DIRS} APPEND) - -find_library(libnest2d_LIBRARIES_TARGETS NAMES nest2d_clipper_nlopt - HINTS - ${libnest2d_PACKAGE_FOLDER}/lib - ${PC_LIBNEST2D_LIBDIR} - ${PC_LIBNEST2D_LIBRARY_DIRS} - ${CMAKE_PREFIX_PATH}/lib/ - ${CMAKE_PREFIX_PATH}/lib/libnest2d - /opt/local/lib/ - /opt/local/lib/libnest2d/ - /usr/local/lib/ - /usr/local/lib/libnest2d/ - /usr/lib - /usr/lib/libnest2d/ - ) -if(libnest2d_LIBRARIES_TARGETS) - set_property(TARGET libnest2d::libnest2d - PROPERTY INTERFACE_LINK_LIBRARIES - ${libnest2d_LIBRARIES_TARGETS} APPEND) -endif() - -set(libnest2d_COMPILE_DEFINITIONS - "LIBNEST2D_GEOMETRIES_clipper" - "LIBNEST2D_OPTIMIZERS_nlopt" - "LIBNEST2D_THREADING_std") -set_property(TARGET libnest2d::libnest2d - PROPERTY INTERFACE_COMPILE_DEFINITIONS - ${libnest2d_COMPILE_DEFINITIONS} APPEND) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(libnest2d DEFAULT_MSG - libnest2d_INCLUDE_DIRS) From 66fa164e527c54c2d3adc2e6705e40f29e1f98cd Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Tue, 5 Apr 2022 10:48:49 +0200 Subject: [PATCH 17/24] Removed Conan support Contributes to CURA-8640 --- CMakeLists.txt | 4 ++-- cmake/conan.cmake | 34 ---------------------------------- conanfile.txt | 11 ----------- 3 files changed, 2 insertions(+), 47 deletions(-) delete mode 100644 cmake/conan.cmake delete mode 100644 conanfile.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index ab8b820..1fafddb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,9 @@ # pynest2d is released under the terms of the LGPLv3 or higher. project(pynest2d) -cmake_minimum_required(VERSION 3.18) # Lowest version it's been tested with. +cmake_minimum_required(VERSION 3.20) # Lowest version it's been tested with. include(cmake/StandardProjectSettings.cmake) -include(cmake/conan.cmake) + AssureOutOfSourceBuilds() list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") diff --git a/cmake/conan.cmake b/cmake/conan.cmake deleted file mode 100644 index 974f5b6..0000000 --- a/cmake/conan.cmake +++ /dev/null @@ -1,34 +0,0 @@ -if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") - message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") - file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.0/conan.cmake" - "${CMAKE_BINARY_DIR}/conan.cmake" - EXPECTED_HASH SHA256=65fc3508c91bf201f5472d28b21259e02b6f975a2917be457412ab7a87906c1e - TLS_VERIFY ON) -endif() -include(${CMAKE_BINARY_DIR}/conan.cmake) - -# === Project specific === - -conan_config_install(ITEM https://github.com/ultimaker/conan-config.git TYPE git VERIFY_SSL True) -conan_check(VERSION 1.46.0 REQUIRED) - -conan_cmake_run( - BASIC_SETUP - CONANFILE - conanfile.txt - GENERATORS - VirtualRunEnv - VirtualBuildEnv - CMakeDeps - CMakeToolchain - json - PROFILE - cura_release.jinja - BUILD - missing - ) - -if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND EXISTS "${CMAKE_BINARY_DIR}/conan_toolchain.cmake") - include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake) - set(CMAKE_TOOLCHAIN_FILE ${CMAKE_BINARY_DIR}/conan_toolchain.cmake) -endif() \ No newline at end of file diff --git a/conanfile.txt b/conanfile.txt deleted file mode 100644 index b96c277..0000000 --- a/conanfile.txt +++ /dev/null @@ -1,11 +0,0 @@ -[requires] -nlopt/2.7.0 -clipper/6.4.2 -boost/1.70.0 - -[generators] -virtualrunenv -CMakeDeps -CMakeToolchain - -[options] From 6ff3f82e11e057b062c8d90e3bb0a56d096f75a0 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Tue, 5 Apr 2022 10:50:27 +0200 Subject: [PATCH 18/24] use correct namespace for Libnest2D Contributes to CURA-8640 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fafddb..549d93f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ find_package(Threads) find_package(clipper) find_package(NLopt) find_package(boost) -target_link_libraries(pynest2d INTERFACE libnest2d::libnest2d Python::Python Threads::Threads clipper::clipper NLopt::nlopt boost::boost) +target_link_libraries(pynest2d INTERFACE Libnest2D::libnest2d Python::Python Threads::Threads clipper::clipper NLopt::nlopt boost::boost) add_sip_module(pynest2d) if(Python_SITELIB_LOCAL) From 3a6989c5f3a5b56bc5a1f57acab51c37784d1f7d Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 8 Apr 2022 09:52:50 +0200 Subject: [PATCH 19/24] Capatelize Boost Contributes to CURA-8640 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 549d93f..68df169 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ target_compile_features(pynest2d INTERFACE cxx_std_17) find_package(Threads) find_package(clipper) find_package(NLopt) -find_package(boost) +find_package(Boost) target_link_libraries(pynest2d INTERFACE Libnest2D::libnest2d Python::Python Threads::Threads clipper::clipper NLopt::nlopt boost::boost) add_sip_module(pynest2d) From e131daeefc7270fc3ced25cba5591897eaed4eec Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 14 Apr 2022 11:48:25 +0200 Subject: [PATCH 20/24] Use Python_VERSION in CPython site-package path Contributes to CURA-8640 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68df169..b8f354f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ if(NOT TARGET cpython::cpython) find_package(Python ${Python_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development) else() add_library(Python::Python ALIAS cpython::python) - set(Python_SITEARCH "${CMAKE_INSTALL_PREFIX}/lib/python3.10/site-packages") + set(Python_SITEARCH "${CMAKE_INSTALL_PREFIX}/lib/python${Python_VERSION}/site-packages") set(Python_EXECUTABLE ${cpython_PACKAGE_FOLDER_RELEASE}/bin/python3) set(ENV{PYTHONPATH} ${Python_SITEARCH}) endif() From 99289b9eba665c9bc3923bcef591e5f68928c1ce Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 14 Apr 2022 11:49:15 +0200 Subject: [PATCH 21/24] Don't set target_compiler_feature cxx_std_17 Allready taken care of in StandardProjectSettings Contributes to CURA-8640 --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8f354f..0556f70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,8 +52,6 @@ target_include_directories(pynest2d $ ) -target_compile_features(pynest2d INTERFACE cxx_std_17) - find_package(Threads) find_package(clipper) find_package(NLopt) From 475fd08de4cd5896bf4bf38f87ca1ba3a5ba5a75 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 14 Apr 2022 11:51:01 +0200 Subject: [PATCH 22/24] Renamed assure_out_of_source_builds codestyle Contributes to CURA-8640 --- CMakeLists.txt | 2 -- cmake/StandardProjectSettings.cmake | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0556f70..bbd3716 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,6 @@ project(pynest2d) cmake_minimum_required(VERSION 3.20) # Lowest version it's been tested with. include(cmake/StandardProjectSettings.cmake) -AssureOutOfSourceBuilds() - list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") if(NOT DEFINED Python_VERSION) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 3d43287..99ee188 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -241,7 +241,7 @@ function(set_project_warnings project_name) endfunction() # This function will prevent in-source builds -function(AssureOutOfSourceBuilds) +function(assure_out_of_source_builds) # make sure the user doesn't play dirty with symlinks get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) @@ -258,7 +258,7 @@ endfunction() option(ALLOW_IN_SOURCE_BUILD "Allow building in your source folder. Strongly discouraged" OFF) if(NOT ALLOW_IN_SOURCE_BUILD) - assureoutofsourcebuilds() + assure_out_of_source_builds() endif() function(enable_sanitizers project_name) From d6e05793c907e405c70ba5975bfa2e0b9fddb9bd Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 14 Apr 2022 11:55:58 +0200 Subject: [PATCH 23/24] Use BUILD_SHARED_LIBS instead of BUILD_STATIC BUILD_STATIC was our own custom option while BUILD_SHARED_LIBS is a global CMake flag Contributes to CURA-8640 --- cmake/SIPMacros.cmake | 7 ++++++- cmake/StandardProjectSettings.cmake | 17 +++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index b90f038..8491427 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -53,7 +53,12 @@ function(add_sip_module MODULE_TARGET) if(${usr_src}) list(APPEND sip_sources "${usr_src}") endif() - add_library("sip_${MODULE_TARGET}" SHARED ${sip_sources}) + + if (BUILD_SHARED_LIBS) + add_library("sip_${MODULE_TARGET}" SHARED ${sip_sources}) + else() + add_library("sip_${MODULE_TARGET}" STATIC ${sip_sources}) + endif() # Make sure that the library name of the target is the same as the MODULE_TARGET with the appropriate extension target_link_libraries("sip_${MODULE_TARGET}" PRIVATE "${MODULE_TARGET}") diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 99ee188..c953561 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -1,20 +1,9 @@ include(GNUInstallDirs) # Standard install dirs -# Uniform how we define BUILD_STATIC or BUILD_SHARED_LIBS (common practice) -if(DEFINED BUILD_STATIC) - if(DEFINED BUILD_SHARED_LIBS) - if(${BUILD_SHARED_LIBS} AND ${BUILD_STATIC}) - message(FATAL_ERROR "Conflicting arguments for BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} and BUILD_STATIC=${BUILD_STATIC}") - endif() - else() - set(BUILD_SHARED_LIBS NOT ${BUILD_STATIC}) - endif() -else() - if(NOT DEFINED BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ON) - endif() +if(NOT DEFINED BUILD_SHARED_LIBS) + set(BUILD_SHARED_LIBS ON) + message(STATUS "Setting BUILD_SHARED_LIBS to ${BUILD_SHARED_LIBS}") endif() -message(STATUS "Setting BUILD_SHARED_LIBS to ${BUILD_SHARED_LIBS}") # Set a default build type if none was specified if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) From fac90e27a4caf6d04f1569cae2509798192dad13 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 14 Apr 2022 11:58:41 +0200 Subject: [PATCH 24/24] Clarify the usage of the relative rpath Contributes to CURA-8640 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbd3716..f93e89a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,7 @@ set_rpath(TARGETS "$<$:usr/bin/lib>" "$<$:../lib>" "$<$:../Resources/lib>" - "../../" + "../../" # In distributions of Cura, the libnest2d dependency is 2 directories up from where pynest2d gets installed. RELATIVE) target_include_directories(pynest2d