CMake + Qt = carved in stone definitions of Qt (aka -DQT _...)?

First, let's look at an 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: why are there two definitions -DQT_DLL ?

Now, if I add, for example, remove_definitions(-DQT_DEBUG) , nothing changes. In other words, the remove_definitions command is remove_definitions , or these definitions are just carved out of stone.

Then I thought, "OK, maybe the remove_definitions command is really listening, let it do it differently." And I made a list(REMOVE_ITEM QT_DEFINITIONS -DQT_DEBUG) . However, this did not work either.

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

NOTE. . Despite problems with editing these built-in definitions, you can add custom definitions, for example:

 add_definitions(-DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT) 
+6
source share
1 answer

Okay, so we have a few things. It comes down to CMake macros and their logic.

The 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 some reason you don't want to have QT_DEBUG in DEBUG mode (and work with QT_USE_FILE ), maybe this will be the way to do it. CMake places 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 can try to configure these settings ...

+2
source

Source: https://habr.com/ru/post/907155/


All Articles