3

I'm attempting to debug a command line CMake failure. The same CMake file works in Qt Creator, with the arguments in the Qt Creator window matching what I have entered on the command line.

This makes me think Qt Creator is adding some extra arguments, which makes sense since the generator drop down has several options that specify architecture and CMake version.

Is there a way to get the CMake command that Qt Creator executed to produce the desired result, specifically the arguments passed to the CMake executable?

I found one post that talks about viewing the CMakeCache files to do some forensics, but this only proves there are differences, it doesn't quickly show me what arguments to change.

Fraser
  • 74,704
  • 20
  • 238
  • 215
Evan
  • 2,441
  • 23
  • 36
  • what generator are you using? – arrowd Oct 25 '12 at 18:16
  • This particular issue is on Windows, where I'm using the NMake generator for Visual Studio 2010 C++, x64. The same project is built on Mac and Linux, where we use the Unix Generator (GCC, 64 bit). I'd like to know what is executed on all our platforms, but Windows is definitely the pressing issue. Thanks. – Evan Oct 25 '12 at 18:21
  • Do you have `qt_wrap_{cpp,ui}()` calls in your CMakeLists.txt? – arrowd Oct 25 '12 at 18:41
  • I must admit I don't know what that command is. What does it do? This is a library level project, I'm using Qt as an IDE, but not using the Qt UI framework. Although we do have application level software in Qt, as well, so if that's a helpful command, then I'm all ears. I googled it, with no immediate avail. – Evan Oct 25 '12 at 19:13
  • So, you are using QtCreator with CMake build system, right? Maybe you should post error messages or something, since it's not clear what's the problem. – arrowd Oct 25 '12 at 19:33

1 Answers1

4

Try adding the following block to the end of your CMakeLists.txt and running CMake from Qt Creator again. The CMake output should list all variables that have been passed via the -D command line argument.

get_cmake_property(CacheVars CACHE_VARIABLES)
foreach(CacheVar ${CacheVars})
  get_property(CacheVarHelpString CACHE ${CacheVar} PROPERTY HELPSTRING)
  if(CacheVarHelpString STREQUAL "No help, variable specified on the command line.")
    get_property(CacheVarType CACHE ${CacheVar} PROPERTY TYPE)
    if(CacheVarType STREQUAL "UNINITIALIZED")
      set(CacheVarType)
    else()
      set(CacheVarType :${CacheVarType})
    endif()
    set(CMakeArgs "${CMakeArgs} -D${CacheVar}${CacheVarType}=\"${${CacheVar}}\"")
  endif()
endforeach()
message("CMakeArgs: ${CMakeArgs}")

For more info, see this answer.

This won't show what generator was selected (if any) via the -G arg. To find that, you need to look for CMAKE_GENERATOR:INTERNAL=... in your CMakeCache.txt

If this doesn't help you identify the overall problem, you should probably heed @arrowdodger's advice and post more details about the errors you're getting and your two build environments. For example, an error could be caused simply by running CMake from a subdirectory of the source tree.

Community
  • 1
  • 1
Fraser
  • 74,704
  • 20
  • 238
  • 215
  • Thanks for this answer. I've been off on something else, but will give this a shot very soon and accept pending it working. On the surface, it looks exactly like what I'm looking for. – Evan Nov 05 '12 at 23:33