So, I was trying to do a script to pass to install(SCRIPT ...)
to package an application.
For clarity of where my problem comes from, I was trying to run windeployqt.exe [...] myapp.exe
from the script.
This is what I wrote:
This file is DeployOnWindows.cmake[.in]
:
execute_process(
COMMAND @WINDEPLOYQT_EXECUTABLE@ --dry-run --no-compiler-runtime --list
mapping $<TARGET_FILE:app>
OUTPUT_VARIABLE _output
OUTPUT_STRIP_TRAILING_WHITESPACE)
# [...]
And in the main CMakeLists.txt
I have something like:
# [...]
add_executable(app src/main.cpp)
target_link_libraries(app Qt5::Widgets)
# [...]
install(TARGETS app)
find_program(
WINDEPLOYQT_EXECUTABLE
NAMES windeployqt
HINTS ${QTDIR} ENV QTDIR
PATH_SUFFIXES bin)
# And this is what I want to do:
# Maybe "${CMAKE_BINARY_DIR}/DeployOnWindows.cmake" after configuration from a DeployOnWindows.cmake.in...
install(SCRIPT "DeployOnWindows.cmake")
include(CPack)
Now, the problem: notice that my eventual .in file has both an @
variable, and a generator expression.
I started looking at my options:
-
configure_file
does not deal with generator expressions. -
file(GENERATE OUTPUT [...] INPUT [...])
does deal with generator expressions but not with@
variable substitution.- Very interestingly, and “New in version 3.18”,
file(GENERATE OUTPUT [...] CONTENT [...])
does work with both but theINPUT
version doesn’t.
- Very interestingly, and “New in version 3.18”,
I tried this, out of desperation:
# This handles generator expressions
file(
GENERATE
OUTPUT "${CMAKE_BINARY_DIR}/DeployOnWindows.cmake.in"
INPUT "${CMAKE_SOURCE_DIR}/DeployOnWindows.cmake.in")
# This handles variable names
configure_file("${CMAKE_BINARY_DIR}/DeployOnWindows.cmake.in"
"${CMAKE_BINARY_DIR}/DeployOnWindows.cmake" @ONLY)
But configure_file
does not find the file and errors out the generation. But it does work after generating again. The file on the CMAKE_BINARY_DIR
from file(GENERATE ...
does get created, but it seems as if only after CMake stops. I don’t understand it.
So, are there suggestions to what I can do to achieve this?