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

use CLI C++ code generator with CMake, put crates in cargo workspace #173

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .github/workflows/github-cxx-qt-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
# TODO: Remove PPA for Qt 5.15 when Ubuntu 22.04 is available
# https://github.com/KDAB/cxx-qt/issues/121
ppa: ppa:savoury1/qt-5-15
# FIXME: linking fails with GNU ld
ldflags: '-fuse-ld=lld'
packages-extra: >-
qtbase5-dev
qtdeclarative5-dev
Expand All @@ -38,6 +40,8 @@ jobs:
# TODO: Remove PPA for Qt 6 when Ubuntu 22.04 is available
# https://github.com/KDAB/cxx-qt/issues/121
ppa: ppa:daschuer/qt6-backports
# FIXME: linking fails with GNU ld
ldflags: '-fuse-ld=lld'
packages-extra: >-
qt6-base-dev
qt6-declarative-dev
Expand Down Expand Up @@ -158,6 +162,7 @@ jobs:
sudo apt-get update &&
sudo apt-get install -y
ninja-build
lld
clang-format-12
libssl-dev
pkg-config
Expand Down Expand Up @@ -203,6 +208,7 @@ jobs:
RUSTC_WRAPPER: sccache
CC: ${{ matrix.cc }}
CXX: ${{ matrix.cxx }}
LDFLAGS: ${{ matrix.ldflags }}
- name: "Build"
run: cmake --build build --config Release --parallel 2
working-directory: ${{ matrix.workspace }}
Expand Down
72 changes: 69 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ else()
option(VCPKG "Use vcpkg for dependencies" OFF)
endif()

if(WIN32)
set(EXE_SUFFIX ".exe")
endif()

if(VCPKG)
# Explicitly setting QT_DEFAULT_MAJOR_VERSION can fail on systems that have both Qt6
# and Qt5 installed, so only set it automatically when using vcpkg.
Expand All @@ -40,12 +44,10 @@ if(VCPKG)
if(NOT DEFINED ENV{VCPKG_BINARY_SOURCES})
if(WIN32)
set(COMMAND_PREIFX "")
set(EXE_SUFFIX ".exe")
set(SCRIPT_SUFFIX ".bat")
set(DOTNET_RUNTIME "")
else()
set(COMMAND_PREFIX "./")
set(EXE_SUFFIX "")
set(SCRIPT_SUFFIX ".sh")
set(DOTNET_RUNTIME "mono")
endif()
Expand Down Expand Up @@ -101,9 +103,73 @@ project(cxx_qt)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(CompilerCaching)

set(CORROSION_VERSION 0.2.1)
find_package(Corrosion ${CORROSION_VERSION} QUIET)
if(NOT Corrosion_FOUND)
message(STATUS "Corrosion not found, downloading...")
include(FetchContent)
FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v${CORROSION_VERSION}
)
FetchContent_MakeAvailable(Corrosion)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cxx-qt-lib")
include(CxxQt)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui REQUIRED)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CARGO_BUILD_TYPE "--release")
set(CARGO_BUILD_TYPE_DIR "release")
else()
set(CARGO_BUILD_TYPE_DIR "debug")
endif()

# FIXME: cxx's build.rs fails without this.
# https://github.com/dtolnay/cxx/issues/1020
if(APPLE)
set(ENV{SDKROOT} ${CMAKE_OSX_SYSROOT})
endif()

message(STATUS "Building C++ code generator and generating C++ library")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS cxx-qt-lib)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS cxx-qt-cli)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS cxx-qt-gen)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS cxx-qt-build)
set(CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/cargo")
set(CXXQT_CPP_LIB_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxx-qt-cpplib")
execute_process(
COMMAND ${CMAKE_COMMAND} -E env
"CARGO_TARGET_DIR=${CARGO_TARGET_DIR}"
"SDKROOT=${CMAKE_OSX_SYSROOT}"
"CXX_QT_LIB_OUT_DIR=${CXXQT_CPP_LIB_GENERATED_DIR}"
cargo build ${CARGO_BUILD_TYPE}
--manifest-path "${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml"
--package cxx-qt-cli
--package cxx-qt-lib
)
set(CXXQTBRIDGE_EXECUTABLE "${CARGO_TARGET_DIR}/${CARGO_BUILD_TYPE_DIR}/cxxqtbridge${EXE_SUFFIX}")

add_subdirectory(${CXXQT_CPP_LIB_GENERATED_DIR})

# This is extremely hacky, but such is CMake. The find_package calls
# in the examples don't actually work because the CMake package config files
# are not generated until install time. One would think the export() command
# could work around this; however, it does not. The export() command does not
# create the CxxQt{5/6}Targets.cmake file until the *end* of the configure
# step, so find_package in the examples can't depend on the targets file
# generated by export(). By creating this library alias target, the
# CMakeLists.txt in the examples can actually serve as examples of how
# downstream projects should write their CMakeLists.txt. The examples can
# use find_package with QUIET and without REQUIRE so the find_package call
# serves as an example but doesn't actually do anything. Because CMake.
add_library(CxxQt${QT_VERSION_MAJOR}::cxxqt ALIAS cxxqt)

# Enable extra Qt definitions for all projects
add_compile_definitions(
QT_NO_CAST_FROM_ASCII
Expand Down
22 changes: 22 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
# SPDX-FileContributor: Be Wilson <[email protected]>
#
# SPDX-License-Identifier: MIT OR Apache-2.0

[workspace]
members = [
"cxx-qt",
"cxx-qt-build",
"cxx-qt-cli",
"cxx-qt-gen",

"examples/demo_threading",
"examples/qml_extension_plugin/core",
"examples/qml_features",
"examples/qml_minimal",
"examples/qml_with_threaded_logic",

"tests/basic_cxx_only",
"tests/basic_cxx_qt",
"tests/qt_types_standalone",
]
115 changes: 0 additions & 115 deletions cmake/CxxQt.cmake

This file was deleted.

4 changes: 0 additions & 4 deletions cxx-qt-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ description = "Helpers for integrating `cxx-qt` crate into a Cargo build"
repository = "https://github.com/KDAB/cxx-qt/"

[dependencies]
clang-format = "0.1"
cxx-gen = "0.7"
cxx-qt-lib = { path = "../cxx-qt-lib", version = "0.3" }
cxx-qt-gen = { path = "../cxx-qt-gen", version = "0.3" }
proc-macro2 = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
syn = { version = "1.0", features = ["extra-traits", "full", "parsing"] }
quote = "1.0"
convert_case = "0.4"
Loading