Skip to content

Commit

Permalink
use FindPython3.cmake, simplify CMakeLists and decrud cmake_extras
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Feb 7, 2025
1 parent 8d071f1 commit 8fa2608
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 1,147 deletions.
106 changes: 36 additions & 70 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ if(NOT DEFINED QTVER)
set(QTVER 6.8.2)
endif()

# Default to using newe findPython3 on Windows and Linux
if ( NOT DEFINED TRY_NEWER_FINDPYTHON3 )
if ( NOT APPLE )
set ( TRY_NEWER_FINDPYTHON3 1 )
else()
set ( TRY_NEWER_FINDPYTHON3 1 )
endif()
endif()

# Set to 1 to create and use a virtual Python venv on Windows and Linux.
# Use in conjunction with QTVER to download/install correct PySide6 module
if ( NOT DEFINED USE_VIRT_PY )
Expand All @@ -53,12 +44,6 @@ else()
set ( WIN_MIN_VERSION 6.1.7601 )
endif()

if (TRY_NEWER_FINDPYTHON3)
set ( USE_NEWER_FINDPYTHON3 1 )
else()
set ( USE_NEWER_FINDPYTHON3 0 )
endif()

set( CMAKE_DEBUG_POSTFIX "d" )
# Avoid the whole Release/Debug folder creation with Visual Studio
if (MSVC_IDE)
Expand Down Expand Up @@ -134,72 +119,53 @@ if (USE_SYSTEM_LIBS)
find_package( PkgConfig )
find_package( MiniZip )
pkg_check_modules( HUNSPELL hunspell )
if ( NOT APPLE )
pkg_check_modules( PCRE2 libpcre2-16 )
endif()
pkg_check_modules( PCRE2 libpcre2-16 )
endif()

message(STATUS "CMake version in use: ${CMAKE_VERSION}")

if (${USE_NEWER_FINDPYTHON3})
message(STATUS "Using newer findpython3 cmake module")
if ( APPLE )
# cmake's FindPython3 does *not* find frameworks based on precendence in PATH
# so set some pretty specific hints using our own FindPython3MacFramework.cmake first
find_package(Python3MacFramework 3.9 QUIET)
find_package(Python3 3.9 COMPONENTS Interpreter Development)
endif()
if ( WIN32 )
if ( DOWNLOAD_QT )
include(windownloadqt.cmake)
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/Qt${QTVER}/lib/cmake")
set(Qt6_Dir "${CMAKE_CURRENT_BINARY_DIR}/Qt${QTVER}/lib/cmake/Qt6")
if(NOT EXISTS "${Qt6_Dir}")
message(FATAL_ERROR "Qt6 download/configure unsuccessful!")
endif()
endif()
if ( USE_VIRT_PY )
include(winvirtpy.cmake)
# Set hints so virtual Python environement is found first
set(Python3_FIND_VIRTUAL ONLY)
set(Python3_FIND_REGISTRY NEVER)
set(Python3_FIND_STRATEGY LOCATION)
# Trick cmake's findPython3 module into thinking the virtual python is activated
set(VIRT_PATH "${CMAKE_CURRENT_BINARY_DIR}/sigilpy")
set(ENV{VIRTUAL_ENV} "${VIRT_PATH}")
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/sigilpy/Scripts/python.exe")
message(FATAL_ERROR "Virtual Python setup unsuccessful!")
endif()
endif()
find_package(Python3 3.9 REQUIRED COMPONENTS Interpreter Development)
endif()
if( UNIX AND NOT APPLE )
if ( USE_VIRT_PY )
# Must be run in an environment with the venv activated
set ( Python3_FIND_VIRTUAL ONLY )
add_definitions( -DLINUX_VIRT_PY )
message(STATUS "Using FindPython3 cmake module")
# Find Python3 module for both the build and bundling
if ( APPLE )
# cmake's FindPython3 does *not* find frameworks based on precendence in PATH
# so set some pretty specific hints using our own FindPython3MacFramework.cmake first
find_package(Python3MacFramework 3.9 QUIET)
find_package(Python3 3.9 COMPONENTS Interpreter Development)
endif()
if ( WIN32 )
if ( DOWNLOAD_QT )
include(windownloadqt.cmake)
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/Qt${QTVER}/lib/cmake")
set(Qt6_Dir "${CMAKE_CURRENT_BINARY_DIR}/Qt${QTVER}/lib/cmake/Qt6")
if(NOT EXISTS "${Qt6_Dir}")
message(FATAL_ERROR "Qt6 download/configure unsuccessful!")
endif()
find_package(Python3 3.9 COMPONENTS Interpreter Development)
endif()
else()
message(STATUS "Using older findpython cmake module")
if ( APPLE )
find_package(PythonMacFramework 3.9 QUIET)
if (NOT PythonMacFramework_FOUND)
find_package(PythonInterp 3.9)
find_package(PythonLibs 3.9)
if ( USE_VIRT_PY )
include(winvirtpy.cmake)
# Set hints so virtual Python environement is found first
set(Python3_FIND_VIRTUAL ONLY)
set(Python3_FIND_REGISTRY NEVER)
set(Python3_FIND_STRATEGY LOCATION)
# Trick cmake's findPython3 module into thinking the virtual python is activated
set(VIRT_PATH "${CMAKE_CURRENT_BINARY_DIR}/sigilpy")
set(ENV{VIRTUAL_ENV} "${VIRT_PATH}")
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/sigilpy/Scripts/python.exe")
message(FATAL_ERROR "Virtual Python setup unsuccessful!")
endif()
endif()
if ( WIN32 )
find_package(PythonInterp 3.9)
find_package (PythonLibs 3.9)
endif()
if( UNIX AND NOT APPLE )
find_package(PythonInterp 3.9)
find_package (PythonLibs 3.9)
find_package(Python3 3.9 REQUIRED COMPONENTS Interpreter Development)
endif()
if( UNIX AND NOT APPLE )
if ( USE_VIRT_PY )
# Must be run in an environment with the venv activated
set ( Python3_FIND_VIRTUAL ONLY )
add_definitions( -DLINUX_VIRT_PY )
endif()
find_package(Python3 3.9 COMPONENTS Interpreter Development)
endif()


# gumbo-parser it is our main xhtml/html5 parser.
# We have an internal version because it diverges from Google's and GitHub's
# versions and neither want's our epub specific changes.
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pre-2.X.X
New Features
- upgrade MacOS and Windows release and ci builds to use Qt 6.8.2
- upgrade MacOS and Windows release and ci builds to embed Python 3.13.2
- move all platforms to use cmake FindPython3 to simplify our cmake files and remove leftovers


Sigil-2.4.2
Expand Down
36 changes: 0 additions & 36 deletions cmake_extras/CMakeFindFrameworks.cmake

This file was deleted.

160 changes: 0 additions & 160 deletions cmake_extras/CMakeParseArguments.cmake

This file was deleted.

Loading

0 comments on commit 8fa2608

Please sign in to comment.