Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake + Qt = carved in stone Qt definitions (aka. -DQT_...)?

First, let's look at the excerpt from my CMakeLists.txt:

find_package(Qt4 4.8.0 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})

Therefore, by default we get the following definitions in Debug mode:

-DQT_DLL -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_DLL -DQT_DEBUG

So the first question is: why there are two -DQT_DLL definitions?

Now, if I append, for instance, remove_definitions(-DQT_DEBUG) - nothing changes. In other words, either remove_definitions command is bugged or these definitions are merely carved in stone.

Then I thought like "OK, maybe remove_definitions command is really bugged, let's do it another way." And I did list(REMOVE_ITEM QT_DEFINITIONS -DQT_DEBUG). However, it didn't work either.

Therefore, the second question is: are these definitions really built-in and persistent and cannot be changed under any circumstances?

NOTE: Despite problems with editing these built-in definitions, it is still possible add custom definitions, for instance:

add_definitions(-DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT)
like image 638
Alexander Shukaev Avatar asked Jan 29 '12 13:01

Alexander Shukaev


1 Answers

Ok, so here we have several things. It boils down to the CMake macros and their logic.

Double -DQT_DLL comes from add_definitions(${QT_DEFINITIONS)}). It is enough to specify include(${QT_USE_FILE}).

QT_USE_FILE defines QT_DEBUG (or QT_NO_DEBUG) based on the current CMAKE_BUILD_TYPE. If for whatever reason you don't want to have QT_DEBUG in the DEBUG mode (and to work with QT_USE_FILE) there might be a way to do that. CMake puts these specific definitions in the directory properties:

SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG QT_DEBUG)
SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG)
SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO QT_NO_DEBUG)
SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL QT_NO_DEBUG)
IF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
  SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_DEBUG)
ENDIF()

Now, you could try tweaking these settings...

like image 86
Anonymous Avatar answered Oct 16 '22 23:10

Anonymous