Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cura 8640 PyQt6 upgrade #134

Merged
merged 66 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
b86c38f
Only use sip to generate source files
Feb 23, 2022
02c7347
Find SIP on the system.
Feb 24, 2022
b6e681d
Added CMake function add_sip_module
Feb 24, 2022
ba6b5a6
Dressed down the pyproject.toml.in file some more
Feb 24, 2022
d16dc55
Renamed the main sip defintion file to reflect the module_name
Feb 24, 2022
3799ae7
Use the new CMake module add_sip_module
Feb 24, 2022
5316234
Link Arcus against protobuf target
jellespijker Feb 24, 2022
b3202a2
Use the CMAKE_SOURCE_DIR for including the SIPMacros
jellespijker Feb 24, 2022
8f71558
Add the current bin directory to the PYTHONPATH
jellespijker Feb 24, 2022
e173335
Make sure the extension is so on UNIX and pyd on Windows
jellespijker Feb 24, 2022
7c1edb3
Merge remote-tracking branch 'origin/CURA-7924_sip_cmake_build' into …
jellespijker Feb 24, 2022
4ba57f2
Use OS specific seperator for the PYTHONPATH
Feb 24, 2022
337d180
Setting the PYTHONPATH with the CMAKE_COMMAND
Feb 24, 2022
c61b68a
Changes needed for Windows compilation.
rburema Feb 24, 2022
5751f92
Nescesary for proper functioning .pyd on Windows.
rburema Feb 24, 2022
ea70846
This wasn't producng a proper dynamic library, not even on Windows.
rburema Feb 24, 2022
50bc179
Always include SIPMacros when find_package(SIP) is called
Feb 25, 2022
104968b
Moved CMakeBuilder to CMake build module location
Feb 25, 2022
12d420d
Added a install_sip_module to SIP CMake build module
Feb 25, 2022
b1325c9
Use the actual Python defined SO ABI extension
Feb 25, 2022
95a2a26
Make user cpp sources optional
Feb 25, 2022
287c7e5
If the sip build is not pre-set it should be here.
rburema Feb 25, 2022
ee282bd
Revert "Make user cpp sources optional"
rburema Feb 25, 2022
2aa1e48
Revert "Use the actual Python defined SO ABI extension"
rburema Feb 25, 2022
0c62785
Remove redundant sanitize_list macro
Feb 25, 2022
b991cc7
Sip 6 can handle enum class.
rburema Feb 25, 2022
83dffa4
Merge pull request #131 from Ultimaker/CURA-7924_sip_cmake_build
nallath Feb 28, 2022
1ffcc3d
Added StandardProjectSettings module
Mar 3, 2022
12fdb07
use arguments for function use_rpaths
Mar 4, 2022
cc167f1
escape dollar sign on ORIGIN rpath
Mar 4, 2022
de5ce6b
allways full RPATH
Mar 4, 2022
7376d78
set rpath for sip_<interface_target> target
Mar 4, 2022
805bcec
Revert "set rpath for sip_<interface_target> target"
jellespijker Mar 4, 2022
2deab5c
transfer rpath properties to sip_target
Mar 4, 2022
c34fbe4
Fixed setting of multiple paths
Mar 4, 2022
bdfc059
Added Linux AppImage paths
Mar 4, 2022
6014174
Sync SIPMAcros.cmake with Savitar
Mar 4, 2022
4dffd0c
Revert "Sync SIPMAcros.cmake with Savitar"
jellespijker Mar 4, 2022
12acc2d
Added relative rpath to lib from site-packages
jellespijker Mar 4, 2022
3c724a6
Also use relative rpath from loader
jellespijker Mar 8, 2022
58a94a0
Also add the ../Resources/lib/
Mar 8, 2022
659796e
Bumped up version and so version to 5
Mar 14, 2022
e6d6b6f
Allow usage of Conan
Mar 29, 2022
5d1d390
Set PYTHONPATH with cmake variable
Mar 31, 2022
053d794
Set PYTHONPATH with cmake variable
Apr 4, 2022
20dd9d0
Mimic find package variables Python
Apr 4, 2022
2f408d6
Also use PYTHONPATH when generating for the first time
Apr 4, 2022
26dbff7
Allow defining local site-package install path
Apr 5, 2022
766f634
Bump up minimum supported CMake version
jellespijker Apr 12, 2022
045fed6
Bump up minimum supported CMake version
jellespijker Apr 12, 2022
7350da2
Removed CPack support
jellespijker Apr 12, 2022
4ba8dda
Removed protobuf Module compatibility workaround
jellespijker Apr 12, 2022
2be1f55
Removed obsolete Export Header
jellespijker Apr 12, 2022
845b021
Revert "Removed obsolete Export Header"
jellespijker Apr 13, 2022
c8aed1b
Remove Example
jellespijker Apr 13, 2022
e583bb8
Review suggestion implemented
jellespijker Apr 13, 2022
9a89a3b
Remove obsolete jenkins file
jellespijker Apr 13, 2022
b42fae3
Add cmake-build to gitignore
jellespijker Apr 13, 2022
8504b4f
We don't use mingw anymore
jellespijker Apr 13, 2022
7373fbf
codestyle change on assure_out_of_source_builds
jellespijker Apr 13, 2022
6b1b7c2
Using BUILD_SHARED_LIBS flag instead of BUILD_STATIC
jellespijker Apr 13, 2022
24199a7
Remove CICD
jellespijker Apr 13, 2022
740514d
Fix wrong function call assure_out_of_source_builds
jellespijker Apr 14, 2022
55ac188
Use Python_VERSION for Cpython site-packages
Apr 14, 2022
6636816
Allow static build of the Python Module
Apr 14, 2022
a69cd0f
Allow in source builds
Apr 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 76 additions & 86 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,54 +1,17 @@
project(arcus)
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.20)
include(cmake/StandardProjectSettings.cmake)
AssureOutOfSourceBuilds()

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(GenerateExportHeader)
generate_export_header(Arcus EXPORT_FILE_NAME src/ArcusExport.h)

