Skip to content

add CMake build system support #240

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

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
57 changes: 57 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CMake CI

on:
push:
branches:
- master

Copy link
Contributor

@mrbean-bremen mrbean-bremen Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to trigger on pull-request to be able to see it in the PR build.
But you probably know that...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generator seems to need some changes, the path to the fetched header file is not always correct in different environments

jobs:
build-and-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
qt_version: [5, 6]
python_version: ["3.8", "3.9", "3.10"]
fail-fast: false

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that you missed the apostrophes here, you need

with:
  python-version: '${{ matrix.python-version }}'

otherwise it won't work.
It would really be much easier for you to just take the setup part form build_latest.yaml, which is working, instead of trying to do it all manually again.
In case you haven't given up on this...

- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
if [ "${{ matrix.qt_version }}" = "5" ]; then
sudo apt-get install -y qtbase5-dev qt5-default
else
sudo apt-get install -y qt6-base-dev
fi

- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: |
choco install qt${{ matrix.qt_version }} --version ${{ matrix.qt_version }}.0.0 --params "/InstallationFolder C:/Qt/${{ matrix.qt_version }}"
echo "C:/Qt/${{ matrix.qt_version }}/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Configure CMake
run: |
mkdir build
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=./install

- name: Build project
run: |
cmake --build build --parallel --target all install

- name: Run tests
run: |
cd build
ctest --output-on-failure
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.27)

project(PythonQt LANGUAGES CXX VERSION 3.5.6)

enable_testing()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Python3 COMPONENTS Development)

set(PYTHONQT_SUFFIX Qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}-Python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR})

add_subdirectory(generator)
add_subdirectory(src)
add_subdirectory(extensions)
add_subdirectory(tests)
# add_subdirectory(examples)
1 change: 1 addition & 0 deletions extensions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(PythonQt_QtAll)
92 changes: 92 additions & 0 deletions extensions/PythonQt_QtAll/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
project(QtAll LANGUAGES CXX)

set(CMAKE_AUTOMOC ON)

file(GLOB SOURCES *.h *.cpp)

if(BUILD_SHARED_LIBS)
add_library(${PROJECT_NAME} SHARED)
target_compile_definitions(${PROJECT_NAME} PRIVATE PYTHONQT_QTALL_EXPORTS)
else()
add_library(${PROJECT_NAME} STATIC)
target_compile_definitions(${PROJECT_NAME} PUBLIC PYTHONQT_QTALL_STATIC)
endif()

target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})

target_link_libraries(${PROJECT_NAME} PUBLIC Core)

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR})

list(APPEND QTMODULES Core Gui Svg Sql Network OpenGL Xml XmlPatterns Multimedia Qml Quick UiTools WebEngineWidgets WebKit)

find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QTMODULES})

foreach(QtModule IN LISTS QTMODULES)
if(NOT TARGET "Qt${QT_VERSION_MAJOR}::${QtModule}")
continue()
endif()

string(TOUPPER ${QtModule} QTMODULE)
target_sources(${PROJECT_NAME} PRIVATE ${PYTHONQT_WRAPPER_${QTMODULE}_SOURCES})
target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::${QtModule})
target_compile_definitions(${PROJECT_NAME} PRIVATE PYTHONQT_WITH_${QTMODULE})
endforeach()

if(TARGET "Qt${QT_VERSION_MAJOR}::Gui")
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets PrintSupport REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::PrintSupport
)
endif()

if(TARGET "Qt${QT_VERSION_MAJOR}::Svg" AND QT_VERSION_MAJOR VERSION_GREATER_EQUAL 6)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS SvgWidgets REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::SvgWidgets
)
endif()

if(TARGET "Qt${QT_VERSION_MAJOR}::Multimedia")
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS MultimediaWidgets REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::MultimediaWidgets
)
endif()

if(TARGET "Qt${QT_VERSION_MAJOR}::Quick")
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS QuickWidgets REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::QuickWidgets
)
endif()

if(TARGET "Qt${QT_VERSION_MAJOR}::WebKit")
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS WebKitWidgets REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::WebKitWidgets
)
endif()

file(GLOB PUBLIC_HEADER *.h)

set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_NAME PythonQt-QtAll-${PYTHONQT_SUFFIX}
PUBLIC_HEADER "${PUBLIC_HEADER}"
)

if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE "/bigobj")
elseif(MINGW)
target_compile_options(${PROJECT_NAME} PRIVATE "-Wa,-mbig-obj")
endif()

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
16 changes: 9 additions & 7 deletions extensions/PythonQt_QtAll/PythonQt_QtAll.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@
*
*/

#ifdef WIN32
#ifdef PYTHONQT_QTALL_EXPORTS
#define PYTHONQT_QTALL_EXPORT __declspec(dllexport)
#else
#define PYTHONQT_QTALL_EXPORT __declspec(dllimport)
#endif
#include <QtCore/qglobal.h>

#ifndef PYTHONQT_QTALL_STATIC
# if defined(PYTHONQT_QTALL_EXPORTS)
# define PYTHONQT_QTALL_EXPORT Q_DECL_EXPORT
# else
# define PYTHONQT_QTALL_EXPORT Q_DECL_IMPORT
# endif
#else
#define PYTHONQT_QTALL_EXPORT
# define PYTHONQT_QTALL_EXPORT
#endif

namespace PythonQt_QtAll
Expand Down
Loading
Loading