Skip to content

Commit 2f0640b

Browse files
committed
make: do not run cargo by cmake, just wrap build steps with standard make
Apparently CMake isn't great at handling build artifacts created by its custom command/target. IIUC, I do need a function that would be called add_custom_executable() so that I can replace the qmluic command while building it: add_custom_executable(qmluic COMMAND cargo build) add_executable(Qmluic::qmluic ALIAS qmluic) AFAIK, there's no easy way to describe such dependency. So let's reintroduce the Make wrapper, which is super easy to write and maintain so long as I don't care much about Windows.
1 parent 465226a commit 2f0640b

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

CMakeLists.txt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ include(CMakePackageConfigHelpers)
99
include(GNUInstallDirs)
1010
include(QmluicMacros)
1111

12-
find_program(CARGO_COMMAND cargo DOC "cargo command" REQUIRED)
13-
set(CARGO_BUILD_TARGET_DIR "${CMAKE_CURRENT_SOURCE_DIR}/target" CACHE PATH "cargo build directory")
12+
set(CARGO_BUILD_TARGET_DIR "${CMAKE_CURRENT_SOURCE_DIR}/target")
1413

15-
# Use the up-to-date version of the qmluic command.
16-
set(QMLUIC_COMMAND ${CARGO_COMMAND} run $<$<CONFIG:Release>:--release> --)
14+
set(QMLUIC_COMMAND "${CARGO_BUILD_TARGET_DIR}/$<IF:$<CONFIG:Release>,release,debug>/qmluic")
1715

1816
# Help Qt Creator find our type stub
1917
set(QML_IMPORT_PATH "${CMAKE_CURRENT_BINARY_DIR}/imports" CACHE STRING "" FORCE)
@@ -34,14 +32,6 @@ endif()
3432

3533
add_subdirectory(uiviewer)
3634

37-
add_custom_target(qmluic ALL
38-
COMMAND
39-
${CARGO_COMMAND} build --workspace $<$<CONFIG:Release>:--release>
40-
--target-dir "${CARGO_BUILD_TARGET_DIR}"
41-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
42-
USES_TERMINAL
43-
)
44-
4535
qmluic_add_qmldir(qmluic.QtWidgets Qt${QT_VERSION_MAJOR}::Widgets)
4636

4737
configure_package_config_file(cmake/QmluicConfig.cmake.in

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ BUILD_TYPE = Debug
1212
DESTDIR =
1313
PREFIX = /usr/local
1414

15+
CARGO_BUILD_FLAGS =
16+
CMAKE_FLAGS =
17+
1518
DEB_VERSION = 0.1~$(shell date +"%Y%m%d").git$(shell git rev-parse --short HEAD)
1619
QT_VERSION_MAJOR = $(word 1,$(subst ., ,$(shell $(QMAKE) -query QT_VERSION)))
1720

21+
ifeq ($(BUILD_TYPE),Release)
22+
override CARGO_BUILD_FLAGS += --release
23+
endif
24+
1825
ifneq ($(shell command -v $(NINJA) 2>/dev/null),)
1926
CMAKE_FLAGS += -GNinja
2027
endif
@@ -36,6 +43,8 @@ help:
3643
@echo ' build-examples - generate .ui from example .qml files and build them'
3744
@echo
3845
@echo 'Make variables:'
46+
@echo ' BUILD_TYPE=$(BUILD_TYPE)'
47+
@echo ' CARGO_BUILD_FLAGS=$(CARGO_BUILD_FLAGS)'
3948
@echo ' CMAKE_FLAGS=$(CMAKE_FLAGS)'
4049
@echo ' QT_VERSION_MAJOR=$(QT_VERSION_MAJOR)'
4150

@@ -50,6 +59,7 @@ release:
5059
.PHONY: build
5160
build:
5261
mkdir -p $(BUILD_DIR)
62+
$(CARGO) build $(CARGO_BUILD_FLAGS) --workspace
5363
cd $(BUILD_DIR) && $(CMAKE) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
5464
-DCMAKE_INSTALL_PREFIX=$(PREFIX) $(CMAKE_FLAGS) $(CURDIR)
5565
$(CMAKE) --build $(BUILD_DIR) --config $(BUILD_TYPE)
@@ -78,7 +88,7 @@ format:
7888
.PHONY: tests
7989
tests:
8090
$(CARGO) clippy
81-
$(CARGO) test --workspace
91+
$(CARGO) test $(CARGO_BUILD_FLAGS) --workspace
8292

8393
.PHONY: build-examples
8494
build-examples: BUILD_DIR = target/build-examples

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ Optional requirements for previewer and type stubs:
126126
- CMake
127127
- Qt 5.15 or 6.2+
128128

129-
If you have all requirements installed, use CMake (or GNU Make) to build
130-
and install everything.
129+
If you have all requirements installed, use Cargo and CMake to build/install
130+
the binaries and data. There's a GNU Make wrapper to automate the build steps.
131+
132+
```
133+
$ make release install
134+
```
131135

132136
If you just need to build the `qmluic` frontend, simply run
133137
`cargo build --release --workspace`.

0 commit comments

Comments
 (0)