option(BUILD_PYTHON "Build " ON)
jellespijker marked this conversation as resolved.
Show resolved Hide resolved
option(BUILD_EXAMPLES "Build the example programs" ON)
option(BUILD_EXAMPLES "Build the example programs" OFF)
jellespijker marked this conversation as resolved.
Show resolved Hide resolved
option(BUILD_STATIC "Build as a static library" OFF)

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.

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")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
find_package(Protobuf 3.17.1 REQUIRED)

set(arcus_SRCS
src/Socket.cpp
Expand All @@ -67,58 +30,38 @@ set(arcus_HDRS
${CMAKE_CURRENT_BINARY_DIR}/src/ArcusExport.h
)

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()
set(ARCUS_VERSION 5.0.0)
set(ARCUS_SOVERSION 5)

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()

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()
set_project_standards(Arcus)
use_threads(Arcus)
set_rpath(TARGETS
Arcus
PATHS
"$<$<PLATFORM_ID:Linux>:usr/bin>"
"$<$<PLATFORM_ID:Linux>:usr/bin/lib>"
"$<$<PLATFORM_ID:Darwin>:../lib>"
RELATIVE)

target_include_directories(Arcus PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${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.
target_compile_definitions(Arcus PRIVATE -D_WIN32_WINNT=0x0600)
jellespijker marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -131,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()
Expand All @@ -163,4 +99,58 @@ 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(cpython ${Python_VERSION} QUIET COMPONENTS Interpreter Development)
if(NOT TARGET cpython::cpython)
find_package(Python ${Python_VERSION} EXACT REQUIRED COMPONENTS Interpreter Development)
else()
add_library(Python::Python ALIAS cpython::python)
set(Python_SITEARCH "${CMAKE_INSTALL_PREFIX}/lib/python3.10/site-packages")
jellespijker marked this conversation as resolved.
Show resolved Hide resolved
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}")

find_package(SIP REQUIRED 6.5.0)

add_library(pyArcus INTERFACE ${CMAKE_SOURCE_DIR}/python/PythonMessage.cpp)
set_project_standards(pyArcus)
set_rpath(TARGETS
pyArcus
PATHS
"$<$<PLATFORM_ID:Linux>:usr/bin>"
"$<$<PLATFORM_ID:Linux>:usr/bin/lib>"
"$<$<PLATFORM_ID:Darwin>:../lib>"
"$<$<PLATFORM_ID:Darwin>:../Resources/lib/>"
"../../"
RELATIVE)
use_threads(pyArcus)

target_include_directories(pyArcus
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/python/>
)

target_compile_features(pyArcus INTERFACE cxx_std_17)
jellespijker marked this conversation as resolved.
Show resolved Hide resolved
target_link_libraries(pyArcus INTERFACE Arcus protobuf::libprotobuf Python::Python)

add_sip_module(pyArcus)
if (DEFINED Python_SITELIB_LOCAL)
install_sip_module(pyArcus ${Python_SITELIB_LOCAL})
else()
install_sip_module(pyArcus)
endif ()
endif()
24 changes: 0 additions & 24 deletions CPackConfig.cmake

This file was deleted.

13 changes: 13 additions & 0 deletions cmake/CMakeBuilder.py
Original file line number Diff line number Diff line change
@@ -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()
107 changes: 40 additions & 67 deletions cmake/FindSIP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
jellespijker marked this conversation as resolved.
Show resolved Hide resolved

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 OR SIP_BUILD_EXECUTABLE)
# Already in cache, be silent
SET(SIP_FOUND TRUE)
ELSE()

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)
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()

mark_as_advanced(SIP_EXECUTABLE SIP_INCLUDE_DIRS SIP_VERSION)
include(${CMAKE_SOURCE_DIR}/cmake/SIPMacros.cmake)
ADD_DEFINITIONS(-DSIP_VERSION=0x${SIP_VERSION})
Loading