From b86c38fa054708528d1c24f0e90203e15ecf77d0 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Wed, 23 Feb 2022 18:07:22 +0100 Subject: [PATCH 01/64] Only use sip to generate source files A simple pyproject.toml which links to the sip, cpp and h files to be used and a Custom build-factory which stops sip from building and linking. These steps are to be done by CMake at a later stage. Contributes to CURA-7924 --- CMakeBuilder.py | 13 +++++++++++++ pyproject.toml.in | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 CMakeBuilder.py create mode 100644 pyproject.toml.in diff --git a/CMakeBuilder.py b/CMakeBuilder.py new file mode 100644 index 00000000..f7aa40fb --- /dev/null +++ b/CMakeBuilder.py @@ -0,0 +1,13 @@ +from sipbuild import SetuptoolsBuilder + + +class CMakeBuilder(SetuptoolsBuilder): + def __init__(self, project, **kwargs): + print("Using the CMake builder") + super().__init__(project, **kwargs) + + def build(self): + """ Only Generate the source files """ + print("Generating the source files") + self._generate_bindings() + self._generate_scripts() \ No newline at end of file diff --git a/pyproject.toml.in b/pyproject.toml.in new file mode 100644 index 00000000..d9b50006 --- /dev/null +++ b/pyproject.toml.in @@ -0,0 +1,20 @@ +[build-system] +requires = ["sip >=6, <7"] +build-backend = "sipbuild.api" + +[tool.sip.metadata] +name = "pyArcus" + +[tool.sip.project] +builder-factory = "CMakeBuilder" +sip-files-dir = "${CMAKE_CURRENT_SOURCE_DIR}/python/" +sip-include-dirs = ["CMAKE_CURRENT_SOURCE_DIR/python/"] +build-dir = "${CMAKE_CURRENT_BINARY_DIR}/pyArcus/" + +[tool.sip.bindings.pyArcus] +headers = ["PythonMessage.h"] +include-dirs = ["${CMAKE_CURRENT_SOURCE_DIR}/python/"] +sources = ["${CMAKE_CURRENT_SOURCE_DIR}/python/PythonMessage.cpp"] +exceptions = true +release-gil = true +concatenate = 8 \ No newline at end of file From 02c734706ca41c42665927ad7f48770653d125fc Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 24 Feb 2022 10:55:08 +0100 Subject: [PATCH 02/64] Find SIP on the system. This is taken directly from QGIS https://github.com/qgis/QGIS/tree/master/cmake Contributes to CURA-7924 --- cmake/FindSIP.cmake | 107 +++++++++++++++++--------------------------- cmake/FindSIP.py | 57 +++++++++++++++++++++++ 2 files changed, 97 insertions(+), 67 deletions(-) create mode 100644 cmake/FindSIP.py diff --git a/cmake/FindSIP.cmake b/cmake/FindSIP.cmake index e15e2b4e..ad9e4d11 100644 --- a/cmake/FindSIP.cmake +++ b/cmake/FindSIP.cmake @@ -8,85 +8,58 @@ # # This file defines the following variables: # -# SIP_VERSION - SIP version. +# SIP_VERSION - The version of SIP found expressed as a 6 digit hex number +# suitable for comparison as a string. # -# SIP_EXECUTABLE - Path to the SIP executable. +# SIP_VERSION_STR - The version of SIP found as a human readable string. # -# SIP_INCLUDE_DIRS - The SIP include directories. +# SIP_BINARY_PATH - Path and filename of the SIP command line executable. # +# SIP_INCLUDE_DIR - Directory holding the SIP C++ header file. +# +# SIP_DEFAULT_SIP_DIR - Default directory where .sip files should be installed +# into. # Copyright (c) 2007, Simon Edwards # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. -if(APPLE) - # Workaround for broken FindPythonLibs. It will always find Python 2.7 libs on OSX - set(CMAKE_FIND_FRAMEWORK LAST) -endif() - -# FIXME: Use FindPython3 to find Python, new in CMake 3.12. -# However currently on our CI server it finds the wrong Python version and then doesn't find the headers. -find_package(PythonInterp 3.5 REQUIRED) -find_package(PythonLibs 3.5 REQUIRED) - -# Define variables that are available in FindPython3, so there's no need to branch off in the later part. -set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) -set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) -set(Python3_LIBRARIES ${PYTHON_LIBRARIES}) -set(Python3_VERSION_MINOR "${PYTHON_VERSION_MINOR}") - -execute_process( - COMMAND ${Python3_EXECUTABLE} -c - "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False))" - RESULT_VARIABLE _process_status - OUTPUT_VARIABLE _process_output - OUTPUT_STRIP_TRAILING_WHITESPACE -) -if(${_process_status} EQUAL 0) - string(STRIP ${_process_output} Python3_SITELIB) -else() - message(FATAL_ERROR "Failed to get Python3_SITELIB. Error: ${_process_output}") -endif() - -execute_process( - COMMAND ${Python3_EXECUTABLE} -c - "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(plat_specific=True,standard_lib=False))" - RESULT_VARIABLE _process_status - OUTPUT_VARIABLE _process_output - OUTPUT_STRIP_TRAILING_WHITESPACE -) -if(${_process_status} EQUAL 0) - string(STRIP ${_process_output} Python3_SITEARCH) -else() - message(FATAL_ERROR "Failed to get Python3_SITEARCH. Error: ${_process_output}") -endif() - -get_filename_component(_python_binary_path ${Python3_EXECUTABLE} DIRECTORY) -find_program(SIP_EXECUTABLE sip - HINTS ${CMAKE_PREFIX_PATH}/bin ${CMAKE_INSTALL_PATH}/bin ${_python_binary_path} ${Python3_SITELIB}/PyQt5 -) -find_path(SIP_INCLUDE_DIRS sip.h - HINTS ${CMAKE_PREFIX_PATH}/include ${CMAKE_INSTALL_PATH}/include ${Python3_INCLUDE_DIRS} ${Python3_SITELIB}/PyQt5 -) +IF(SIP_VERSION) + # Already in cache, be silent + SET(SIP_FOUND TRUE) +ELSE(SIP_VERSION) -execute_process( - COMMAND ${Python3_EXECUTABLE} -c "import sip; print(sip.SIP_VERSION_STR)" - RESULT_VARIABLE _process_status - OUTPUT_VARIABLE _process_output - OUTPUT_STRIP_TRAILING_WHITESPACE -) + FIND_FILE(_find_sip_py FindSIP.py PATHS ${CMAKE_MODULE_PATH} NO_CMAKE_FIND_ROOT_PATH) -if(${_process_status} EQUAL 0) - string(STRIP ${_process_output} SIP_VERSION) -endif() + EXECUTE_PROCESS(COMMAND ${Python_EXECUTABLE} ${_find_sip_py} OUTPUT_VARIABLE sip_config) + IF(sip_config) + STRING(REGEX REPLACE "^sip_version:([^\n]+).*$" "\\1" SIP_VERSION ${sip_config}) + STRING(REGEX REPLACE ".*\nsip_version_num:([^\n]+).*$" "\\1" SIP_VERSION_NUM ${sip_config}) + STRING(REGEX REPLACE ".*\nsip_version_str:([^\n]+).*$" "\\1" SIP_VERSION_STR ${sip_config}) + STRING(REGEX REPLACE ".*\ndefault_sip_dir:([^\n]+).*$" "\\1" SIP_DEFAULT_SIP_DIR ${sip_config}) + IF(${SIP_VERSION_STR} VERSION_LESS 5) + STRING(REGEX REPLACE ".*\nsip_bin:([^\n]+).*$" "\\1" SIP_BINARY_PATH ${sip_config}) + STRING(REGEX REPLACE ".*\nsip_inc_dir:([^\n]+).*$" "\\1" SIP_INCLUDE_DIR ${sip_config}) + STRING(REGEX REPLACE ".*\nsip_module_dir:([^\n]+).*$" "\\1" SIP_MODULE_DIR ${sip_config}) + ELSE(${SIP_VERSION_STR} VERSION_LESS 5) + FIND_PROGRAM(SIP_BUILD_EXECUTABLE sip-build) + ENDIF(${SIP_VERSION_STR} VERSION_LESS 5) + SET(SIP_FOUND TRUE) + ENDIF(sip_config) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(SIP REQUIRED_VARS SIP_EXECUTABLE SIP_INCLUDE_DIRS VERSION_VAR SIP_VERSION) + IF(SIP_FOUND) + IF(NOT SIP_FIND_QUIETLY) + MESSAGE(STATUS "Found SIP version: ${SIP_VERSION_STR}") + ENDIF(NOT SIP_FIND_QUIETLY) + include(${CMAKE_CURRENT_SOURCE_DIR}/SIPMacros.cmake) + ELSE(SIP_FOUND) + IF(SIP_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find SIP") + ENDIF(SIP_FIND_REQUIRED) + ENDIF(SIP_FOUND) -if(SIP_FOUND) - include(${CMAKE_CURRENT_LIST_DIR}/SIPMacros.cmake) -endif() +ENDIF(SIP_VERSION) -mark_as_advanced(SIP_EXECUTABLE SIP_INCLUDE_DIRS SIP_VERSION) +ADD_DEFINITIONS(-DSIP_VERSION=0x${SIP_VERSION}) diff --git a/cmake/FindSIP.py b/cmake/FindSIP.py new file mode 100644 index 00000000..b7bfc9a7 --- /dev/null +++ b/cmake/FindSIP.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2007, Simon Edwards +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the Simon Edwards nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY Simon Edwards ''AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL Simon Edwards BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# FindSIP.py +# Copyright (c) 2007, Simon Edwards +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +try: + import sipbuild + + print("sip_version:%06.0x" % sipbuild.version.SIP_VERSION) + print("sip_version_num:%d" % sipbuild.version.SIP_VERSION) + print("sip_version_str:%s" % sipbuild.version.SIP_VERSION_STR) + + from distutils.sysconfig import get_python_lib + python_modules_dir = get_python_lib(plat_specific=1) + print("default_sip_dir:%s" % python_modules_dir) +except ImportError: # Code for SIP v4 + import sipconfig + + sipcfg = sipconfig.Configuration() + print("sip_version:%06.0x" % sipcfg.sip_version) + print("sip_version_num:%d" % sipcfg.sip_version) + print("sip_version_str:%s" % sipcfg.sip_version_str) + print("sip_bin:%s" % sipcfg.sip_bin) + print("default_sip_dir:%s" % sipcfg.default_sip_dir) + print("sip_inc_dir:%s" % sipcfg.sip_inc_dir) + # SIP 4.19.10+ has new sipcfg.sip_module_dir + if hasattr(sipcfg, "sip_module_dir"): + print("sip_module_dir:%s" % sipcfg.sip_module_dir) + else: + print("sip_module_dir:%s" % sipcfg.sip_mod_dir) From b6e681d5c9a70df5c01416b50d20df31ee696a19 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 24 Feb 2022 11:13:16 +0100 Subject: [PATCH 03/64] Added CMake function add_sip_module To have better control over compiling and linking of the sip generated source code. We decided to make CMake responsible for those processes. The `add_sip_module` will first generate the source-files using sip and the previous commit build-factory. Which disables the compiling and linking by sip. It will then collect and identify those generated files and make a shared library of these. Compiler flags, user source files, dependency libraries etc. can be specified in the main CMakeLists.txt using an INTERFACE library. The most basic usage is: ```cmake find_package(SIP REQUIRED 6.5.0) add_library(module_name INTERFACE ) target_link_libraries(module_name INTERFACE target_lib_for_the_bindings ) add_sip_module(module_name) ``` compile features and extra include directories can be specified in the normal way, if needed. ```cmake target_include_directories(module_name INTERFACE ) target_compile_features(module_name INTERFACE cxx_std_17) ``` The minimum pyproject.toml.in would consist of: ```toml [build-system] requires = ["sip >=6, <7"] build-backend = "sipbuild.api" [tool.sip.metadata] name = "module_name" [tool.sip.project] builder-factory = "CMakeBuilder" sip-files-dir = "location_of_the_sip_files" build-dir = "${CMAKE_CURRENT_BINARY_DIR}/module_name/" [tool.sip.bindings.module_name] exceptions = true release-gil = true concatenate = 8 ``` Make sure that the main sip definition file is named the same as the module_name and that it contains the following line ``` %Module(name = module_name, call_super_init = True) ``` Contributes to CURA-7924 --- cmake/SIPMacros.cmake | 192 +++++++++++++++--------------------------- 1 file changed, 68 insertions(+), 124 deletions(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 50553e0f..ff9736e9 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -1,128 +1,72 @@ # Macros for SIP # ~~~~~~~~~~~~~~ -# Copyright (c) 2007, Simon Edwards -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# -# SIP website: http://www.riverbankcomputing.co.uk/sip/index.php -# -# This file defines the following macros: -# -# ADD_SIP_PYTHON_MODULE (MODULE_NAME MODULE_SIP [library1, libaray2, ...]) -# Specifies a SIP file to be built into a Python module and installed. -# MODULE_NAME is the name of Python module including any path name. (e.g. -# os.sys, Foo.bar etc). MODULE_SIP the path and filename of the .sip file -# to process and compile. libraryN are libraries that the Python module, -# which is typically a shared library, should be linked to. The built -# module will also be install into Python's site-packages directory. -# -# The behaviour of the ADD_SIP_PYTHON_MODULE macro can be controlled by a -# number of variables: -# -# SIP_INCLUDE_DIRS - List of directories which SIP will scan through when looking -# for included .sip files. (Corresponds to the -I option for SIP.) -# -# SIP_TAGS - List of tags to define when running SIP. (Corresponds to the -t -# option for SIP.) -# -# SIP_CONCAT_PARTS - An integer which defines the number of parts the C++ code -# of each module should be split into. Defaults to 8. (Corresponds to the -# -j option for SIP.) -# -# SIP_DISABLE_FEATURES - List of feature names which should be disabled -# running SIP. (Corresponds to the -x option for SIP.) -# -# SIP_EXTRA_OPTIONS - Extra command line options which should be passed on to -# SIP. -SET(SIP_INCLUDE_DIRS) -SET(SIP_TAGS) -SET(SIP_CONCAT_PARTS 8) -SET(SIP_DISABLE_FEATURES) -SET(SIP_EXTRA_OPTIONS) - -MACRO(ADD_SIP_PYTHON_MODULE MODULE_NAME MODULE_SIP) - - SET(EXTRA_LINK_LIBRARIES ${ARGN}) - - STRING(REPLACE "." "/" _x ${MODULE_NAME}) - GET_FILENAME_COMPONENT(_parent_module_path ${_x} PATH) - GET_FILENAME_COMPONENT(_child_module_name ${_x} NAME) - - GET_FILENAME_COMPONENT(_module_path ${MODULE_SIP} PATH) - GET_FILENAME_COMPONENT(_abs_module_sip ${MODULE_SIP} ABSOLUTE) - - # We give this target a long logical target name. - # (This is to avoid having the library name clash with any already - # install library names. If that happens then cmake dependency - # tracking get confused.) - STRING(REPLACE "." "_" _logical_name ${MODULE_NAME}) - SET(_logical_name "python_module_${_logical_name}") - - FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_module_path}) # Output goes in this dir. - - SET(_sip_includes) - FOREACH (_inc ${SIP_INCLUDES}) - GET_FILENAME_COMPONENT(_abs_inc ${_inc} ABSOLUTE) - LIST(APPEND _sip_includes -I ${_abs_inc}) - ENDFOREACH (_inc ) - - SET(_sip_tags) - FOREACH (_tag ${SIP_TAGS}) - LIST(APPEND _sip_tags -t ${_tag}) - ENDFOREACH (_tag) - - SET(_sip_x) - FOREACH (_x ${SIP_DISABLE_FEATURES}) - LIST(APPEND _sip_x -x ${_x}) - ENDFOREACH (_x ${SIP_DISABLE_FEATURES}) - - SET(_message "-DMESSAGE=Generating CPP code for module ${MODULE_NAME}") - SET(_sip_output_files) - FOREACH(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS} ) - IF( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS} ) - SET(_sip_output_files ${_sip_output_files} ${CMAKE_CURRENT_BINARY_DIR}/${_module_path}/sip${_child_module_name}part${CONCAT_NUM}.cpp ) - ENDIF( ${CONCAT_NUM} LESS ${SIP_CONCAT_PARTS} ) - ENDFOREACH(CONCAT_NUM RANGE 0 ${SIP_CONCAT_PARTS} ) - - # Suppress warnings - IF(PEDANTIC) - IF(MSVC) - # 4996 deprecation warnings (bindings re-export deprecated methods) - # 4701 potentially uninitialized variable used (sip generated code) - # 4702 unreachable code (sip generated code) - ADD_DEFINITIONS( /wd4996 /wd4701 /wd4702 ) - ELSE(MSVC) - # disable all warnings - ADD_DEFINITIONS( -w ) - ENDIF(MSVC) - ENDIF(PEDANTIC) - - ADD_CUSTOM_COMMAND( - OUTPUT ${_sip_output_files} - COMMAND ${CMAKE_COMMAND} -E echo ${message} - COMMAND ${CMAKE_COMMAND} -E touch ${_sip_output_files} - COMMAND ${SIP_EXECUTABLE} ${_sip_tags} ${_sip_x} ${SIP_EXTRA_OPTIONS} -j ${SIP_CONCAT_PARTS} -c ${CMAKE_CURRENT_BINARY_DIR}/${_module_path} ${_sip_includes} ${_abs_module_sip} - DEPENDS ${_abs_module_sip} ${SIP_EXTRA_FILES_DEPEND} +set(SIPCMD ${SIP_BUILD_EXECUTABLE}) + +macro(sanitize_list var_list) + if(${var_list}) + list(REMOVE_DUPLICATES ${var_list}) + list(REMOVE_ITEM ${var_list} "") + list(TRANSFORM ${var_list} PREPEND "\"") + list(TRANSFORM ${var_list} APPEND "\"") + list(JOIN ${var_list} ", " ${var_list}) + set(${var_list} "${${var_list}}, ") + else() + set(${var_list} "") + endif() +endmacro() + +function(add_sip_module MODULE_TARGET) + message(STATUS "SIP: Generating pyproject.toml") + configure_file(${CMAKE_SOURCE_DIR}/pyproject.toml.in ${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml) + configure_file(${CMAKE_SOURCE_DIR}/CMakeBuilder.py ${CMAKE_CURRENT_BINARY_DIR}/CMakeBuilder.py) + + message(STATUS "SIP: Generating source files") + execute_process( + COMMAND ${SIPCMD} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ ) - ADD_LIBRARY(${_logical_name} MODULE ${_sip_output_files} ${SIP_EXTRA_SOURCE_FILES}) - IF (NOT APPLE) - IF ("${Python3_VERSION_MINOR}" GREATER 7) - MESSAGE(STATUS "Python > 3.7 - not linking to libpython") - ELSE () - TARGET_LINK_LIBRARIES(${_logical_name} ${Python3_LIBRARIES}) - ENDIF () - ENDIF (NOT APPLE) - TARGET_LINK_LIBRARIES(${_logical_name} ${EXTRA_LINK_LIBRARIES}) - IF (APPLE) - SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") - ENDIF (APPLE) - SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES PREFIX "" OUTPUT_NAME ${_child_module_name}) - - IF (WIN32) - SET_TARGET_PROPERTIES(${_logical_name} PROPERTIES SUFFIX ".pyd" IMPORT_PREFIX "_") - ENDIF (WIN32) - - INSTALL(TARGETS ${_logical_name} DESTINATION "${Python3_SITEARCH}/${_parent_module_path}") - -ENDMACRO(ADD_SIP_PYTHON_MODULE) + # This will generate the source-files during the configuration step in CMake. Needed to obtain the sources + + # Touch the generated files (8 in total) to make them dirty and force them to rebuild + message(STATUS "SIP: Touching the source files") + set(_sip_output_files) + list(LENGTH SIP_FILES _no_outputfiles) + foreach(_concat_file_nr RANGE 0 ${_no_outputfiles}) + if(${_concat_file_nr} LESS 8) + list(APPEND _sip_output_files "${CMAKE_CURRENT_BINARY_DIR}/${MODULE_TARGET}/${MODULE_TARGET}/sip${MODULE_TARGET}part${_concat_file_nr}.cpp") + endif() + endforeach() + + # Find the generated source files + message(STATUS "SIP: Collecting the generated source files") + file(GLOB sip_c "${CMAKE_CURRENT_BINARY_DIR}/${MODULE_TARGET}/${MODULE_TARGET}/*.c") + file(GLOB sip_cpp "${CMAKE_CURRENT_BINARY_DIR}/${MODULE_TARGET}/${MODULE_TARGET}/*.cpp") + file(GLOB sip_hdr "${CMAKE_CURRENT_BINARY_DIR}/${MODULE_TARGET}/${MODULE_TARGET}/*.h") + + # Add the user specified source files + message(STATUS "SIP: Collecting the user specified source files") + get_target_property(usr_src ${MODULE_TARGET} SOURCES) + + # 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}" "${usr_src}") + add_library("sip_${MODULE_TARGET}" SHARED ${sip_sources}) + + # 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}") + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES PREFIX "") + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES OUTPUT_NAME "${MODULE_TARGET}") + + # 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( + TARGET "sip_${MODULE_TARGET}" + COMMAND ${SIPCMD} + COMMAND ${CMAKE_COMMAND} -E touch ${_sip_output_files} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ + MAIN_DEPENDENCY ${MODULE_SIP} + DEPENDS ${sip_sources} + VERBATIM + ) +endfunction() \ No newline at end of file From ba6b5a6c55a4331a47fb4fbf3995dff6fbc3b4b5 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 24 Feb 2022 11:14:37 +0100 Subject: [PATCH 04/64] Dressed down the pyproject.toml.in file some more These are not needed for 'just' code generation Contributes to CURA-7924 --- pyproject.toml.in | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyproject.toml.in b/pyproject.toml.in index d9b50006..81a85f33 100644 --- a/pyproject.toml.in +++ b/pyproject.toml.in @@ -12,9 +12,6 @@ sip-include-dirs = ["CMAKE_CURRENT_SOURCE_DIR/python/"] build-dir = "${CMAKE_CURRENT_BINARY_DIR}/pyArcus/" [tool.sip.bindings.pyArcus] -headers = ["PythonMessage.h"] -include-dirs = ["${CMAKE_CURRENT_SOURCE_DIR}/python/"] -sources = ["${CMAKE_CURRENT_SOURCE_DIR}/python/PythonMessage.cpp"] exceptions = true release-gil = true concatenate = 8 \ No newline at end of file From d16dc5558977db41f9348e6516a55e40bdf27913 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 24 Feb 2022 11:15:34 +0100 Subject: [PATCH 05/64] Renamed the main sip defintion file to reflect the module_name Contributes to CURA-7924 --- python/{Socket.sip => pyArcus.sip} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename python/{Socket.sip => pyArcus.sip} (97%) diff --git a/python/Socket.sip b/python/pyArcus.sip similarity index 97% rename from python/Socket.sip rename to python/pyArcus.sip index 5603c663..aea4f8c4 100644 --- a/python/Socket.sip +++ b/python/pyArcus.sip @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -%Module(name = Arcus, call_super_init = True) +%Module(name = pyArcus, call_super_init = True) %Include Types.sip %Include SocketListener.sip From 3799ae740baf6f649903f55e9f496f9737926fa3 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 24 Feb 2022 11:20:04 +0100 Subject: [PATCH 06/64] Use the new CMake module add_sip_module These changes are not fully tested locally. This is due to the way I have personally setup my development environment. This should generate a python module named `pyArcus.so` linking to in Arcus.so both located in the build directory. TODO: Add installing step. TODO: propagate the name change to downstream dependencies Contributes to CURA-7924 --- CMakeLists.txt | 66 ++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a699a722..00c81479 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ project(arcus) -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.18) include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -21,29 +21,6 @@ find_package(Protobuf 3.0.0 REQUIRED) set(CMAKE_POSITION_INDEPENDENT_CODE ON) #Required if a patch to libArcus needs to be made via templates. -if(BUILD_PYTHON) - list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) - - if(NOT DEFINED Python_VERSION) - set(Python_VERSION - 3.10 - CACHE STRING "Python Version" FORCE) - message(STATUS "Setting Python version to ${Python_VERSION}. Set Python_VERSION if you want to compile against an other version.") - 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(SIP REQUIRED) - if(NOT DEFINED LIB_SUFFIX) - set(LIB_SUFFIX "") - endif() - - include_directories(python/ src/ ${SIP_INCLUDE_DIRS} ${Python_INCLUDE_DIRS}) -endif() - set(CMAKE_CXX_STANDARD 17) if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") @@ -96,13 +73,6 @@ if(MSVC_STATIC_RUNTIME) endforeach(flag_var) endif() -if(BUILD_PYTHON) - set(SIP_EXTRA_FILES_DEPEND python/SocketListener.sip python/Types.sip python/PythonMessage.sip python/Error.sip) - set(SIP_EXTRA_SOURCE_FILES python/PythonMessage.cpp) - set(SIP_EXTRA_OPTIONS -g -n PyQt5.sip) # -g means always release the GIL before calling C++ methods. -n PyQt5.sip is required to not get the PyCapsule error - add_sip_python_module(Arcus python/Socket.sip Arcus) -endif() - target_include_directories(Arcus PUBLIC $ $ @@ -163,4 +133,36 @@ install(FILES DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Arcus ) -include(CPackConfig.cmake) +# Create the Python bindings +if(BUILD_PYTHON) + list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) + + if(NOT DEFINED Python_VERSION) + set(Python_VERSION + 3.10 + CACHE STRING "Python Version" FORCE) + message(STATUS "Setting Python version to ${Python_VERSION}. Set Python_VERSION if you want to compile against an other version.") + 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(SIP REQUIRED 6.5.0) + + add_library(pyArcus INTERFACE ${CMAKE_SOURCE_DIR}/python/PythonMessage.cpp) + + target_include_directories(pyArcus + INTERFACE + $ + $ + ) + + target_compile_features(pyArcus INTERFACE cxx_std_17) + target_link_libraries(pyArcus INTERFACE Arcus protobuf::protobuf Python::Python) + + add_sip_module(pyArcus) +endif() + +include(CPackConfig.cmake) \ No newline at end of file From 531623457e16571dcf6caa3cf0c32ad611b54458 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Thu, 24 Feb 2022 14:25:18 +0100 Subject: [PATCH 07/64] Link Arcus against protobuf target Contributes to CURA_7924 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00c81479..21ee7be4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,7 @@ target_include_directories(Arcus PUBLIC $ ${PROTOBUF_INCLUDE_DIR} ) -target_link_libraries(Arcus PUBLIC ${PROTOBUF_LIBRARIES}) +target_link_libraries(Arcus PUBLIC protobuf::libprotobuf) if(WIN32) add_definitions(-D_WIN32_WINNT=0x0600) # Declare we require Vista or higher, this allows us to use IPv6 functions. From b3202a29f23056c29a8c81c22c50c58967afb76b Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Thu, 24 Feb 2022 14:26:07 +0100 Subject: [PATCH 08/64] Use the CMAKE_SOURCE_DIR for including the SIPMacros Contributes to CURA_7924 --- cmake/FindSIP.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FindSIP.cmake b/cmake/FindSIP.cmake index ad9e4d11..2bac14e0 100644 --- a/cmake/FindSIP.cmake +++ b/cmake/FindSIP.cmake @@ -53,7 +53,7 @@ ELSE(SIP_VERSION) IF(NOT SIP_FIND_QUIETLY) MESSAGE(STATUS "Found SIP version: ${SIP_VERSION_STR}") ENDIF(NOT SIP_FIND_QUIETLY) - include(${CMAKE_CURRENT_SOURCE_DIR}/SIPMacros.cmake) + include(${CMAKE_SOURCE_DIR}/cmake/SIPMacros.cmake) ELSE(SIP_FOUND) IF(SIP_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Could not find SIP") From 8f715585997fdd59587e8f6c8621277e8e35a305 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Thu, 24 Feb 2022 14:27:41 +0100 Subject: [PATCH 09/64] Add the current bin directory to the PYTHONPATH It can't find the CMakeBuilder.py on the build server otherwise Contributes to CURA_7924 --- cmake/SIPMacros.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index ff9736e9..50f4abc9 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -1,7 +1,7 @@ # Macros for SIP # ~~~~~~~~~~~~~~ -set(SIPCMD ${SIP_BUILD_EXECUTABLE}) +set(SIP_ARGS --pep484-pyi --no-protected-is-public) macro(sanitize_list var_list) if(${var_list}) @@ -22,10 +22,14 @@ function(add_sip_module MODULE_TARGET) configure_file(${CMAKE_SOURCE_DIR}/CMakeBuilder.py ${CMAKE_CURRENT_BINARY_DIR}/CMakeBuilder.py) message(STATUS "SIP: Generating source files") + set(OLD_PYTHONPATH $ENV{PYTHONPATH}) + set(ENV{PYTHONPATH} "$ENV{PYTHONPATH}:${CMAKE_CURRENT_BINARY_DIR}") execute_process( - COMMAND ${SIPCMD} + COMMAND ${SIP_BUILD_EXECUTABLE} ${SIP_ARGS} + COMMAND_ECHO STDOUT WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ ) + set(ENV{PYTHONPATH} ${OLD_PYTHONPATH}) # This will generate the source-files during the configuration step in CMake. Needed to obtain the sources # Touch the generated files (8 in total) to make them dirty and force them to rebuild From e173335ad592659a2dd31f6ad5fbcae156378322 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Thu, 24 Feb 2022 14:41:40 +0100 Subject: [PATCH 10/64] Make sure the extension is so on UNIX and pyd on Windows Contributes to CURA_7924 --- cmake/SIPMacros.cmake | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 50f4abc9..87d3205a 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -60,6 +60,12 @@ function(add_sip_module MODULE_TARGET) # 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}") set_target_properties("sip_${MODULE_TARGET}" PROPERTIES PREFIX "") + if(WIN32) + set(ext .pyd) + else() + set(ext .so) + endif() + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES SUFFIX ${ext}) set_target_properties("sip_${MODULE_TARGET}" PROPERTIES OUTPUT_NAME "${MODULE_TARGET}") # Add the custom command to (re-)generate the files and mark them as dirty. This allows the user to actually work From 4ba57f24c5e7879f202d2b205b5df0d84869e96b Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 24 Feb 2022 16:06:10 +0100 Subject: [PATCH 11/64] Use OS specific seperator for the PYTHONPATH Contributes to CURA-7924 --- cmake/SIPMacros.cmake | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 87d3205a..6aa67ccb 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -20,10 +20,17 @@ function(add_sip_module MODULE_TARGET) message(STATUS "SIP: Generating pyproject.toml") configure_file(${CMAKE_SOURCE_DIR}/pyproject.toml.in ${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml) configure_file(${CMAKE_SOURCE_DIR}/CMakeBuilder.py ${CMAKE_CURRENT_BINARY_DIR}/CMakeBuilder.py) + if(WIN32) + set(ext .pyd) + set(env_path_sep ";") + else() + set(ext .so) + set(env_path_sep ":") + endif() message(STATUS "SIP: Generating source files") set(OLD_PYTHONPATH $ENV{PYTHONPATH}) - set(ENV{PYTHONPATH} "$ENV{PYTHONPATH}:${CMAKE_CURRENT_BINARY_DIR}") + set(ENV{PYTHONPATH} "$ENV{PYTHONPATH}${env_path_sep}${CMAKE_CURRENT_BINARY_DIR}") execute_process( COMMAND ${SIP_BUILD_EXECUTABLE} ${SIP_ARGS} COMMAND_ECHO STDOUT @@ -60,11 +67,6 @@ function(add_sip_module MODULE_TARGET) # 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}") set_target_properties("sip_${MODULE_TARGET}" PROPERTIES PREFIX "") - if(WIN32) - set(ext .pyd) - else() - set(ext .so) - endif() set_target_properties("sip_${MODULE_TARGET}" PROPERTIES SUFFIX ${ext}) set_target_properties("sip_${MODULE_TARGET}" PROPERTIES OUTPUT_NAME "${MODULE_TARGET}") From 337d180cd755fdc53d774ca07d96d3313acb2a79 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 24 Feb 2022 16:31:10 +0100 Subject: [PATCH 12/64] Setting the PYTHONPATH with the CMAKE_COMMAND This should add the current build_dir to the PYTHONPATH Contributes to CURA-7924 --- cmake/SIPMacros.cmake | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 6aa67ccb..e40c06bc 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -29,14 +29,11 @@ function(add_sip_module MODULE_TARGET) endif() message(STATUS "SIP: Generating source files") - set(OLD_PYTHONPATH $ENV{PYTHONPATH}) - set(ENV{PYTHONPATH} "$ENV{PYTHONPATH}${env_path_sep}${CMAKE_CURRENT_BINARY_DIR}") execute_process( - COMMAND ${SIP_BUILD_EXECUTABLE} ${SIP_ARGS} + COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=$ENV{PYTHONPATH}${env_path_sep}${CMAKE_CURRENT_BINARY_DIR} ${SIP_BUILD_EXECUTABLE} ${SIP_ARGS} COMMAND_ECHO STDOUT WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ ) - set(ENV{PYTHONPATH} ${OLD_PYTHONPATH}) # This will generate the source-files during the configuration step in CMake. Needed to obtain the sources # Touch the generated files (8 in total) to make them dirty and force them to rebuild @@ -74,7 +71,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 ${SIPCMD} + COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=$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 c61b68a0da8f6c0134959bb14b82db5624d538bb Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 24 Feb 2022 17:02:36 +0100 Subject: [PATCH 13/64] Changes needed for Windows compilation. Arcus (non-py version) still seems to be static though, so it doesn't work yet completely. part of CURA-7924 --- CMakeLists.txt | 2 +- cmake/SIPMacros.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21ee7be4..90703d5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,7 +160,7 @@ if(BUILD_PYTHON) ) target_compile_features(pyArcus INTERFACE cxx_std_17) - target_link_libraries(pyArcus INTERFACE Arcus protobuf::protobuf Python::Python) + target_link_libraries(pyArcus INTERFACE Arcus protobuf::libprotobuf Python::Python) add_sip_module(pyArcus) endif() diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index e40c06bc..10beddc7 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -30,7 +30,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=$ENV{PYTHONPATH}${env_path_sep}${CMAKE_CURRENT_BINARY_DIR}" ${SIP_BUILD_EXECUTABLE} ${SIP_ARGS} COMMAND_ECHO STDOUT WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ ) @@ -71,7 +71,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=$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 5751f92b8f03e6488a8655e99b2d18775345295e Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 24 Feb 2022 17:40:06 +0100 Subject: [PATCH 14/64] Nescesary for proper functioning .pyd on Windows. Not tested on MacOS. part of CURA-7924 --- CMakeLists.txt | 2 ++ cmake/SIPMacros.cmake | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90703d5b..898aff50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ option(BUILD_PYTHON "Build " ON) option(BUILD_EXAMPLES "Build the example programs" ON) option(BUILD_STATIC "Build as a static library" OFF) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + if(WIN32) option(MSVC_STATIC_RUNTIME "Link the MSVC runtime statically" OFF) endif() diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 10beddc7..d3fd7485 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -64,7 +64,7 @@ function(add_sip_module MODULE_TARGET) # 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}") set_target_properties("sip_${MODULE_TARGET}" PROPERTIES PREFIX "") - set_target_properties("sip_${MODULE_TARGET}" PROPERTIES SUFFIX ${ext}) + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES IMPORT_SUFFIX ${ext}) set_target_properties("sip_${MODULE_TARGET}" PROPERTIES OUTPUT_NAME "${MODULE_TARGET}") # Add the custom command to (re-)generate the files and mark them as dirty. This allows the user to actually work From ea70846f5347f2ca4b84a3a7c68f3caaca19f992 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 24 Feb 2022 20:28:31 +0100 Subject: [PATCH 15/64] This wasn't producng a proper dynamic library, not even on Windows. part of CURA-7924 --- cmake/SIPMacros.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index d3fd7485..10beddc7 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -64,7 +64,7 @@ function(add_sip_module MODULE_TARGET) # 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}") set_target_properties("sip_${MODULE_TARGET}" PROPERTIES PREFIX "") - set_target_properties("sip_${MODULE_TARGET}" PROPERTIES IMPORT_SUFFIX ${ext}) + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES SUFFIX ${ext}) set_target_properties("sip_${MODULE_TARGET}" PROPERTIES OUTPUT_NAME "${MODULE_TARGET}") # Add the custom command to (re-)generate the files and mark them as dirty. This allows the user to actually work From 50bc1795812260cbdae10e6c0b0730769103a7b2 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 25 Feb 2022 07:40:16 +0100 Subject: [PATCH 16/64] Always include SIPMacros when find_package(SIP) is called Contributes to CURA-7924 --- cmake/FindSIP.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FindSIP.cmake b/cmake/FindSIP.cmake index 2bac14e0..f5198902 100644 --- a/cmake/FindSIP.cmake +++ b/cmake/FindSIP.cmake @@ -53,7 +53,6 @@ ELSE(SIP_VERSION) IF(NOT SIP_FIND_QUIETLY) MESSAGE(STATUS "Found SIP version: ${SIP_VERSION_STR}") ENDIF(NOT SIP_FIND_QUIETLY) - include(${CMAKE_SOURCE_DIR}/cmake/SIPMacros.cmake) ELSE(SIP_FOUND) IF(SIP_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Could not find SIP") @@ -62,4 +61,5 @@ ELSE(SIP_VERSION) ENDIF(SIP_VERSION) +include(${CMAKE_SOURCE_DIR}/cmake/SIPMacros.cmake) ADD_DEFINITIONS(-DSIP_VERSION=0x${SIP_VERSION}) From 104968b61e70d9b899f45cf8b588064ebe7be7e7 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 25 Feb 2022 07:43:11 +0100 Subject: [PATCH 17/64] Moved CMakeBuilder to CMake build module location This file isn't project specific but an integral part of how the CMake SIP build module works. Contributes to CURA-7924 --- CMakeBuilder.py => cmake/CMakeBuilder.py | 0 cmake/SIPMacros.cmake | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename CMakeBuilder.py => cmake/CMakeBuilder.py (100%) diff --git a/CMakeBuilder.py b/cmake/CMakeBuilder.py similarity index 100% rename from CMakeBuilder.py rename to cmake/CMakeBuilder.py diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 10beddc7..740d5094 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -19,7 +19,7 @@ endmacro() function(add_sip_module MODULE_TARGET) message(STATUS "SIP: Generating pyproject.toml") configure_file(${CMAKE_SOURCE_DIR}/pyproject.toml.in ${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml) - configure_file(${CMAKE_SOURCE_DIR}/CMakeBuilder.py ${CMAKE_CURRENT_BINARY_DIR}/CMakeBuilder.py) + configure_file(${CMAKE_SOURCE_DIR}/cmake/CMakeBuilder.py ${CMAKE_CURRENT_BINARY_DIR}/CMakeBuilder.py) if(WIN32) set(ext .pyd) set(env_path_sep ";") From 12d420d247d7b16beba82ba8b632aa2a547cde76 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 25 Feb 2022 08:35:10 +0100 Subject: [PATCH 18/64] Added a install_sip_module to SIP CMake build module This will install the Python module and PEP 484 file in site-packages Contributes to CURA-7924 --- CMakeLists.txt | 1 + cmake/SIPMacros.cmake | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 898aff50..1ce277b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,6 +165,7 @@ if(BUILD_PYTHON) target_link_libraries(pyArcus INTERFACE Arcus protobuf::libprotobuf Python::Python) add_sip_module(pyArcus) + install_sip_module(pyArcus) endif() include(CPackConfig.cmake) \ No newline at end of file diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 740d5094..a9c1a668 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -78,4 +78,29 @@ function(add_sip_module MODULE_TARGET) DEPENDS ${sip_sources} VERBATIM ) + + set_target_properties("sip_${MODULE_TARGET}" + PROPERTIES + RESOURCE "${CMAKE_CURRENT_BINARY_DIR}/${MODULE_TARGET}/${MODULE_TARGET}/${MODULE_TARGET}.pyi") +endfunction() + +function(install_sip_module MODULE_TARGET) + if(DEFINED ARGV1) + set(_install_path ${ARGV1}) + else() + if(DEFINED Python_SITEARCH) + set(_install_path ${Python_SITEARCH}) + elseif(DEFINED Python_SITELIB) + set(_install_path ${Python_SITELIB}) + else() + message(FATAL_ERROR "SIP: Specify the site-packages location") + endif() + endif() + message(STATUS "SIP: Installing Python module and PEP 484 file in ${_install_path}") + install(TARGETS "sip_${MODULE_TARGET}" + ARCHIVE DESTINATION ${_install_path} + LIBRARY DESTINATION ${_install_path} + RUNTIME DESTINATION ${_install_path} + RESOURCE DESTINATION ${_install_path} + ) endfunction() \ No newline at end of file From b1325c9957d02a1f1b48bf019a01babb79e56e88 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 25 Feb 2022 08:38:16 +0100 Subject: [PATCH 19/64] Use the actual Python defined SO ABI extension Which is basically a call to sysconfig made by the find_package Python and outputs the following extension ```python sysconfig.get_config_var('EXT_SUFFIX') '.cpython-310-x86_64-linux-gnu.so' ``` Contributes to CURA-7924 --- cmake/SIPMacros.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index a9c1a668..e997396e 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -21,10 +21,8 @@ function(add_sip_module MODULE_TARGET) configure_file(${CMAKE_SOURCE_DIR}/pyproject.toml.in ${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml) configure_file(${CMAKE_SOURCE_DIR}/cmake/CMakeBuilder.py ${CMAKE_CURRENT_BINARY_DIR}/CMakeBuilder.py) if(WIN32) - set(ext .pyd) set(env_path_sep ";") else() - set(ext .so) set(env_path_sep ":") endif() @@ -64,7 +62,7 @@ function(add_sip_module MODULE_TARGET) # 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}") set_target_properties("sip_${MODULE_TARGET}" PROPERTIES PREFIX "") - set_target_properties("sip_${MODULE_TARGET}" PROPERTIES SUFFIX ${ext}) + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES SUFFIX ${Python_SOABI}) set_target_properties("sip_${MODULE_TARGET}" PROPERTIES OUTPUT_NAME "${MODULE_TARGET}") # Add the custom command to (re-)generate the files and mark them as dirty. This allows the user to actually work From 95a2a26935b6fd89b3fcac931119e0d48812ded2 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 25 Feb 2022 09:38:46 +0100 Subject: [PATCH 20/64] Make user cpp sources optional Not necessary for Arcus, but Savitar doesn't use user specified cpp files and I think it's good practice to keep these modules in-sync. Contributes to CURA-7924 --- cmake/SIPMacros.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index e997396e..fe216d22 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -56,7 +56,11 @@ 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}" "${usr_src}") + set(sip_sources "${sip_c}" "${sip_cpp}") + set(sip_sources "${sip_c}" "${sip_cpp}") + if(usr_src) + list(APPEND sip_source "${usr_src}") + endif() add_library("sip_${MODULE_TARGET}" SHARED ${sip_sources}) # Make sure that the library name of the target is the same as the MODULE_TARGET with the appropriate extension From 287c7e50e168d0fdf0a43effc19027296f23776b Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Fri, 25 Feb 2022 10:13:28 +0100 Subject: [PATCH 21/64] If the sip build is not pre-set it should be here. part of CURA-7924 --- cmake/SIPMacros.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index fe216d22..c1fdf1cd 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -17,6 +17,10 @@ macro(sanitize_list var_list) endmacro() function(add_sip_module MODULE_TARGET) + if(NOT SIP_BUILD_EXECUTABLE) + set(SIP_BUILD_EXECUTABLE ${CMAKE_PREFIX_PATH}/Scripts/sip-build) + endif() + message(STATUS "SIP: Generating pyproject.toml") configure_file(${CMAKE_SOURCE_DIR}/pyproject.toml.in ${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml) configure_file(${CMAKE_SOURCE_DIR}/cmake/CMakeBuilder.py ${CMAKE_CURRENT_BINARY_DIR}/CMakeBuilder.py) From ee282bd4c6612ba4ecf98219aa4db9489348275a Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Fri, 25 Feb 2022 10:35:59 +0100 Subject: [PATCH 22/64] Revert "Make user cpp sources optional" This reverts commit 95a2a26935b6fd89b3fcac931119e0d48812ded2. --- cmake/SIPMacros.cmake | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index c1fdf1cd..0401d95e 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -60,11 +60,7 @@ 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}") - set(sip_sources "${sip_c}" "${sip_cpp}") - if(usr_src) - list(APPEND sip_source "${usr_src}") - endif() + set(sip_sources "${sip_c}" "${sip_cpp}" "${usr_src}") add_library("sip_${MODULE_TARGET}" SHARED ${sip_sources}) # Make sure that the library name of the target is the same as the MODULE_TARGET with the appropriate extension From 2aa1e48adedb6843a90cba76f6259cb940a5f7c5 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Fri, 25 Feb 2022 11:06:55 +0100 Subject: [PATCH 23/64] Revert "Use the actual Python defined SO ABI extension" This reverts commit b1325c9957d02a1f1b48bf019a01babb79e56e88. --- cmake/SIPMacros.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 0401d95e..3fb5af03 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -25,8 +25,10 @@ function(add_sip_module MODULE_TARGET) configure_file(${CMAKE_SOURCE_DIR}/pyproject.toml.in ${CMAKE_CURRENT_BINARY_DIR}/pyproject.toml) configure_file(${CMAKE_SOURCE_DIR}/cmake/CMakeBuilder.py ${CMAKE_CURRENT_BINARY_DIR}/CMakeBuilder.py) if(WIN32) + set(ext .pyd) set(env_path_sep ";") else() + set(ext .so) set(env_path_sep ":") endif() @@ -66,7 +68,7 @@ function(add_sip_module MODULE_TARGET) # 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}") set_target_properties("sip_${MODULE_TARGET}" PROPERTIES PREFIX "") - set_target_properties("sip_${MODULE_TARGET}" PROPERTIES SUFFIX ${Python_SOABI}) + set_target_properties("sip_${MODULE_TARGET}" PROPERTIES SUFFIX ${ext}) set_target_properties("sip_${MODULE_TARGET}" PROPERTIES OUTPUT_NAME "${MODULE_TARGET}") # Add the custom command to (re-)generate the files and mark them as dirty. This allows the user to actually work From 0c62785b79d532b71ad87e047030c0077088d353 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 25 Feb 2022 11:46:04 +0100 Subject: [PATCH 24/64] Remove redundant sanitize_list macro Contributes to CURA-7924 --- cmake/SIPMacros.cmake | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 3fb5af03..b7bd7aa4 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -3,19 +3,6 @@ set(SIP_ARGS --pep484-pyi --no-protected-is-public) -macro(sanitize_list var_list) - if(${var_list}) - list(REMOVE_DUPLICATES ${var_list}) - list(REMOVE_ITEM ${var_list} "") - list(TRANSFORM ${var_list} PREPEND "\"") - list(TRANSFORM ${var_list} APPEND "\"") - list(JOIN ${var_list} ", " ${var_list}) - set(${var_list} "${${var_list}}, ") - else() - set(${var_list} "") - endif() -endmacro() - function(add_sip_module MODULE_TARGET) if(NOT SIP_BUILD_EXECUTABLE) set(SIP_BUILD_EXECUTABLE ${CMAKE_PREFIX_PATH}/Scripts/sip-build) From b991cc7703e9400120922dc216636f0250e03b4e Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Fri, 25 Feb 2022 14:24:18 +0100 Subject: [PATCH 25/64] Sip 6 can handle enum class. Also, in earlier sip 4.x it was 'transparent' but now if you add that 'fix' of wrapping it in a namespace, you also have to refer to the namespace in Python, making awkward constructs like pyArcus.SocketState.SocketState.Closed or whatever. done as part of CURA-7924 --- examples/example.cpp | 2 +- python/Error.sip | 37 +++++++++++++++----------------- python/SocketListener.sip | 2 +- python/Types.sip | 21 ++++++++----------- python/pyArcus.sip | 2 +- src/Error.cpp | 4 ++-- src/Error.h | 44 ++++++++++++++++++--------------------- src/Socket.cpp | 2 +- src/Socket.h | 2 +- src/SocketListener.h | 2 +- src/Socket_p.h | 12 +++++------ src/Types.h | 24 +++++++++------------ 12 files changed, 70 insertions(+), 84 deletions(-) diff --git a/examples/example.cpp b/examples/example.cpp index f3a7defd..dc578338 100644 --- a/examples/example.cpp +++ b/examples/example.cpp @@ -20,7 +20,7 @@ struct Object class Listener : public Arcus::SocketListener { public: - void stateChanged(Arcus::SocketState::SocketState new_state) + void stateChanged(Arcus::SocketState new_state) { std::cout << "State Changed: " << new_state << std::endl; } diff --git a/python/Error.sip b/python/Error.sip index f996704e..56f585b3 100644 --- a/python/Error.sip +++ b/python/Error.sip @@ -16,25 +16,22 @@ * along with this program. If not, see . */ -namespace ErrorCode +enum class ErrorCode { - enum ErrorCode - { - UnknownError, - CreationError, - ConnectFailedError, - BindFailedError, - AcceptFailedError, - SendFailedError, - ReceiveFailedError, - UnknownMessageTypeError, - ParseFailedError, - ConnectionResetError, - MessageRegistrationFailedError, - InvalidStateError, - InvalidMessageError, - Debug, - }; + UnknownError, + CreationError, + ConnectFailedError, + BindFailedError, + AcceptFailedError, + SendFailedError, + ReceiveFailedError, + UnknownMessageTypeError, + ParseFailedError, + ConnectionResetError, + MessageRegistrationFailedError, + InvalidStateError, + InvalidMessageError, + Debug, }; class Error @@ -45,10 +42,10 @@ class Error public: Error(); - Error(ErrorCode::ErrorCode error_code, const std::string& error_message); + Error(ErrorCode error_code, const std::string& error_message); Error(const Error& error); - ErrorCode::ErrorCode getErrorCode() const; + ErrorCode getErrorCode() const; std::string getErrorMessage() const; bool isFatalError() const; bool isValid() const; diff --git a/python/SocketListener.sip b/python/SocketListener.sip index a3f28e09..fcc86ffb 100644 --- a/python/SocketListener.sip +++ b/python/SocketListener.sip @@ -28,7 +28,7 @@ public: Socket* getSocket(); - virtual void stateChanged(SocketState::SocketState newState) = 0 /HoldGIL/; + virtual void stateChanged(SocketState newState) = 0 /HoldGIL/; virtual void messageReceived() = 0 /HoldGIL/; virtual void error(const Error& error) = 0 /HoldGIL/; }; diff --git a/python/Types.sip b/python/Types.sip index ada586ca..5f1deed4 100644 --- a/python/Types.sip +++ b/python/Types.sip @@ -134,17 +134,14 @@ #include "Types.h" %End -namespace SocketState +enum class SocketState { - enum SocketState - { - Initial, - Connecting, - Connected, - Opening, - Listening, - Closing, - Closed, - Error - }; + Initial, + Connecting, + Connected, + Opening, + Listening, + Closing, + Closed, + Error }; diff --git a/python/pyArcus.sip b/python/pyArcus.sip index aea4f8c4..5fa6caa0 100644 --- a/python/pyArcus.sip +++ b/python/pyArcus.sip @@ -37,7 +37,7 @@ public: Socket(); virtual ~Socket(); - SocketState::SocketState getState() const; + SocketState getState() const; Error getLastError() const; void clearError(); diff --git a/src/Error.cpp b/src/Error.cpp index 4acbe183..62bf73a4 100644 --- a/src/Error.cpp +++ b/src/Error.cpp @@ -26,14 +26,14 @@ Arcus::Error::Error() { } -Arcus::Error::Error(ErrorCode::ErrorCode error_code, const std::string& error_message) +Arcus::Error::Error(ErrorCode error_code, const std::string& error_message) : _error_code(ErrorCode::UnknownError), _fatal_error(false), _native_error_code(0) { _error_code = error_code; _error_message = error_message; } -ErrorCode::ErrorCode Arcus::Error::getErrorCode() const +ErrorCode Arcus::Error::getErrorCode() const { return _error_code; } diff --git a/src/Error.h b/src/Error.h index b2bca19c..13b6ac42 100644 --- a/src/Error.h +++ b/src/Error.h @@ -26,28 +26,24 @@ namespace Arcus { /** * Possible error codes. - */ - namespace ErrorCode + */ + enum class ErrorCode { - // Note: Not using enum class due to incompatibility with SIP. - enum ErrorCode - { - UnknownError, ///< An unknown error occurred. - CreationError, ///< Socket creation failed. - ConnectFailedError, ///< Connection failed. - BindFailedError, ///< Bind to IP and port failed. - AcceptFailedError, ///< Accepting an incoming connection failed. - SendFailedError, ///< Sending a message failed. - ReceiveFailedError, ///< Receiving a message failed. - UnknownMessageTypeError, ///< Received a message with an unknown message type. - ParseFailedError, ///< Parsing the received message failed. - ConnectionResetError, ///< The connection was reset by peer. - MessageRegistrationFailedError, ///< Message registration failed. - InvalidStateError, ///< Socket is in an invalid state. - InvalidMessageError, ///< Message being handled is a nullptr or otherwise invalid. - Debug, //Debug messages - }; - } + UnknownError, ///< An unknown error occurred. + CreationError, ///< Socket creation failed. + ConnectFailedError, ///< Connection failed. + BindFailedError, ///< Bind to IP and port failed. + AcceptFailedError, ///< Accepting an incoming connection failed. + SendFailedError, ///< Sending a message failed. + ReceiveFailedError, ///< Receiving a message failed. + UnknownMessageTypeError, ///< Received a message with an unknown message type. + ParseFailedError, ///< Parsing the received message failed. + ConnectionResetError, ///< The connection was reset by peer. + MessageRegistrationFailedError, ///< Message registration failed. + InvalidStateError, ///< Socket is in an invalid state. + InvalidMessageError, ///< Message being handled is a nullptr or otherwise invalid. + Debug, //Debug messages + }; /** * A class representing an error with an error code and an error message. @@ -62,13 +58,13 @@ namespace Arcus /** * Create an error with an error code and error message. */ - Error(ErrorCode::ErrorCode error_code, const std::string& error_message); + Error(ErrorCode error_code, const std::string& error_message); /** * Get the error code of this error. */ - ErrorCode::ErrorCode getErrorCode() const; + ErrorCode getErrorCode() const; /** * Get the error message. */ @@ -99,7 +95,7 @@ namespace Arcus std::string toString() const; private: - ErrorCode::ErrorCode _error_code; + ErrorCode _error_code; std::string _error_message; bool _fatal_error; int _native_error_code; diff --git a/src/Socket.cpp b/src/Socket.cpp index c95146d1..82a6d36e 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -50,7 +50,7 @@ Socket::~Socket() } } -SocketState::SocketState Socket::getState() const +SocketState Socket::getState() const { return d->state; } diff --git a/src/Socket.h b/src/Socket.h index 52e5dcb4..27d33af3 100644 --- a/src/Socket.h +++ b/src/Socket.h @@ -48,7 +48,7 @@ namespace Arcus * * \return The current socket state. */ - virtual SocketState::SocketState getState() const; + virtual SocketState getState() const; /** * Get the last error. diff --git a/src/SocketListener.h b/src/SocketListener.h index ce229d44..448de33f 100644 --- a/src/SocketListener.h +++ b/src/SocketListener.h @@ -57,7 +57,7 @@ namespace Arcus * * \param newState The new state of the socket. */ - virtual void stateChanged(SocketState::SocketState newState) = 0; + virtual void stateChanged(SocketState newState) = 0; /** * Called whenever a new message has been received and * correctly parsed. diff --git a/src/Socket_p.h b/src/Socket_p.h index 9c3c084a..024064ce 100644 --- a/src/Socket_p.h +++ b/src/Socket_p.h @@ -93,11 +93,11 @@ namespace Arcus #ifdef ARCUS_DEBUG void debug(const std::string& message); #endif - void error(ErrorCode::ErrorCode error_code, const std::string& message); - void fatalError(ErrorCode::ErrorCode error_code, const std::string& msg); + void error(ErrorCode error_code, const std::string& message); + void fatalError(ErrorCode error_code, const std::string& msg); - SocketState::SocketState state; - SocketState::SocketState next_state; + SocketState state; + SocketState next_state; bool received_close; @@ -148,7 +148,7 @@ namespace Arcus #endif // Report an error that should not cause the connection to abort. - void Socket::Private::error(ErrorCode::ErrorCode error_code, const std::string& message) + void Socket::Private::error(ErrorCode error_code, const std::string& message) { Error error(error_code, message); error.setNativeErrorCode(platform_socket.getNativeErrorCode()); @@ -162,7 +162,7 @@ namespace Arcus } // Report an error that should cause the socket to go into an error state and abort the connection. - void Socket::Private::fatalError(ErrorCode::ErrorCode error_code, const std::string& message) + void Socket::Private::fatalError(ErrorCode error_code, const std::string& message) { Error error(error_code, message); error.setFatalError(true); diff --git a/src/Types.h b/src/Types.h index ac55c0ef..53e4576b 100644 --- a/src/Types.h +++ b/src/Types.h @@ -40,21 +40,17 @@ namespace Arcus /** * Socket state. */ - namespace SocketState + enum class SocketState { - // Note: Not using enum class due to incompatibility with SIP. - enum SocketState - { - Initial, ///< Created, not running. - Connecting, ///< Connecting to an address and port. - Connected, ///< Connected and capable of sending and receiving messages. - Opening, ///< Opening for incoming connections. - Listening, ///< Listening for incoming connections. - Closing, ///< Closing down. - Closed, ///< Closed, not running. - Error ///< A fatal error happened that blocks the socket from operating. - }; - } + Initial, ///< Created, not running. + Connecting, ///< Connecting to an address and port. + Connected, ///< Connected and capable of sending and receiving messages. + Opening, ///< Opening for incoming connections. + Listening, ///< Listening for incoming connections. + Closing, ///< Closing down. + Closed, ///< Closed, not running. + Error ///< A fatal error happened that blocks the socket from operating. + }; } #endif //ARCUS_TYPES_H From 1ffcc3d98a5bbda0b073e2475e1d422b049d7099 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 3 Mar 2022 05:38:26 +0100 Subject: [PATCH 26/64] Added StandardProjectSettings module This module sets the rpaths relative from the executable - rpath for Arcus -> ../lib - rpath for pyArcus -> ../lib/python3.10/site-packages It also transfers some other cmake logic out of the main CMakeLists.txt Contributes to CURA-8640 --- CMakeLists.txt | 53 +---- cmake/StandardProjectSettings.cmake | 349 ++++++++++++++++++++++++++++ 2 files changed, 361 insertions(+), 41 deletions(-) create mode 100644 cmake/StandardProjectSettings.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ce277b8..f1a361bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ project(arcus) cmake_minimum_required(VERSION 3.18) +include(cmake/StandardProjectSettings.cmake) +AssureOutOfSourceBuilds() -include(GNUInstallDirs) include(CMakePackageConfigHelpers) include(GenerateExportHeader) @@ -9,25 +10,11 @@ option(BUILD_PYTHON "Build " ON) option(BUILD_EXAMPLES "Build the example programs" ON) option(BUILD_STATIC "Build as a static library" OFF) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -if(WIN32) - option(MSVC_STATIC_RUNTIME "Link the MSVC runtime statically" OFF) -endif() - # We want to have access to protobuf_generate_cpp and other FindProtobuf features. # However, if ProtobufConfig is used instead, there is a CMake option that controls # this, which defaults to OFF. We need to force this option to ON instead. set(protobuf_MODULE_COMPATIBLE ON CACHE INTERNAL "" FORCE) -find_package(Protobuf 3.0.0 REQUIRED) - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) #Required if a patch to libArcus needs to be made via templates. - -set(CMAKE_CXX_STANDARD 17) - -if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") -endif() +find_package(Protobuf 3.15.0 REQUIRED) set(arcus_SRCS src/Socket.cpp @@ -49,31 +36,14 @@ set(arcus_HDRS set(ARCUS_VERSION 1.1.0) set(ARCUS_SOVERSION 3) -OPTION(SET_RPATH ON) - -if(SET_RPATH) - set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}") -endif() - if(BUILD_STATIC) add_library(Arcus STATIC ${arcus_SRCS}) - if(NOT WIN32 OR CMAKE_COMPILER_IS_GNUCXX) - target_link_libraries(Arcus PRIVATE pthread) - set_target_properties(Arcus PROPERTIES COMPILE_FLAGS -fPIC) - endif() else() add_library(Arcus SHARED ${arcus_SRCS}) endif() - -if(MSVC_STATIC_RUNTIME) - foreach(flag_var - CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if(${flag_var} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - endif(${flag_var} MATCHES "/MD") - endforeach(flag_var) -endif() +set_project_standards(Arcus) +set_rpath(Arcus) +use_threads(Arcus) target_include_directories(Arcus PUBLIC $ @@ -83,14 +53,12 @@ target_include_directories(Arcus PUBLIC target_link_libraries(Arcus PUBLIC protobuf::libprotobuf) if(WIN32) - add_definitions(-D_WIN32_WINNT=0x0600) # Declare we require Vista or higher, this allows us to use IPv6 functions. + target_compile_definitions(Arcus PRIVATE -D_WIN32_WINNT=0x0600) target_link_libraries(Arcus PUBLIC Ws2_32) endif() -if(${CMAKE_BUILD_TYPE}) - if(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") - add_definitions(-DARCUS_DEBUG) - endif() +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") + target_compile_definitions(Arcus PRIVATE -DARCUS_DEBUG) endif() set_target_properties(Arcus PROPERTIES @@ -154,6 +122,9 @@ if(BUILD_PYTHON) find_package(SIP REQUIRED 6.5.0) add_library(pyArcus INTERFACE ${CMAKE_SOURCE_DIR}/python/PythonMessage.cpp) + set_project_standards(pyArcus) + set_rpath(pyArcus "../lib/python3.10/site-packages") + use_threads(pyArcus) target_include_directories(pyArcus INTERFACE diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake new file mode 100644 index 00000000..104277a3 --- /dev/null +++ b/cmake/StandardProjectSettings.cmake @@ -0,0 +1,349 @@ +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 project_name) + if(ARGV1) + set(_relative_path ${ARGV1}) + else() + set(_relative_path "../lib") + endif() + set_target_properties(${project_name} PROPERTIES BUILD_WITH_INSTALL_RPATH ON) + if (APPLE) + set_target_properties(${project_name} PROPERTIES MACOSX_RPATH ON) + set_target_properties(${project_name} PROPERTIES INSTALL_RPATH "@executable_path/${_relative_path}") + message(STATUS "Setting relative install RPATH for target ${project_name} to @executable_path/${_relative_path}") + else() + set_target_properties(${project_name} PROPERTIES INSTALL_RPATH "$ORIGIN/${_relative_path}") + message(STATUS "Setting relative install RPATH for target ${project_name} to $ORIGIN/${_relative_path}") + endif() +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 12fdb070826e644b54f7ee22a37412d5a5c9d0f7 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 4 Mar 2022 12:40:33 +0100 Subject: [PATCH 27/64] use arguments for function use_rpaths 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 Contributes to CURA-8640 --- CMakeLists.txt | 14 ++++++-- cmake/StandardProjectSettings.cmake | 52 ++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1a361bb..e22b033f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,8 +42,13 @@ else() add_library(Arcus SHARED ${arcus_SRCS}) endif() set_project_standards(Arcus) -set_rpath(Arcus) use_threads(Arcus) +set_rpath(TARGETS + Arcus + PATHS + "." + "../lib" + RELATIVE) target_include_directories(Arcus PUBLIC $ @@ -123,7 +128,12 @@ if(BUILD_PYTHON) add_library(pyArcus INTERFACE ${CMAKE_SOURCE_DIR}/python/PythonMessage.cpp) set_project_standards(pyArcus) - set_rpath(pyArcus "../lib/python3.10/site-packages") + set_rpath(TARGETS + pyArcus + PATHS + "." + "../lib" + RELATIVE) use_threads(pyArcus) target_include_directories(pyArcus diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 104277a3..556e21f3 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -102,21 +102,43 @@ function(set_project_standards project_name) endif() endfunction() -function(set_rpath project_name) - if(ARGV1) - set(_relative_path ${ARGV1}) - else() - set(_relative_path "../lib") - endif() - set_target_properties(${project_name} PROPERTIES BUILD_WITH_INSTALL_RPATH ON) - if (APPLE) - set_target_properties(${project_name} PROPERTIES MACOSX_RPATH ON) - set_target_properties(${project_name} PROPERTIES INSTALL_RPATH "@executable_path/${_relative_path}") - message(STATUS "Setting relative install RPATH for target ${project_name} to @executable_path/${_relative_path}") - else() - set_target_properties(${project_name} PROPERTIES INSTALL_RPATH "$ORIGIN/${_relative_path}") - message(STATUS "Setting relative install RPATH for target ${project_name} to $ORIGIN/${_relative_path}") - endif() +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 BUILD_WITH_INSTALL_RPATH for target ${_target}") + set_target_properties(${_target} PROPERTIES BUILD_WITH_INSTALL_RPATH ON) + if(APPLE) + message(STATUS "Setting MACOSX_RPATH for target ${_target}") + set_target_properties(${_target} PROPERTIES MACOSX_RPATH ON) + endif() + if(SET_RPATH_RELATIVE) + if(APPLE) + foreach(_path IN ITEMS ${SET_RPATH_PATHS}) + set_target_properties(${_target} PROPERTIES INSTALL_RPATH "@executable_path/${_path}") + message(STATUS "Setting relative install RPATH for target ${_target} to @executable_path/${_path}") + endforeach() + else(LINUX) + foreach(_path IN ITEMS ${SET_RPATH_PATHS}) + set_target_properties(${_target} PROPERTIES INSTALL_RPATH "$ORIGIN/${_path}") + message(STATUS "Setting relative install RPATH for target ${_target} to $ORIGIN/${_path}") + endforeach() + endif() + else() + foreach(_path IN ITEMS ${SET_RPATH_PATHS}) + set_target_properties(${_target} PROPERTIES INSTALL_RPATH ${_path}) + message(STATUS "Setting absolute install RPATH for target ${_target} to ${_path}") + endforeach() + endif() + endforeach() endfunction() # Ultimaker uniform Python linking method From cc167f1f4882b0bf004ecca1879d90c81a1e9fc1 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 4 Mar 2022 13:30:48 +0100 Subject: [PATCH 28/64] escape dollar sign on ORIGIN rpath Contributes to CURA-8640 --- cmake/StandardProjectSettings.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 556e21f3..7dc5fe0f 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -128,7 +128,7 @@ function(set_rpath) endforeach() else(LINUX) foreach(_path IN ITEMS ${SET_RPATH_PATHS}) - set_target_properties(${_target} PROPERTIES INSTALL_RPATH "$ORIGIN/${_path}") + set_target_properties(${_target} PROPERTIES INSTALL_RPATH "\$ORIGIN/${_path}") message(STATUS "Setting relative install RPATH for target ${_target} to $ORIGIN/${_path}") endforeach() endif() From de5ce6b60d6ea99b0c09facd86d7d5967fd79f9f Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 4 Mar 2022 13:35:35 +0100 Subject: [PATCH 29/64] allways full RPATH As described here: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath Contributes to CURA-8640 --- cmake/StandardProjectSettings.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 7dc5fe0f..772d771e 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -114,8 +114,12 @@ function(set_rpath) set(multiValueArgs TARGETS PATHS) cmake_parse_arguments(SET_RPATH "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) foreach(_target IN ITEMS ${SET_RPATH_TARGETS}) - message(STATUS "Setting BUILD_WITH_INSTALL_RPATH for target ${_target}") - set_target_properties(${_target} PROPERTIES BUILD_WITH_INSTALL_RPATH ON) + 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) From 7376d78eddb5a7d584bc13331dd1fb32551ee614 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 4 Mar 2022 14:40:42 +0100 Subject: [PATCH 30/64] set rpath for sip_ target The libArcus rpaths are now set correctly but the python module not yet. This is probably because I used the INTERFACE target. Trying it out against the sip target. Contributes to CURA-8640 --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e22b033f..9b49f207 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,12 +128,6 @@ if(BUILD_PYTHON) add_library(pyArcus INTERFACE ${CMAKE_SOURCE_DIR}/python/PythonMessage.cpp) set_project_standards(pyArcus) - set_rpath(TARGETS - pyArcus - PATHS - "." - "../lib" - RELATIVE) use_threads(pyArcus) target_include_directories(pyArcus @@ -146,6 +140,12 @@ if(BUILD_PYTHON) target_link_libraries(pyArcus INTERFACE Arcus protobuf::libprotobuf Python::Python) add_sip_module(pyArcus) + set_rpath(TARGETS + sip_pyArcus + PATHS + "." + "../lib" + RELATIVE) install_sip_module(pyArcus) endif() From 805bcecd245c46585a65e6e45c60ac7534a6cc64 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Fri, 4 Mar 2022 15:07:15 +0100 Subject: [PATCH 31/64] Revert "set rpath for sip_ target" This reverts commit 7376d78eddb5a7d584bc13331dd1fb32551ee614. --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b49f207..e22b033f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,12 @@ if(BUILD_PYTHON) add_library(pyArcus INTERFACE ${CMAKE_SOURCE_DIR}/python/PythonMessage.cpp) set_project_standards(pyArcus) + set_rpath(TARGETS + pyArcus + PATHS + "." + "../lib" + RELATIVE) use_threads(pyArcus) target_include_directories(pyArcus @@ -140,12 +146,6 @@ if(BUILD_PYTHON) target_link_libraries(pyArcus INTERFACE Arcus protobuf::libprotobuf Python::Python) add_sip_module(pyArcus) - set_rpath(TARGETS - sip_pyArcus - PATHS - "." - "../lib" - RELATIVE) install_sip_module(pyArcus) endif() From 2deab5c4176ba0324c4b9125c7377ddc47ba739a Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 4 Mar 2022 15:18:02 +0100 Subject: [PATCH 32/64] transfer rpath properties to sip_target Contributes to CURA-8640 --- cmake/SIPMacros.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index b7bd7aa4..629cc83a 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -58,6 +58,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( From c34fbe430af8d31aa1f10b0eb731e0d70897c7c2 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 4 Mar 2022 16:09:33 +0100 Subject: [PATCH 33/64] Fixed setting of multiple paths Contributes to CURA-8640 --- CMakeLists.txt | 2 -- cmake/StandardProjectSettings.cmake | 24 ++++++++---------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e22b033f..0d3d4b1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,6 @@ use_threads(Arcus) set_rpath(TARGETS Arcus PATHS - "." "../lib" RELATIVE) @@ -131,7 +130,6 @@ if(BUILD_PYTHON) set_rpath(TARGETS pyArcus PATHS - "." "../lib" RELATIVE) use_threads(pyArcus) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 772d771e..cca13d9a 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -114,34 +114,26 @@ function(set_rpath) 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) + 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) + 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) + 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) - foreach(_path IN ITEMS ${SET_RPATH_PATHS}) - set_target_properties(${_target} PROPERTIES INSTALL_RPATH "@executable_path/${_path}") - message(STATUS "Setting relative install RPATH for target ${_target} to @executable_path/${_path}") - endforeach() + list(TRANSFORM SET_RPATH_PATHS PREPEND "@executable_path/") else(LINUX) - foreach(_path IN ITEMS ${SET_RPATH_PATHS}) - set_target_properties(${_target} PROPERTIES INSTALL_RPATH "\$ORIGIN/${_path}") - message(STATUS "Setting relative install RPATH for target ${_target} to $ORIGIN/${_path}") - endforeach() + list(TRANSFORM SET_RPATH_PATHS PREPEND "\$ORIGIN/") endif() - else() - foreach(_path IN ITEMS ${SET_RPATH_PATHS}) - set_target_properties(${_target} PROPERTIES INSTALL_RPATH ${_path}) - message(STATUS "Setting absolute install RPATH for target ${_target} to ${_path}") - endforeach() 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() From bdfc059f9a7885275404edb49898dce25763f791 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 4 Mar 2022 16:26:42 +0100 Subject: [PATCH 34/64] Added Linux AppImage paths Contributes to CURA-8640 --- CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d3d4b1d..f3f0961b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,9 @@ use_threads(Arcus) set_rpath(TARGETS Arcus PATHS - "../lib" + "$<$:usr/bin>" + "$<$:usr/bin/lib>" + "$<$:../lib>" RELATIVE) target_include_directories(Arcus PUBLIC @@ -130,7 +132,9 @@ if(BUILD_PYTHON) set_rpath(TARGETS pyArcus PATHS - "../lib" + "$<$:usr/bin>" + "$<$:usr/bin/lib>" + "$<$:../lib>" RELATIVE) use_threads(pyArcus) From 60141743966e16a3d649d2afa03c43cf3cf28a6b Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Fri, 4 Mar 2022 16:40:36 +0100 Subject: [PATCH 35/64] Sync SIPMAcros.cmake with Savitar Contributes to CURA-8640 --- cmake/SIPMacros.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 629cc83a..e36d0808 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -49,7 +49,10 @@ 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}" "${usr_src}") + set(sip_sources "${sip_c}" "${sip_cpp}") + if(${usr_src}) + list(APPEND sip_sources "${usr_src}") + endif() add_library("sip_${MODULE_TARGET}" SHARED ${sip_sources}) # Make sure that the library name of the target is the same as the MODULE_TARGET with the appropriate extension From 4dffd0cbfa7b81a73d1cf1cfcc118b92e0b14def Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Fri, 4 Mar 2022 17:42:25 +0100 Subject: [PATCH 36/64] Revert "Sync SIPMAcros.cmake with Savitar" This reverts commit 60141743966e16a3d649d2afa03c43cf3cf28a6b. --- cmake/SIPMacros.cmake | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index e36d0808..629cc83a 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -49,10 +49,7 @@ 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(APPEND sip_sources "${usr_src}") - endif() + set(sip_sources "${sip_c}" "${sip_cpp}" "${usr_src}") add_library("sip_${MODULE_TARGET}" SHARED ${sip_sources}) # Make sure that the library name of the target is the same as the MODULE_TARGET with the appropriate extension From 12acc2d126e4b1c26738834d43d3f07c4eab35d9 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Fri, 4 Mar 2022 18:54:45 +0100 Subject: [PATCH 37/64] 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 f3f0961b..c9e50609 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,7 @@ if(BUILD_PYTHON) "$<$:usr/bin>" "$<$:usr/bin/lib>" "$<$:../lib>" + "../../" RELATIVE) use_threads(pyArcus) From 3c724a664a214ecaaa81393d4da7ccadc43ea6b4 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 8 Mar 2022 13:06:17 +0100 Subject: [PATCH 38/64] Also use relative rpath from loader Contributes to CURA-8640 --- cmake/StandardProjectSettings.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index cca13d9a..3d432874 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 58a94a02ba2e87be8018307ce31dde48f2edce11 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Tue, 8 Mar 2022 14:30:07 +0100 Subject: [PATCH 39/64] 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 c9e50609..a9e8e64c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,7 @@ if(BUILD_PYTHON) "$<$:usr/bin>" "$<$:usr/bin/lib>" "$<$:../lib>" + "$<$:../Resources/lib/>" "../../" RELATIVE) use_threads(pyArcus) From 659796eda2f3c68156f4f96d53d4b23281849bad Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Mon, 14 Mar 2022 12:30:17 +0100 Subject: [PATCH 40/64] Bumped up version and so version to 5 Contributes to CURA-8640 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9e8e64c..884a2a84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,8 +33,8 @@ set(arcus_HDRS ${CMAKE_CURRENT_BINARY_DIR}/src/ArcusExport.h ) -set(ARCUS_VERSION 1.1.0) -set(ARCUS_SOVERSION 3) +set(ARCUS_VERSION 5.0.0) +set(ARCUS_SOVERSION 5) if(BUILD_STATIC) add_library(Arcus STATIC ${arcus_SRCS}) From e6d6b6f9b7593228a30e1788629c4aed9b5ad1d3 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Tue, 29 Mar 2022 16:21:20 +0200 Subject: [PATCH 41/64] Allow usage of Conan Contributes to CURA-8640 --- CMakeLists.txt | 9 +++++++-- cmake/FindSIP.cmake | 6 +++--- conanfile.txt | 10 ++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 conanfile.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 884a2a84..055b0bfa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ include(CMakePackageConfigHelpers) include(GenerateExportHeader) option(BUILD_PYTHON "Build " ON) -option(BUILD_EXAMPLES "Build the example programs" ON) +option(BUILD_EXAMPLES "Build the example programs" OFF) option(BUILD_STATIC "Build as a static library" OFF) # We want to have access to protobuf_generate_cpp and other FindProtobuf features. @@ -122,7 +122,12 @@ if(BUILD_PYTHON) if(APPLE) set(Python_FIND_FRAMEWORK NEVER) endif() - find_package(Python ${Python_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development) + 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::cpython) + endif() message(STATUS "Linking and building ${project_name} against Python ${Python_VERSION}") find_package(SIP REQUIRED 6.5.0) diff --git a/cmake/FindSIP.cmake b/cmake/FindSIP.cmake index f5198902..828e82d4 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}) diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 00000000..dee88ad2 --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,10 @@ +[requires] +protobuf/3.17.1 +cpython/3.10.0 + +[generators] +virtualrunenv +CMakeToolchain +CMakeDeps + +[options] \ No newline at end of file From 5d1d390cf2f50f86f122c949123d0f67a46e24e9 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 31 Mar 2022 18:00:39 +0200 Subject: [PATCH 42/64] Set PYTHONPATH with cmake variable Contributes to CURA-8640 --- cmake/SIPMacros.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 629cc83a..31208d63 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -72,9 +72,12 @@ function(add_sip_module MODULE_TARGET) # 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. + if (NOT DEFINED PYTHONPATH) + set(PYTHONPATH "") + endif () 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}${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 053d794ada9f7db606e8112fa73229b3fa124cdb Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Mon, 4 Apr 2022 13:58:50 +0200 Subject: [PATCH 43/64] Set PYTHONPATH with cmake variable 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 31208d63..7f66aeda 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -77,7 +77,7 @@ function(add_sip_module MODULE_TARGET) endif () add_custom_command( TARGET "sip_${MODULE_TARGET}" - COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${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 20dd9d09364e7386738898c97ac559e82e1382f7 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Mon, 4 Apr 2022 14:01:30 +0200 Subject: [PATCH 44/64] Mimic find package variables Python Contributes to CURA-8640 --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 055b0bfa..f1502869 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,7 +126,10 @@ if(BUILD_PYTHON) if(NOT TARGET cpython::cpython) find_package(Python ${Python_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development) else() - add_library(Python::Python ALIAS cpython::cpython) + 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 "Linking and building ${project_name} against Python ${Python_VERSION}") From 2f408d62212024400120daeb377b5e71101d9dda Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Mon, 4 Apr 2022 14:18:47 +0200 Subject: [PATCH 45/64] Also use PYTHONPATH when generating for the first time 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 7f66aeda..5ef42243 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 26dbff721063c08eff0200f4967e1d50824f2883 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Tue, 5 Apr 2022 10:17:49 +0200 Subject: [PATCH 46/64] Allow defining local site-package install path Contributes to CURA-8640 --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1502869..15be917f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,7 +158,11 @@ if(BUILD_PYTHON) target_link_libraries(pyArcus INTERFACE Arcus protobuf::libprotobuf Python::Python) add_sip_module(pyArcus) - install_sip_module(pyArcus) + if (DEFINED Python_SITELIB_LOCAL) + install_sip_module(pyArcus ${Python_SITELIB_LOCAL}) + else() + install_sip_module(pyArcus) + endif () endif() include(CPackConfig.cmake) \ No newline at end of file From 766f6346aa036d87b17ab4626f973050e6e64764 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 12 Apr 2022 10:24:51 +0200 Subject: [PATCH 47/64] Bump up minimum supported CMake version Contributes to CURA-8640 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 15be917f..ae3fb27a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ project(arcus) -cmake_minimum_required(VERSION 3.18) +cmake_minimum_required(VERSION 3.20) include(cmake/StandardProjectSettings.cmake) AssureOutOfSourceBuilds() From 045fed6e1b816e40bf85425f027c9364c79f1d49 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 12 Apr 2022 10:25:37 +0200 Subject: [PATCH 48/64] Bump up minimum supported CMake version Contributes to CURA-8640 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae3fb27a..a551a364 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ option(BUILD_STATIC "Build as a static library" OFF) # However, if ProtobufConfig is used instead, there is a CMake option that controls # this, which defaults to OFF. We need to force this option to ON instead. set(protobuf_MODULE_COMPATIBLE ON CACHE INTERNAL "" FORCE) -find_package(Protobuf 3.15.0 REQUIRED) +find_package(Protobuf 3.17.1 REQUIRED) set(arcus_SRCS src/Socket.cpp From 7350da2e2532e716c254014aaae1b6bc58e349cd Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 12 Apr 2022 10:26:42 +0200 Subject: [PATCH 49/64] Removed CPack support No longer used by our build system Contributes to CURA-8640 --- CMakeLists.txt | 4 +--- CPackConfig.cmake | 24 ------------------------ 2 files changed, 1 insertion(+), 27 deletions(-) delete mode 100644 CPackConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a551a364..fb7ceecd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,6 +163,4 @@ if(BUILD_PYTHON) else() install_sip_module(pyArcus) endif () -endif() - -include(CPackConfig.cmake) \ No newline at end of file +endif() \ No newline at end of file diff --git a/CPackConfig.cmake b/CPackConfig.cmake deleted file mode 100644 index bd1680e6..00000000 --- a/CPackConfig.cmake +++ /dev/null @@ -1,24 +0,0 @@ -set(CPACK_PACKAGE_VENDOR "Ultimaker") -set(CPACK_PACKAGE_CONTACT "Ruben Dulek ") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "libArcus Communication library") -if(NOT DEFINED CPACK_PACKAGE_VERSION) - set(CPACK_PACKAGE_VERSION "15.05.91") -endif() -set(CPACK_GENERATOR "DEB") -if(NOT DEFINED CPACK_DEBIAN_PACKAGE_ARCHITECTURE) - execute_process(COMMAND dpkg --print-architecture OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() -set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}") - -set(DEB_DEPENDS - "python3 (>= 3.4.0)" - "libgcc1 (>= 4.9.0)" - "libstdc++6 (>= 4.9.0)" - "libc6 (>= 2.19)" - "zlib1g (>= 1.2.0)" - "protobuf (>= 3.0.0)" -) -string(REPLACE ";" ", " DEB_DEPENDS "${DEB_DEPENDS}") -set(CPACK_DEBIAN_PACKAGE_DEPENDS ${DEB_DEPENDS}) - -include(CPack) From 4ba8dda1cf7028ad6346764f890ead06aacf3548 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 12 Apr 2022 10:28:04 +0200 Subject: [PATCH 50/64] Removed protobuf Module compatibility workaround No longer needed with our current Protobuf version Contributes to CURA-8640 --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb7ceecd..6f399dec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,10 +10,6 @@ option(BUILD_PYTHON "Build " ON) option(BUILD_EXAMPLES "Build the example programs" OFF) option(BUILD_STATIC "Build as a static library" OFF) -# We want to have access to protobuf_generate_cpp and other FindProtobuf features. -# However, if ProtobufConfig is used instead, there is a CMake option that controls -# this, which defaults to OFF. We need to force this option to ON instead. -set(protobuf_MODULE_COMPATIBLE ON CACHE INTERNAL "" FORCE) find_package(Protobuf 3.17.1 REQUIRED) set(arcus_SRCS From 2be1f55dfda5a07bff361e3b6050fd3258b222db Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Tue, 12 Apr 2022 10:42:12 +0200 Subject: [PATCH 51/64] Removed obsolete Export Header Already taken care with the target_include_directories Contributes to CURA-8640 --- CMakeLists.txt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f399dec..0ce1b1a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ AssureOutOfSourceBuilds() include(CMakePackageConfigHelpers) include(GenerateExportHeader) +generate_export_header(Arcus EXPORT_FILE_NAME src/ArcusExport.h) option(BUILD_PYTHON "Build " ON) option(BUILD_EXAMPLES "Build the example programs" OFF) @@ -73,13 +74,6 @@ set_target_properties(Arcus PROPERTIES VISIBILITY_INLINES_HIDDEN 1 ) -generate_export_header(Arcus - EXPORT_FILE_NAME src/ArcusExport.h -) -# This is required when building out-of-tree. -# The compiler won't find the generated header otherwise. -include_directories(${CMAKE_BINARY_DIR}/src) - if(BUILD_EXAMPLES) add_subdirectory(examples) endif() From 845b0213660d4bf3102f6c9acf86a92d01cfd3f7 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 13 Apr 2022 11:30:18 +0200 Subject: [PATCH 52/64] Revert "Removed obsolete Export Header" This reverts commit 2be1f55dfda5a07bff361e3b6050fd3258b222db. --- CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ce1b1a9..6f399dec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ AssureOutOfSourceBuilds() include(CMakePackageConfigHelpers) include(GenerateExportHeader) -generate_export_header(Arcus EXPORT_FILE_NAME src/ArcusExport.h) option(BUILD_PYTHON "Build " ON) option(BUILD_EXAMPLES "Build the example programs" OFF) @@ -74,6 +73,13 @@ set_target_properties(Arcus PROPERTIES VISIBILITY_INLINES_HIDDEN 1 ) +generate_export_header(Arcus + EXPORT_FILE_NAME src/ArcusExport.h +) +# This is required when building out-of-tree. +# The compiler won't find the generated header otherwise. +include_directories(${CMAKE_BINARY_DIR}/src) + if(BUILD_EXAMPLES) add_subdirectory(examples) endif() From c8aed1b253c7b8d73a9116440c3fe9296968d104 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 13 Apr 2022 15:00:16 +0200 Subject: [PATCH 53/64] Remove Example They are old and don't compile anymore, they are hardly used. If people require an usage example they can look how Cura, Uranium and CuraEngine use Arcus Contributes to CURA-8640 --- CMakeLists.txt | 5 -- examples/CMakeLists.txt | 25 -------- examples/example.cpp | 128 ---------------------------------------- examples/example.proto | 40 ------------- examples/example.py | 82 ------------------------- examples/example_py.sh | 3 - 6 files changed, 283 deletions(-) delete mode 100644 examples/CMakeLists.txt delete mode 100644 examples/example.cpp delete mode 100644 examples/example.proto delete mode 100644 examples/example.py delete mode 100755 examples/example_py.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f399dec..abfe89f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,6 @@ include(CMakePackageConfigHelpers) include(GenerateExportHeader) option(BUILD_PYTHON "Build " ON) -option(BUILD_EXAMPLES "Build the example programs" OFF) option(BUILD_STATIC "Build as a static library" OFF) find_package(Protobuf 3.17.1 REQUIRED) @@ -80,10 +79,6 @@ generate_export_header(Arcus # The compiler won't find the generated header otherwise. include_directories(${CMAKE_BINARY_DIR}/src) -if(BUILD_EXAMPLES) - add_subdirectory(examples) -endif() - install(TARGETS Arcus EXPORT Arcus-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt deleted file mode 100644 index 012d2ebb..00000000 --- a/examples/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ - -include_directories(example ${CMAKE_CURRENT_BINARY_DIR}) - -set(example_SRCS - example.cpp - example_pb2.py -) - -protobuf_generate_cpp(example_PB_SRCS example_PB_HDRS "example.proto") - -add_executable(example ${example_SRCS} ${example_PB_SRCS}) -target_link_libraries(example Arcus) -if(NOT WIN32 OR CMAKE_COMPILER_IS_GNUCXX) - target_link_libraries(example pthread) - set_target_properties(example PROPERTIES COMPILE_FLAGS "-std=c++11") -endif() - -add_custom_command( - OUTPUT example_pb2.py - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} - ARGS --python_out ${CMAKE_CURRENT_BINARY_DIR} --proto_path=${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/example.proto - COMMENT "Running Python protocol buffer compiler on example.proto" - VERBATIM ) - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/example_py.sh ${CMAKE_CURRENT_BINARY_DIR}/example_py.sh) diff --git a/examples/example.cpp b/examples/example.cpp deleted file mode 100644 index dc578338..00000000 --- a/examples/example.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include -#include -#include - -#include "../src/Socket.h" -#include "../src/SocketListener.h" -#include "../src/Error.h" - -#include "example.pb.h" - -struct Object -{ -public: - int id; - std::string vertices; - std::string normals; - std::string indices; -}; - -class Listener : public Arcus::SocketListener -{ -public: - void stateChanged(Arcus::SocketState new_state) - { - std::cout << "State Changed: " << new_state << std::endl; - } - - void messageReceived() - { - } - - void error(const Arcus::Error& new_error) - { - std::cout << new_error << std::endl; - } -}; - -std::vector objects; - -void handleMessage(Arcus::Socket& socket, Arcus::MessagePtr message); - -int main(int argc, char** argv) -{ - Arcus::Socket socket; - - socket.registerMessageType(&Example::ObjectList::default_instance()); - socket.registerMessageType(&Example::ProgressUpdate::default_instance()); - socket.registerMessageType(&Example::SlicedObjectList::default_instance()); - - socket.addListener(new Listener()); - - std::cout << "Connecting to server\n"; - socket.connect("127.0.0.1", 56789); - - while(socket.getState() != Arcus::SocketState::Connected) - { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - - std::cout << "Connected to server\n"; - - while(true) - { - if(socket.getState() == Arcus::SocketState::Connected) - { - auto message = socket.takeNextMessage(); - if(message) - { - handleMessage(socket, message); - } - std::this_thread::sleep_for(std::chrono::milliseconds(250)); - } - else if(socket.getState() == Arcus::SocketState::Closed || socket.getState() == Arcus::SocketState::Error) - { - break; - } - } - - socket.close(); - return 0; -} - -void handleMessage(Arcus::Socket& socket, Arcus::MessagePtr message) -{ - // (Dynamicly) cast the message to one of our types. If this works (does not return a nullptr), we've found the right type. - auto objectList = dynamic_cast(message.get()); - if(objectList) - { - objects.clear(); - - std::cout << "Received object list containing " << objectList->objects_size() << " objects" << std::endl; - - for(auto objectDesc : objectList->objects()) - { - Object obj; - obj.id = objectDesc.id(); - obj.vertices = objectDesc.vertices(); - obj.normals = objectDesc.normals(); - obj.indices = objectDesc.indices(); - objects.push_back(obj); - } - - auto msg = std::make_shared(); - int progress = 0; - for(auto object : objects) - { - auto slicedObject = msg->add_objects(); - slicedObject->set_id(object.id); - - for(int i = 0; i < 1000; ++i) - { - auto polygon = slicedObject->add_polygons(); - polygon->set_type(i % 2 == 0 ? Example::Polygon_Type_InnerType : Example::Polygon_Type_OuterType); - polygon->set_points(object.vertices); - } - - auto update = std::make_shared(); - update->set_objectid(object.id); - update->set_amount((float(++progress) / float(objects.size())) * 100.f); - socket.sendMessage(update); - } - - std::cout << "Sending SlicedObjectList" << std::endl; - socket.sendMessage(msg); - - return; - } -} diff --git a/examples/example.proto b/examples/example.proto deleted file mode 100644 index 91568aa6..00000000 --- a/examples/example.proto +++ /dev/null @@ -1,40 +0,0 @@ -syntax = "proto3"; - -package Example; - -message ObjectList { - repeated Object objects = 1; -} - -message Object { - int32 id = 1; - bytes vertices = 2; //An array of 3 floats. - bytes normals = 3; //An array of 3 floats. - bytes indices = 4; //An array of ints. -} - -message ProgressUpdate { - int32 objectId = 1; - int32 amount = 2; -} - -message SlicedObjectList { - repeated SlicedObject objects = 1; -} - -message SlicedObject { - int32 id = 1; - - repeated Polygon polygons = 2; -} - -message Polygon { - enum Type - { - InnerType = 0; - OuterType = 1; - } - - Type type = 1; - bytes points = 2; -} diff --git a/examples/example.py b/examples/example.py deleted file mode 100644 index 709dce91..00000000 --- a/examples/example.py +++ /dev/null @@ -1,82 +0,0 @@ -import Arcus - -import time -import os.path - -class Listener(Arcus.SocketListener): - def stateChanged(self, state): - print("Socket state changed:", state) - - def messageReceived(self): - message = self.getSocket().takeNextMessage() - - if message.getTypeName() == "Example.ProgressUpdate": - print("Progress:", message.amount) - - if message.getTypeName() == "Example.SlicedObjectList": - print("Sliced Objects:", message.repeatedMessageCount("objects")) - - for i in range(message.repeatedMessageCount("objects")): - obj = message.getRepeatedMessage("objects", i) - print(" Object ID:", obj.id) - print(" Polygon Count:", obj.repeatedMessageCount("polygons")) - - def error(self, error): - print(error) - -print("Creating socket") - -socket = Arcus.Socket() - -print("Registering message types") - -path = os.path.dirname(os.path.abspath(__file__)).replace("\\", "/") -if not socket.registerAllMessageTypes(path + "/example.proto"): - print("Failed to register messages:", socket.getLastError()) - - -print("Creating listener") - -listener = Listener() -socket.addListener(listener) - -print("Listening for connections on 127.0.0.1:56789") - -socket.listen('127.0.0.1', 56789) - -while(socket.getState() != Arcus.SocketState.Connected): - time.sleep(0.1) - -#time.sleep(5) #Sleep for a bit so the other side can connect - -if(socket.getState() == Arcus.SocketState.Connected): - print("Connection established") -else: - print(socket.getState()) - print("Could not establish a connection:", socket.getLastError()) - exit(1) - -for i in range(10): - msg = socket.createMessage("Example.ObjectList") - - for i in range(100): - obj = msg.addRepeatedMessage("objects") - obj.id = i - obj.vertices = b'abcdefghijklmnopqrstuvwxyz' * 10 - obj.normals = b'abcdefghijklmnopqrstuvwxyz' * 10 - obj.indices = b'abcdefghijklmnopqrstuvwxyz' * 10 - - print("Sending message containing", msg.repeatedMessageCount("objects"), "objects") - socket.sendMessage(msg) - - time.sleep(1) - - if socket.getState() != Arcus.SocketState.Connected: - print("Socket lost connection, aborting!") - break - -time.sleep(5) #Sleep for a bit more so we can receive replies to what we just sent. - -print("Closing connection") - -socket.close() diff --git a/examples/example_py.sh b/examples/example_py.sh deleted file mode 100755 index fb0baa8e..00000000 --- a/examples/example_py.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_SOURCE_DIR}/python python3 ${CMAKE_CURRENT_SOURCE_DIR}/example.py From e583bb8b623e19c96a51ed16c0d2816fb88fb4c7 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 13 Apr 2022 15:02:43 +0200 Subject: [PATCH 54/64] Review suggestion implemented Contributes to CURA-8640 --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abfe89f1..ce36e186 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ AssureOutOfSourceBuilds() include(CMakePackageConfigHelpers) include(GenerateExportHeader) -option(BUILD_PYTHON "Build " ON) +option(BUILD_PYTHON "Build Python bindings for this library" ON) option(BUILD_STATIC "Build as a static library" OFF) find_package(Protobuf 3.17.1 REQUIRED) @@ -55,6 +55,8 @@ target_link_libraries(Arcus PUBLIC protobuf::libprotobuf) if(WIN32) target_compile_definitions(Arcus PRIVATE -D_WIN32_WINNT=0x0600) + # Declare we require Vista or higher, this allows us to use IPv6 functions. + target_link_libraries(Arcus PUBLIC Ws2_32) endif() @@ -145,7 +147,6 @@ if(BUILD_PYTHON) $ ) - target_compile_features(pyArcus INTERFACE cxx_std_17) target_link_libraries(pyArcus INTERFACE Arcus protobuf::libprotobuf Python::Python) add_sip_module(pyArcus) From 9a89a3b0717d16a8b17d9034bfda98983c301122 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 13 Apr 2022 15:03:24 +0200 Subject: [PATCH 55/64] Remove obsolete jenkins file We no longer use Jenkins Contributes to CURA-8640 --- Jenkinsfile | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index f0afbafa..00000000 --- a/Jenkinsfile +++ /dev/null @@ -1,45 +0,0 @@ -parallel_nodes(["linux && cura", "windows && cura"]) { - stage('Prepare') { - step([$class: 'WsCleanup']) - - checkout scm - } - - catchError { - dir('build') { - stage('Build') { - def branch = env.BRANCH_NAME - if(!fileExists("${env.CURA_ENVIRONMENT_PATH}/${branch}")) { - branch = "master" - } - - def extra_cmake_options = "" - if(!isUnix()) - { - // Disable building of Python bindings on Windows for now, - // since it requires MSVC to build properly. - extra_cmake_options = "-DBUILD_PYTHON=OFF" - - // Building example requires dynamic linking, while with MingGW - // on Windows in the build environment doesn't have dynamic protobuf - // library, so we can't do dynamic linking. - extra_cmake_options = "${extra_cmake_options} -DBUILD_EXAMPLES=OFF" - extra_cmake_options = "${extra_cmake_options} -DBUILD_STATIC=ON" - - // The CI is using MinGW as the CMake target, but the MinGW protobuf - // libraries are installed in "lib-mingw" instead of the default "lib" - // directory. We need to specify to use "lib-mingw" specifically so - // the linking process can use the correct library. - extra_cmake_options = "${extra_cmake_options} -DPROTOBUF_LIBRARY=\"${env.CURA_ENVIRONMENT_PATH}/${branch}/inst/lib-mingw/libprotobuf.a\"" - } - - cmake '..', "-DCMAKE_PREFIX_PATH=\"${env.CURA_ENVIRONMENT_PATH}/${branch}\" -DCMAKE_BUILD_TYPE=Release ${extra_cmake_options}" - make('') - } - } - } - - stage('Finalize') { - notify_build_result(env.CURA_EMAIL_RECIPIENTS, '#cura-dev', ['master']) - } -} From b42fae342021004b9613c702b6c5ffdbd69a6954 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 13 Apr 2022 15:04:09 +0200 Subject: [PATCH 56/64] Add cmake-build to gitignore Contributes to CURA-8640 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e2bde249..8f2cac30 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,4 @@ nbproject/* # Generated headers /src/ArcusExport.h +/cmake-build-* From 8504b4fef8731dc27fee4db7cf5d1c90a1585157 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 13 Apr 2022 15:10:33 +0200 Subject: [PATCH 57/64] We don't use mingw anymore Contributes to CURA-8640 --- .github/workflows/cicd-mingw64.yml | 58 ------------------------------ docker/build-deb-mingw64.sh | 27 -------------- docker/publish-debs.sh | 13 ------- 3 files changed, 98 deletions(-) delete mode 100644 .github/workflows/cicd-mingw64.yml delete mode 100755 docker/build-deb-mingw64.sh delete mode 100755 docker/publish-debs.sh diff --git a/.github/workflows/cicd-mingw64.yml b/.github/workflows/cicd-mingw64.yml deleted file mode 100644 index ac0f4b75..00000000 --- a/.github/workflows/cicd-mingw64.yml +++ /dev/null @@ -1,58 +0,0 @@ ---- -name: CI/CD for mingw64 debian package -on: - push: - branches: - - master - pull_request: - branches: - - master -jobs: - build: - name: Build debian package - timeout-minutes: 10 - runs-on: ubuntu-latest - container: debian:buster - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - name: Install dependencies - run: | - apt-get update - apt-get upgrade -y - apt-get install -y curl cmake gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 - update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix - update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix - curl -1sLf 'https://dl.cloudsmith.io/public/ultimaker/cura-public/cfg/setup/bash.deb.sh' | bash - apt-get install -y cura-libprotobuf-mingw-w64-dev - - name: Build debian package - run: | - docker/build-deb-mingw64.sh - - name: Upload build directory - uses: actions/upload-artifact@v1 - with: - name: build - path: build/ - publish: - name: Publish debian package - if: github.event_name != 'pull_request' - needs: build - timeout-minutes: 5 - runs-on: ubuntu-latest - container: python:3.10-slim-buster - env: - CLOUDSMITH_API_KEY: "${{ secrets.CLOUDSMITH_API_KEY }}" - CLOUDSMITH_DEB_REPO: "${{ secrets.CLOUDSMITH_DEB_REPO }}" - steps: - - name: Check repository - uses: actions/checkout@v2 - - name: Prepare cloudsmith-cli - run: | - pip3 install --upgrade cloudsmith-cli - - name: Download artifacts - uses: actions/download-artifact@v1 - with: - name: build - - name: Publish debian package - run: | - docker/publish-debs.sh diff --git a/docker/build-deb-mingw64.sh b/docker/build-deb-mingw64.sh deleted file mode 100755 index b5927bfb..00000000 --- a/docker/build-deb-mingw64.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -# -# This scripts uses CMake to build protobuf with static libraries using MinGW -# W64 targeting Windows x64. It also creates a debian package with cpack. The -# contents of the package are installed under "/usr/x86_64-w64-mingw32". -# - -# Include binaries in the cura development environment -CURA_DEV_ENV_ROOT=/opt/cura-dev -export PATH="${CURA_DEV_ENV_ROOT}/bin:${PATH}" - -mkdir build -cd build -cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_SYSTEM_NAME="Windows" \ - -DCMAKE_FIND_ROOT_PATH=/usr/x86_64-w64-mingw32 \ - -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \ - -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \ - -DBUILD_PYTHON=OFF \ - -DBUILD_EXAMPLES=OFF \ - -DBUILD_STATIC=ON \ - .. -make -cpack \ - --config ../cmake/cpack_config_deb_mingw64.cmake \ - -D CPACK_INSTALL_CMAKE_PROJECTS="$(pwd);libArcus;ALL;/" diff --git a/docker/publish-debs.sh b/docker/publish-debs.sh deleted file mode 100755 index 70e48929..00000000 --- a/docker/publish-debs.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -# -# This scripts lists all the .deb files in the "build/" directory and -# publishes them one by one to Cloudsmith.io -# - -for f in build/*.deb -do - echo "Uploading '${f}' to Cloudsmith..." - cloudsmith push deb \ - --api-key "${CLOUDSMITH_API_KEY}" \ - --republish "${CLOUDSMITH_DEB_REPO}" "${f}" -done From 7373fbf8d3aed853d9fe7741635d85cb0636b3ef Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 13 Apr 2022 15:12:08 +0200 Subject: [PATCH 58/64] codestyle change on assure_out_of_source_builds Contributes to CURA-8640 --- CMakeLists.txt | 2 +- cmake/StandardProjectSettings.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce36e186..7d808358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ project(arcus) cmake_minimum_required(VERSION 3.20) include(cmake/StandardProjectSettings.cmake) -AssureOutOfSourceBuilds() +assure_out_of_source_builds() include(CMakePackageConfigHelpers) include(GenerateExportHeader) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 3d432874..51e49618 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) From 6b1b7c23832ca59b995c5f228c34700b83c7a8ed Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 13 Apr 2022 15:21:32 +0200 Subject: [PATCH 59/64] Using BUILD_SHARED_LIBS flag instead of BUILD_STATIC BUILD_STATIC was our own custom option while the BUILD_SHARED_LIBS is a CMake global flag https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html Contributes to CURA-8640 --- CMakeLists.txt | 7 +++---- cmake/StandardProjectSettings.cmake | 18 ++++-------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d808358..6b7acf45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,6 @@ include(CMakePackageConfigHelpers) include(GenerateExportHeader) option(BUILD_PYTHON "Build Python bindings for this library" ON) -option(BUILD_STATIC "Build as a static library" OFF) find_package(Protobuf 3.17.1 REQUIRED) @@ -31,10 +30,10 @@ set(arcus_HDRS set(ARCUS_VERSION 5.0.0) set(ARCUS_SOVERSION 5) -if(BUILD_STATIC) - add_library(Arcus STATIC ${arcus_SRCS}) -else() +if(BUILD_SHARED_LIBS) add_library(Arcus SHARED ${arcus_SRCS}) +else() + add_library(Arcus STATIC ${arcus_SRCS}) endif() set_project_standards(Arcus) use_threads(Arcus) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index 51e49618..dff96c29 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -1,20 +1,10 @@ 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 24199a736bb407b9fb6a37c3de447f091285f242 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 13 Apr 2022 15:24:27 +0200 Subject: [PATCH 60/64] Remove CICD We don't have any unit tests in this repo so no need for this have this pipeline. Contributes to CURA-8640 --- .github/workflows/cicd.yml | 13 ------------- docker/build.sh | 23 ----------------------- 2 files changed, 36 deletions(-) delete mode 100644 .github/workflows/cicd.yml delete mode 100755 docker/build.sh diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml deleted file mode 100644 index 3a0b57d7..00000000 --- a/.github/workflows/cicd.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -name: CI/CD -on: [push, pull_request] -jobs: - build: - name: Build and test - runs-on: ubuntu-latest - container: ultimaker/cura-build-environment - steps: - - name: Checkout master - uses: actions/checkout@v1.2.0 - - name: Build and test - run: docker/build.sh diff --git a/docker/build.sh b/docker/build.sh deleted file mode 100755 index 0f28c5b8..00000000 --- a/docker/build.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -e - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -PROJECT_DIR="$( cd "${SCRIPT_DIR}/.." && pwd )" - -# Make sure that environment variables are set properly -export PATH="${CURA_BUILD_ENV_PATH}/bin:${PATH}" -export PKG_CONFIG_PATH="${CURA_BUILD_ENV_PATH}/lib/pkgconfig:${PKG_CONFIG_PATH}" -export LD_LIBRARY_PATH="${CURA_BUILD_ENV_PATH}/lib:${LD_LIBRARY_PATH}" - -cd "${PROJECT_DIR}" - -mkdir build -cd build -cmake \ - -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_PREFIX_PATH="${CURA_BUILD_ENV_PATH}" \ - -DBUILD_TESTS=ON \ - .. -make -ctest --output-on-failure -T Test From 740514de7c4c2094f418fb30d0e09c062404b139 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Thu, 14 Apr 2022 07:35:23 +0200 Subject: [PATCH 61/64] Fix wrong function call assure_out_of_source_builds Contributes to CURA-8640 --- cmake/StandardProjectSettings.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index dff96c29..37ff00e5 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -248,7 +248,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 55ac18890a556ce2828c68322507ff8260f0e486 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 14 Apr 2022 11:44:18 +0200 Subject: [PATCH 62/64] Use Python_VERSION for Cpython site-packages Contributes to CURA-8640 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b7acf45..6c003ee9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,7 @@ if(BUILD_PYTHON) 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 6636816ca7cb4a04c52f3f8b5a2ad0e2ae9d0377 Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 14 Apr 2022 12:00:50 +0200 Subject: [PATCH 63/64] Allow static build of the Python Module Contributes to CURA-8640 --- cmake/SIPMacros.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/SIPMacros.cmake b/cmake/SIPMacros.cmake index 5ef42243..51645245 100644 --- a/cmake/SIPMacros.cmake +++ b/cmake/SIPMacros.cmake @@ -50,7 +50,12 @@ 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}" "${usr_src}") - 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}") From a69cd0fb4eb20cc5e53bbb828e2801d20a92edca Mon Sep 17 00:00:00 2001 From: "j.spijker@ultimaker.com" Date: Thu, 14 Apr 2022 12:03:30 +0200 Subject: [PATCH 64/64] Allow in source builds Contributes to CURA-8640 --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c003ee9..3eb15437 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ project(arcus) cmake_minimum_required(VERSION 3.20) include(cmake/StandardProjectSettings.cmake) -assure_out_of_source_builds() include(CMakePackageConfigHelpers) include(GenerateExportHeader)