Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

qmake to cmake, are there any tools to help automate this?



  • Hey folks, so I'm a total noob to cmake, and I'm trying to convert my current qmake setup over (since I figure that it has to happen sooner or later). However, I my qmake has a bunch of weird stuff in it that I'm not sure how to convert over:

    # For use with Visual Studio 
    
    message("Beginning qmake build of project_name.pro")
    
    TEMPLATE = app
    TARGET = project_name
    QT += core \
          opengl \ 
    	  gui \
    	  widgets \
    	  concurrent \ # Mutexes/multithreading
    	  openglextensions \
    	  multimedia \
    	  gamepad \ # Controller support
    	  network # TCP/IP
    
    # Set compiler flags /////////////////////////////////////////////////////////////
    QMAKE_CXXFLAGS += /MP # Multiprocess compile, much faster
    
    # MSVC versions after 15.3 are fickle with the flags required to use more modern c++ variants
    QMAKE_CXXFLAGS *= /std:c++17 # Add if not there, this may be the ticket
    # QMAKE_CXXFLAGS += -std=c++17 # For GCC/Clang
    # QMAKE_CXXFLAGS += -std=c++1z
    
    # Set general configuration options /////////////////////////////////////////////////
    CONFIG += c++latest # Add support for c++17.
    # CONFIG += c++1z # another attempt at C++17 support
    CONFIG += qt thread # console 
    CONFIG += debug_and_release # Creates additional debug and release folders, but need it for debug
    
    CONFIG(debug, debug|release){
        DESTDIR = ../app/debug
    	DEFINES += DEBUG_MODE
    } 
    else {
        DESTDIR = ../app/release
    }
    
    # Replace O2 flag with O3 flag
    #CONFIG(release, debug|release) {
    #    QMAKE_CXXFLAGS_RELEASE -= -O1
    #	QMAKE_CXXFLAGS_RELEASE -= -O2
    #	QMAKE_CXXFLAGS_RELEASE *= -O3
    #}
    
    # Do not display debug output in release mode
    CONFIG(debug, debug|release) : CONFIG += debug_info
    CONFIG(release, debug|release) : DEFINES += QT_NO_DEBUG_OUTPUT
    
    CONFIG += no_lflags_merge # Ensures that the list of libraries stored in the LIBS variable is not reduced to a list of unique values before it is used.
    # CONFIG += CONSOLE # makes this a console application
    CONFIG -= flat # flattens file hierarchy, subtract if this is not desired
    
    # Defines //////////////////////////////////////////////////////////////////////////
    DEFINES += _UNICODE _ENABLE_EXTENDED_ALIGNED_STORAGE WIN64 QT_DLL QT_OPENGL_LIB QT_OPENGLEXTENSIONS_LIB QT_WIDGETS_LIB
    DEFINES += DEVELOP_MODE
    DEFINES += LINALG_USE_EIGEN
    INCLUDEPATH += ./qt_generated \
        . \
        ./qt_generated/$(ConfigurationName) 
    	
    LIBS += -lopengl32 \
        -lglu32 
    DEPENDPATH += .
    
    
    # Add Libraries ////////////////////////////////////////////////////////////////////
    # Don't forget to add to unit tests project as well, or else Intellisense errors will carry over
    # Include PythonQt and required libraries
    # Maybe not needed here, since python.prf is included when PythonQt is built?
    # Note that both windows and linux style library links work in windows
    # LIBS += -L$$(PYTHON_LIB)/ -lpython$$(PYTHON_VERSION) # L"PATH" adds PATH to library search directory list, and -lName loads library Name during linking
    
    # Enable import <PythonQt.h>
    # INCLUDEPATH += $$PWD/src/third_party/pythonqt
    
    #include ( ../third_party/PythonQt/build/python.prf )   #Was pulled from  PythonQt build
    include ( ../third_party/PythonQt/build/common.prf )  
    include ( ../third_party/PythonQt/build/PythonQt.prf )  
    #include ( ../third_party/PythonQt/build/PythonQt_QtAll.prf )  
    
    
    # Compile against release version of python
    CONFIG(debug, debug|release) : DEFINES += PYTHONQT_USE_RELEASE_PYTHON_FALLBACK
    
    # Eigen
    INCLUDEPATH += $$PWD/src/third_party/eigen \
    			   $$PWD/src/third_party/eigen/Eigen
    
    # ASSIMP
    # To be able to write <module.h>
    INCLUDEPATH += ../third_party/assimp/assimp-5.0.0/include
    INCLUDEPATH += ../third_party/assimp/assimp-5.0.0/build/include
    CONFIG(debug, debug|release) : LIBS += -L$$PWD/lib/assimp -lassimp_d
    CONFIG(release, debug|release) : LIBS += -L$$PWD/lib/assimp -lassimp
    
    # PhysX
    DEFINES += PX_PHYSX_STATIC_LIB
    INCLUDEPATH += ../../PhysX/physx/include \
    			   ../../PhysX/pxshared/include
    CONFIG(debug, debug|release) { 
    	LIBS += -L$$PWD/lib/physx/debug -lPhysX_static_32
    	LIBS += -L$$PWD/lib/physx/debug -lPhysXCharacterKinematic_static_32
    	LIBS += -L$$PWD/lib/physx/debug -lPhysXCommon_static_32
    	LIBS += -L$$PWD/lib/physx/debug -lPhysXCooking_static_32
    	LIBS += -L$$PWD/lib/physx/debug -lPhysXExtensions_static_32
    	LIBS += -L$$PWD/lib/physx/debug -lPhysXFoundation_static_32
    	LIBS += -L$$PWD/lib/physx/debug -lPhysXPvdSDK_static_32
    	LIBS += -L$$PWD/lib/physx/debug -lPhysXVehicle_static_32
    }
    CONFIG(release, debug|release) { 
    	# Always needed
    	LIBS += -L$$PWD/lib/physx/release -lPhysXCommon_static_32
    	
    	# Always needed
    	LIBS += -L$$PWD/lib/physx/release -lPhysX_static_32
    	
    	# Always needed
    	LIBS += -L$$PWD/lib/physx/release -lPhysXFoundation_static_32
    	
    	# To cook geometry data on the fly
    	LIBS += -L$$PWD/lib/physx/release -lPhysXCooking_static_32
    	
    	# Other
    	LIBS += -L$$PWD/lib/physx/release -lPhysXCharacterKinematic_static_32
    	LIBS += -L$$PWD/lib/physx/release -lPhysXExtensions_static_32
    	LIBS += -L$$PWD/lib/physx/release -lPhysXPvdSDK_static_32
    	LIBS += -L$$PWD/lib/physx/release -lPhysXVehicle_static_32
    }
    
    # FreeType
    INCLUDEPATH +=  ../third_party/freetype-2.10.1/include
    CONFIG(debug, debug|release) : LIBS += -L$$PWD/lib/freetype/debug -lfreetype
    CONFIG(release, debug|release) : LIBS += -L$$PWD/lib/freetype/release -lfreetype
    
    # SoLoud
    INCLUDEPATH += ../third_party/soloud/include
    CONFIG(debug, debug|release) { 
    	LIBS += -L$$PWD/lib/soloud/debug -lsoloud_x86_d
    	LIBS += -L$$PWD/lib/soloud/debug -lsoloud_static_x86_d
    }
    CONFIG(release, debug|release) { 
    	LIBS += -L$$PWD/lib/soloud/release -lsoloud_x86
    	LIBS += -L$$PWD/lib/soloud/release -lsoloud_static_x86
    }
    
    
    # Include Visual Leak Detector //////////////////////////////////////////////////////////////////
    INCLUDEPATH += "../third_party/Visual Leak Detector/include/"
    LIBS        += -L"../third_party/Visual Leak Detector/lib/Win32"	
    	
    			   
    # Set directories //////////////////////////////////////////////////////////////////
    MOC_DIR += ./qt_generated/moc
    OBJECTS_DIR += ./qt_generated/obj
    UI_DIR += ./qt_generated/ui
    RCC_DIR += ./qt_generated
    
    message("Loaded .pro files, now loading .pri")
    
    # Load in library files for project
    include(project_name.pri)
    
    message("Loaded .pri files")
    

    For example, do "TEMPLATE" and "TARGET" mean anything for cmake? Can I print out messages similarly? Can I add to my DEFINES, LIB, INCLUDEPATH, and all those other variables the same way? Is there something similar to CONFIG? What about my MOC_DIR, OBJECTS_DIR, etc? And how would I override flags like with QMAKE_CXXFLAGS ? I don't even know where to start, it's all a bit overwhelming.


  • Lifetime Qt Champion

    Hi,

    A quick search showed that Kitware has such a script for the base things.

    There's likely something as well in the dev branch of Qt since Qt 6 uses cmake as build system.



  • @SGaist Thanks, but I feel like it would be more work to learn and set up Ruby than it would be to attempt this by hand. I did find this script, but I'm not sure if there's any documentation on it, or if it even works properly. I'll give it a go, it'd just be nice to be able to sanity check things.


  • Lifetime Qt Champion

    AFAIK, it's the script that was used to bootstrap the port from qmake to cmake so it should do a pretty good job.


Log in to reply