Detect current CMake configuration type. How?
-
As I said - multi-configuration generators like msbuild or even Ninja nowadays (afair) don't have a build type during configure time.
If you want to add sources depeding on the build type use what the documentation and I wrote. -
Based on Debug or Release even Qt Creator were showing different files. It was making developing process simple and clear. For now because of this generators need to add all of the versions of the files and only one will be used when building but all of them in sources in Qt Creator.
-
In my project only XCode used. Why the simplicity of just "if-else" exchanged on complexity of the tricks of f-wording generators???
@bogong said in Detect current CMake configuration type. How?:
Why the simplicity of just "if-else" exchanged on complexity of the tricks of f-wording generators
There is no need for the kind of language here.
CMake is complex, because cross-platform build engineering is inherently complex. When you use a tool you need to understand it, and the fact that CMake has distinct configuration, generation and build phases (each with its' own way of specifying what should run at that phase) is often uncomfortable but important.
@bogong said in Detect current CMake configuration type. How?:
${CMAKE_BUILD_TYPE} variable. It's just empty.
@bogong said in Detect current CMake configuration type. How?:
In my project only XCode used
Xcode is exactly one of the generators that are multi-configuration (alongside MSBuild); where the same set of final build system files (i.e post configuration/generation) is used to make all build configuration. The variable is empty because variables are set during the configuration phase, and it wasn't set. As you shown, the actual build configuration is only passed to the
cmake --build
invocation - hence only available during the build phase.This is pretty unavoidable, even if you try to manually pass
-DCMAKE_BUILD_TYPE=Debug
or something to CMake directly alongside-G Xcode
to do a a manual CMake configuration, it will just be ignored. That's how Xcode project files work... If that's what Qt Creator's wrapper is doing, what Qt Creator shows is of no relevance.Also see this note in CMake documentation: https://cmake.org/cmake/help/v4.1/generator/Xcode.html#limitations
@bogong said in Detect current CMake configuration type. How?:
For example for iOS for Debug - one Info.plist file for Release another one set of the files.
Even on generators that do support that (and again, Xcode doesn't) CMake doesn't make this pattern very easy - mostly because it is a bit of an abuse of the concept of build configurations. Configurations are meant to affect the flags that are passed to the build tools when making targets, not so much the shape of the dependency graph of the targets among themselves.
Luckily that's not what you are actually trying to do (although you appear to think so) - you don't want different files between build configurations, you want different content for the same file. That can certainly be done, with a custom build target. This is completely unrelated to Qt, but there are many examples around and if you want to delve into this the CMake Discourse site will be more appropriate place. You'll probably love the syntax even less than the one for generator expressions though... (not that you have much of a choice, really).
-
Now we finally have a usecase where we also can answer...
See https://cmake.org/cmake/help/latest/command/target_sources.htmltarget_sources(MyTarget PRIVATE "$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/dbgsrc.cpp>")
@Christian-Ehrlicher said in Detect current CMake configuration type. How?:
"$<$CONFIG:Debug:${CMAKE_CURRENT_SOURCE_DIR}/dbgsrc.cpp>"
This is what in result when using your way. The CMake settings is:
qt_add_executable(${A_NAME_APPLICATION} "$<$<CONFIG:Debug>:Platforms/Debug/IOS/Info.plist>")
Is it next one Qt Creator bug? Or it's normal behavior?
-
@bogong said in Detect current CMake configuration type. How?:
Why the simplicity of just "if-else" exchanged on complexity of the tricks of f-wording generators
There is no need for the kind of language here.
CMake is complex, because cross-platform build engineering is inherently complex. When you use a tool you need to understand it, and the fact that CMake has distinct configuration, generation and build phases (each with its' own way of specifying what should run at that phase) is often uncomfortable but important.
@bogong said in Detect current CMake configuration type. How?:
${CMAKE_BUILD_TYPE} variable. It's just empty.
@bogong said in Detect current CMake configuration type. How?:
In my project only XCode used
Xcode is exactly one of the generators that are multi-configuration (alongside MSBuild); where the same set of final build system files (i.e post configuration/generation) is used to make all build configuration. The variable is empty because variables are set during the configuration phase, and it wasn't set. As you shown, the actual build configuration is only passed to the
cmake --build
invocation - hence only available during the build phase.This is pretty unavoidable, even if you try to manually pass
-DCMAKE_BUILD_TYPE=Debug
or something to CMake directly alongside-G Xcode
to do a a manual CMake configuration, it will just be ignored. That's how Xcode project files work... If that's what Qt Creator's wrapper is doing, what Qt Creator shows is of no relevance.Also see this note in CMake documentation: https://cmake.org/cmake/help/v4.1/generator/Xcode.html#limitations
@bogong said in Detect current CMake configuration type. How?:
For example for iOS for Debug - one Info.plist file for Release another one set of the files.
Even on generators that do support that (and again, Xcode doesn't) CMake doesn't make this pattern very easy - mostly because it is a bit of an abuse of the concept of build configurations. Configurations are meant to affect the flags that are passed to the build tools when making targets, not so much the shape of the dependency graph of the targets among themselves.
Luckily that's not what you are actually trying to do (although you appear to think so) - you don't want different files between build configurations, you want different content for the same file. That can certainly be done, with a custom build target. This is completely unrelated to Qt, but there are many examples around and if you want to delve into this the CMake Discourse site will be more appropriate place. You'll probably love the syntax even less than the one for generator expressions though... (not that you have much of a choice, really).
-
Global goal not use manual settings in Qt Creator or command line. It's required by updating procedures when Qt Creator could be broken just because of update.
-
After 27 years of developing and about +15 year cross-platform in it haven't found complexity in this process when using simplicity of "if-else". For now need (or must) to redesign entire approach for projects development only because someone decided something about "modern and progress".
-
When you using setting up manual settings in Qt Creator for CMAKE_BUILD_TYPE variable you can't have automated build. You need to rewrite this every time when you switching release and debug version. Only because of Qt bugs, when Debug version not exactly Release version it's important to have ability to rebuild with different types of config rapidly without additional "manual" activities. For now only way - to use global system variable for each of config that will be attached to the Qt Creator environment. It means every update will require me to resetup it because Qt Creator clearing everything when updating or could be rising error for previous versions configs. There are a lot of bugs posted by me related to the Qt Creator.
Beside everything mentioned above - when asking on this forum means manuals, official, AI (less useful by the way, 8 from 10 question supplied by wrong reply), Google or other sources researched by me for the solution. Here asking only because of pro from Qt Company writing here.
-
-
You mix QtCreator and CMake here for unknown reasons. Also you still mix configure and build time stuff but I would guess this is by intention...
XCode sadly does not support the stuff I suggested so you have to find another way: https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754 -
You mix QtCreator and CMake here for unknown reasons. Also you still mix configure and build time stuff but I would guess this is by intention...
XCode sadly does not support the stuff I suggested so you have to find another way: https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754@Christian-Ehrlicher Mixing Qt Creator with CMake only because Qt Company in reality allow no other options when using Qt itself for iOS. Trying to use CMake under covering by Qt Creator within minimal efforts.
Thx for link on similar troubles discussed on CMake Official.
-
You mix QtCreator and CMake here for unknown reasons. Also you still mix configure and build time stuff but I would guess this is by intention...
XCode sadly does not support the stuff I suggested so you have to find another way: https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754@Christian-Ehrlicher For now solution is using environment variables like this:
In CMakeLists.txt using something like this:
if(DEFINED ENV{A_DATA_MODIFIER_BUILD_TYPE}) set(${A_PREFIX}_BUILD_TYPE $ENV{A_DATA_MODIFIER_BUILD_TYPE}) message(STATUS "Using build type config: ${${A_PREFIX}_BUILD_TYPE}") else() message(FATAL_ERROR "The system variable A_DATA_MODIFIER_BUILD_TYPE not set") endif()
The troubles in this case need to rescan project when switching Debug-Release. Is there any option to do it automatically when switching between configs? Or is there option to configure CMake variable in "Current Configuration" only for exact config in Qt Creator?
-
You mix QtCreator and CMake here for unknown reasons. Also you still mix configure and build time stuff but I would guess this is by intention...
XCode sadly does not support the stuff I suggested so you have to find another way: https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754@Christian-Ehrlicher Beside all of it why CMAKE_BUILD_TYPE return in CMakeLists.txt empty value? CMakeLists.txt.user contain defined for Android:
But has nothing similar for iOS:
Is it bug or it on purpose?
-
You mix QtCreator and CMake here for unknown reasons. Also you still mix configure and build time stuff but I would guess this is by intention...
XCode sadly does not support the stuff I suggested so you have to find another way: https://discourse.cmake.org/t/xcode-problem-with-files-which-has-vary-configuration/11754@Christian-Ehrlicher The solution for all of this troubles is in fixing CMakeLists.txt.user file generated automatically by Qt Creator. This file contain
-DCMAKE_BUILD_TYPE=Debug
only for Android configurations. For MacOS and iOS it's not defined. When manually added for each of MacOS and iOS configuration all troubles disappeared. It's happening on Qt Creator 17.0.1.
There are no need to use system or environment variables when fixed this file.
This file generated automatically by Qt Creator. By my opinion it's definitely next one bug that is blocking normal iOS/MacOS development.
Just created project from template. It's by default generated by Qt Creator. The same issue when using template. No defined CMAKE_BUILD_TYPE variable in CMake.Initial.Parameters for any iOS or MacOS platforms with any of configs.
-