Skip to content
Merged
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
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ members = [
"crates/cxx-qt-build",
"crates/cxx-qt-gen",
"crates/cxx-qt-lib",
"crates/cxx-qt-lib-headers",
"crates/qt-build-utils",
"crates/cxx-qt-lib-extras-headers",
"crates/cxx-qt-lib-extras",

"examples/cargo_without_cmake",
Expand Down Expand Up @@ -39,9 +37,7 @@ cxx-qt-macro = { path = "crates/cxx-qt-macro", version = "0.6.1" }
cxx-qt-build = { path = "crates/cxx-qt-build", version = "0.6.1" }
cxx-qt-gen = { path = "crates/cxx-qt-gen", version = "0.6.1" }
cxx-qt-lib = { path = "crates/cxx-qt-lib", version = "0.6.1" }
cxx-qt-lib-headers = { path = "crates/cxx-qt-lib-headers", version = "0.6.1" }
qt-build-utils = { path = "crates/qt-build-utils", version = "0.6.1" }
cxx-qt-lib-extras-headers = { path = "crates/cxx-qt-lib-extras-headers", version = "0.6.1" }
cxx-qt-lib-extras = { path = "crates/cxx-qt-lib-extras", version = "0.6.1" }

cc = { version = "1.0.89", features = ["parallel"] }
Expand Down
24 changes: 11 additions & 13 deletions cmake/CxxQt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function(cxxqt_import_crate)
"QMAKE=${IMPORT_CRATE_QMAKE}"
$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>)

file(MAKE_DIRECTORY "${IMPORT_CRATE_CXXQT_EXPORT_DIR}/include/${CRATE}")
target_include_directories(${CRATE} INTERFACE "${IMPORT_CRATE_CXXQT_EXPORT_DIR}/include/${CRATE}")
file(MAKE_DIRECTORY "${IMPORT_CRATE_CXXQT_EXPORT_DIR}/crates/${CRATE}/include/")
target_include_directories(${CRATE} INTERFACE "${IMPORT_CRATE_CXXQT_EXPORT_DIR}/crates/${CRATE}/include/")

set_target_properties(${CRATE}
PROPERTIES
Expand All @@ -53,27 +53,25 @@ function(cxxqt_import_crate)
# cxx-qt-build generates object files that need to be linked to the final target.
# These are the static initializers that would be removed as an optimization if they're not referenced.
# So add them to an object library instead.
file(MAKE_DIRECTORY "${IMPORT_CRATE_CXXQT_EXPORT_DIR}/initializers/")
file(MAKE_DIRECTORY "${IMPORT_CRATE_CXXQT_EXPORT_DIR}/crates/${CRATE}/")
# When using the Ninja generator, we need to provide **some** way to generate the object file
# Unfortunately I'm not able to tell corrosion that this obj file is indeed a byproduct, so
# create a fake target for it.
# This target doesn't need to do anything, because the file should already exist after building the crate.
add_custom_target(${CRATE}_mock_initializers
COMMAND ${CMAKE_COMMAND} -E true
DEPENDS ${CRATE}
BYPRODUCTS "${IMPORT_CRATE_CXXQT_EXPORT_DIR}/initializers/${CRATE}.o")
BYPRODUCTS "${IMPORT_CRATE_CXXQT_EXPORT_DIR}/crates/${CRATE}/initializers.o")

add_library(${CRATE}_initializers OBJECT IMPORTED)
set_target_properties(${CRATE}_initializers
PROPERTIES
IMPORTED_OBJECTS "${IMPORT_CRATE_CXXQT_EXPORT_DIR}/initializers/${CRATE}.o")
IMPORTED_OBJECTS "${IMPORT_CRATE_CXXQT_EXPORT_DIR}/crates/${CRATE}/initializers.o")
# Note that we need to link using TARGET_OBJECTS, so that the object files are included **transitively**, otherwise
# Only the linker flags from the object library would be included, but not the actual object files.
# See also the "Linking Object Libraries" and "Linking Object Libraries via $<TARGET_OBJECTS>" sections:
# https://cmake.org/cmake/help/latest/command/target_link_libraries.html
target_link_libraries(${CRATE} INTERFACE ${CRATE}_initializers $<TARGET_OBJECTS:${CRATE}_initializers>)

message(VERBOSE "CXX-Qt Expects QML plugin: ${QML_MODULE_URI} in directory: ${QML_MODULE_PLUGIN_DIR}")
endforeach()

endfunction()
Expand All @@ -98,9 +96,9 @@ function(cxxqt_import_qml_module target)
endif()

# Note: This needs to match the URI conversion in cxx-qt-build
string(REPLACE "." "_" plugin_name ${QML_MODULE_URI})
set(QML_MODULE_PLUGIN_DIR "${QML_MODULE_EXPORT_DIR}/plugins/${plugin_name}")
file(MAKE_DIRECTORY ${QML_MODULE_PLUGIN_DIR})
string(REPLACE "." "_" module_name ${QML_MODULE_URI})
set(QML_MODULE_DIR "${QML_MODULE_EXPORT_DIR}/qml_modules/${module_name}")
file(MAKE_DIRECTORY ${QML_MODULE_DIR})

# QML plugin - init target
# When using the Ninja generator, we need to provide **some** way to generate the object file
Expand All @@ -110,13 +108,13 @@ function(cxxqt_import_qml_module target)
add_custom_target(${target}_mock_obj_output
COMMAND ${CMAKE_COMMAND} -E true
DEPENDS ${QML_MODULE_SOURCE_CRATE}
BYPRODUCTS "${QML_MODULE_PLUGIN_DIR}/plugin_init.o")
BYPRODUCTS "${QML_MODULE_DIR}/plugin_init.o")

add_library(${target} OBJECT IMPORTED)
set_target_properties(${target}
PROPERTIES
IMPORTED_OBJECTS "${QML_MODULE_PLUGIN_DIR}/plugin_init.o")
IMPORTED_OBJECTS "${QML_MODULE_DIR}/plugin_init.o")
target_link_libraries(${target} INTERFACE ${QML_MODULE_SOURCE_CRATE})

message(VERBOSE "CXX-Qt Expects QML plugin: ${QML_MODULE_URI} in directory: ${QML_MODULE_PLUGIN_DIR}")
message(VERBOSE "CXX-Qt Expects QML plugin: ${QML_MODULE_URI} in directory: ${QML_MODULE_DIR}")
endfunction()
3 changes: 3 additions & 0 deletions crates/cxx-qt-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ quote.workspace = true
qt-build-utils.workspace = true
codespan-reporting = "0.11"
version_check = "0.9"
scratch = "1.0"
serde = { version = "1.0", features = ["default", "derive"] }
serde_json = "1.0"

[features]
link_qt_object_files = ["qt-build-utils/link_qt_object_files"]
Loading