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 #41

Merged
merged 29 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2e38a9d
Porting CMake SIP build module from Arcus.
Feb 25, 2022
7661354
Export CMake compile commands
Feb 25, 2022
18037ee
Use SIP 6.5.0 types and methods
Feb 25, 2022
c201485
Synced SIPMacros.cmake from Arcus
Feb 25, 2022
25fa38d
Merge pull request #39 from Ultimaker/CURA-7924_sip_cmake_build
nallath Feb 28, 2022
3713706
Use StandardProjectSettings
Mar 4, 2022
a900f9f
Added relative rpath to lib from site-packages
Mar 4, 2022
1264a20
Also use loader as relative rpath
Mar 8, 2022
7a0baf1
Also add the ../Resources/lib/
Mar 8, 2022
867230f
Allow setting the sip-build externally
Mar 30, 2022
586a2e9
Obtain CPython from Conan dependency if available
Ghostkeeper Apr 1, 2022
9d050f8
Pass exported variables on when finding via Conan
Ghostkeeper Apr 1, 2022
735e0e7
Allow setting the sip-build externally
Apr 4, 2022
894f02c
Also use PYTHONPATH when generating for the first time
Apr 4, 2022
5590b68
Don't touch when re-generating
Apr 5, 2022
f6211eb
Allow installing to alternative site-packages
Apr 5, 2022
85d20a9
Bump up minimum supported CMake version
jellespijker Apr 12, 2022
1dede18
remove old cmake include generate header
jellespijker Apr 12, 2022
cdbb99f
removed redundant find_package call to threads
jellespijker Apr 12, 2022
23556fe
Bumped up version and SO version to 5.0
jellespijker Apr 12, 2022
67a2e1e
Revert "remove old cmake include generate header"
jellespijker Apr 13, 2022
b89462b
Renamed assure_out_of_source_builds
jellespijker Apr 14, 2022
b405b86
Use BUILD_SHARED_LIBS instead of BUILD_STATIC
Apr 14, 2022
4cca70a
Don't link against Threads
Apr 14, 2022
694465e
No need to sett compile feature cxx_std_17
Apr 14, 2022
9a9a680
clarify the relative rpath
Apr 14, 2022
7f22b76
Use Python_VERSION for CPython site-package path
Apr 14, 2022
1c87af4
Allow static builds of the Python Module
Apr 14, 2022
6be8b67
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
125 changes: 69 additions & 56 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
project(savitar)
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(Savitar EXPORT_FILE_NAME src/SavitarExport.h)

option(BUILD_PYTHON "Build " ON)
option(BUILD_STATIC "Build as a static library" OFF)
Expand All @@ -12,40 +14,10 @@ option(BUILD_TESTS "Building the test-suite" OFF)
if(BUILD_TESTS)
message(STATUS "Building with tests...")
find_package(GTest REQUIRED)
find_package(Threads QUIET)
endif()

add_subdirectory(pugixml)

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)
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} ${Python3_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()

set(savitar_SRCS
src/Namespace.cpp
src/ThreeMFParser.cpp
Expand All @@ -68,32 +40,80 @@ set(savitar_HDRS
${CMAKE_CURRENT_BINARY_DIR}/src/SavitarExport.h
)

set(SAVITAR_VERSION 0.1.2)
set(SAVITAR_SOVERSION 0)

set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
set(SAVITAR_VERSION 5.0.0)
set(SAVITAR_SOVERSION 5)

if(BUILD_STATIC)
add_library(Savitar STATIC ${savitar_SRCS})
else()
add_library(Savitar SHARED ${savitar_SRCS})
endif()

set(Savitar_LINK_LIBRARIES pugixml)
if(CMAKE_USE_PTHREADS_INIT)
list(APPEND Savitar_LINK_LIBRARIES pthread)
endif()
target_link_libraries(Savitar PUBLIC ${Savitar_LINK_LIBRARIES})
set_project_standards(Savitar)
use_threads(Savitar)
jellespijker marked this conversation as resolved.
Show resolved Hide resolved
set_rpath(TARGETS
Savitar
PATHS
"$<$<PLATFORM_ID:Linux>:usr/bin>"
"$<$<PLATFORM_ID:Linux>:usr/bin/lib>"
"$<$<PLATFORM_ID:Darwin>:../lib>"
"$<$<PLATFORM_ID:Darwin>:../Resources/lib>"
RELATIVE)

if(NOT WIN32 OR CMAKE_COMPILER_IS_GNUCXX)
set_target_properties(Savitar PROPERTIES COMPILE_FLAGS -fPIC)
endif()
target_link_libraries(Savitar PUBLIC pugixml)

if(BUILD_PYTHON)
set(SIP_EXTRA_FILES_DEPEND python/Types.sip python/MeshData.sip python/SceneNode.sip python/Scene.sip)
#set(SIP_EXTRA_SOURCE_FILES python/Types.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(Savitar python/ThreeMFParser.sip Savitar)
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::cpython)
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(pySavitar INTERFACE)
set_project_standards(pySavitar)
set_rpath(TARGETS
pySavitar
PATHS
"$<$<PLATFORM_ID:Linux>:usr/bin>"
"$<$<PLATFORM_ID:Linux>:usr/bin/lib>"
"$<$<PLATFORM_ID:Darwin>:../lib>"
"../../"
jellespijker marked this conversation as resolved.
Show resolved Hide resolved
RELATIVE)
use_threads(pySavitar)
jellespijker marked this conversation as resolved.
Show resolved Hide resolved

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

target_compile_features(pySavitar INTERFACE cxx_std_17)
target_link_libraries(pySavitar INTERFACE Savitar Python::Python)

add_sip_module(pySavitar)
if(Python_SITELIB_LOCAL)
install_sip_module(pySavitar ${Python_SITELIB_LOCAL})
else()
install_sip_module(pySavitar)
endif()
endif()

target_include_directories(Savitar PUBLIC
Expand All @@ -103,7 +123,7 @@ target_include_directories(Savitar PUBLIC

if(${CMAKE_BUILD_TYPE})
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
add_definitions(-DSAVITAR_DEBUG)
target_compile_definitions(Savitar -DSAVITAR_DEBUG)
endif()
endif()

Expand All @@ -117,13 +137,6 @@ set_target_properties(Savitar PROPERTIES
VISIBILITY_INLINES_HIDDEN 1
)

generate_export_header(Savitar
EXPORT_FILE_NAME src/SavitarExport.h
)
# This is required when building out-of-tree.
# The compiler won't find the generated header otherwise.
include_directories(${CMAKE_BINARY_DIR}/src)

install(TARGETS Savitar
EXPORT Savitar-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
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()
106 changes: 40 additions & 66 deletions cmake/FindSIP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +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.

if(APPLE)
# Workaround for broken FindPythonLibs. It will always find Python 2.7 libs on OSX
set(CMAKE_FIND_FRAMEWORK LAST)
endif()

# FIXME: Use the new FindPython3 module rather than these. New in CMake 3.12.
# However currently that breaks on our CI server, since the CI server finds the built-in Python3.6 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})

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})
57 changes: 57 additions & 0 deletions cmake/FindSIP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2007, Simon Edwards <[email protected]>
# 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 <[email protected]> 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 <[email protected]> ''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 <[email protected]> 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 <[email protected]>
# 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
jellespijker marked this conversation as resolved.
Show resolved Hide resolved
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)
Loading