mingw64 cmake build command

lsgxeva發表於2024-03-11

mingw64 cmake build command

cmake_minimum_required(VERSION 3.5)

project(00_qt_hello VERSION 0.1 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check https://doc.qt.io/qt/deployment-android.html for more information.
# They need to be set before the find_package( ...) calls below.

#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets LinguistTools REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools REQUIRED)

set(TS_FILES 00_qt_hello_zh_CN.ts)

set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
        ${TS_FILES}
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(00_qt_hello
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )

    qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
else()
    if(ANDROID)
        add_library(00_qt_hello SHARED
            ${PROJECT_SOURCES}
        )
    else()
        add_executable(00_qt_hello
            ${PROJECT_SOURCES}
        )
    endif()

    qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()

target_link_libraries(00_qt_hello PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

set_target_properties(00_qt_hello PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(00_qt_hello)
endif()

# cmake gen cache
"C:\cmake\bin\cmake.exe" -S D:/mydevelop/mydemo/00_qt_hello -B D:/mydevelop/mydemo/build-00_qt_hello-mingw64-Release "-GMinGW Makefiles" "-DCMAKE_BUILD_TYPE:STRING=Release" "-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=D:/program/qtcreator-mingw64/share/qtcreator/package-manager/auto-setup.cmake" "-DQT_QMAKE_EXECUTABLE:STRING=D:/program/qt5.15.12-mingw64/bin/qmake.exe" "-DCMAKE_PREFIX_PATH:STRING=D:/program/qt5.15.12-mingw64" "-DCMAKE_C_COMPILER:STRING=C:/mingw64/bin/gcc.exe" "-DCMAKE_CXX_COMPILER:STRING=C:/mingw64/bin/g++.exe" 

# cmake cache update
"C:\cmake\bin\cmake.exe" -S D:/mydevelop/mydemo/00_qt_hello -B D:/mydevelop/mydemo/build-00_qt_hello-mingw64-Release

# cmake target clean
"C:\cmake\bin\cmake.exe" --build D:/mydevelop/mydemo/build-00_qt_hello-mingw64-Release --target clean

# cmake target all
"C:\cmake\bin\cmake.exe" --build D:/mydevelop/mydemo/build-00_qt_hello-mingw64-Release --target all

# running target
"D:\mydevelop\mydemo\build-00_qt_hello-mingw64-Release\00_qt_hello.exe"

======= End

相關文章