cmake添加NO_MOC来应对直接粗暴include moc生成的源代码

qt6
zcy 2021-04-06 13:18:24 +08:00
parent da25df7311
commit 5407bf8b1e
2 changed files with 18 additions and 18 deletions

View File

@ -16,37 +16,35 @@ list(APPEND EXTSERIAL_SOURCES
${CMAKE_CURRENT_LIST_DIR}/qextserialenumerator.cpp
)
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
list(APPEND EXTSERIAL_SOURCES ${CMAKE_CURRENT_LIST_DIR}/qextserialport_unix.cpp)
list(APPEND EXTSERIAL_SOURCES ${CMAKE_CURRENT_LIST_DIR}/qextserialenumerator_linux.cpp)
message("CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}")
list(APPEND NO_MOC_SOURCES ${CMAKE_CURRENT_LIST_DIR}/qextserialport_unix.cpp)
list(APPEND NO_MOC_SOURCES ${CMAKE_CURRENT_LIST_DIR}/qextserialenumerator_linux.cpp)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows")
list(APPEND EXTSERIAL_SOURCES ${CMAKE_CURRENT_LIST_DIR}/qextserialport_win.cpp)
list(APPEND EXTSERIAL_SOURCES ${CMAKE_CURRENT_LIST_DIR}/qextserialenumerator_win.cpp)
message("CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}")
list(APPEND NO_MOC_SOURCES ${CMAKE_CURRENT_LIST_DIR}/qextserialport_win.cpp)
list(APPEND NO_MOC_SOURCES ${CMAKE_CURRENT_LIST_DIR}/qextserialenumerator_win.cpp)
link_libraries(setupapi advapi32 user32)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
message("CMAKE_SYSTEM_NAME is ${FreeBSD}")
ENDIF()
QT5_WRAP_CPP(EXTSERIAL_MOC_SOURCE ${EXTSERIAL_SOURCES} ) # moc
QT5_WRAP_CPP(EXTSERIAL_MOC_HEADER ${EXTSERIAL_HEADERS} ) # moc
QT5_WRAP_CPP(EXTSERIAL_MOC ${EXTSERIAL_SOURCES} ) # moc
QT5_WRAP_CPP(EXTSERIAL_MOCHEADER ${EXTSERIAL_HEADERS} ) # moc
list(APPEND MOC ${EXTSERIAL_MOC_SOURCE})
list(APPEND SOURCES ${EXTSERIAL_SOURCES})
FOREACH(list ${EXTSERIAL_MOC_SOURCE})
FOREACH(list ${EXTSERIAL_MOCHEADER})
get_filename_component(BIN_PATH ${list} "DIRECTORY" )
message("EXTSERIAL_MOC_SOURCE file" ${list})
ENDFOREACH(list)
FOREACH(list ${EXTSERIAL_MOC_HEADER})
message("EXTSERIAL_MOC_HEADER file " ${list})
ENDFOREACH(list)
message("EXTSERIAL_MOC_SOURCE file " ${BIN_PATH})
message("EXTSERIAL_MOCHEADER file" ${list} ${BIN_PATH})
include_directories(${BIN_PATH})
ENDFOREACH(list)
# list(APPEND HEADERS ${EXTSERIAL_HEADERS})
# list(APPEND SOURCES ${EXTSERIAL_SOURCES})
list(APPEND NO_MOC_SOURCES ${EXTSERIAL_SOURCES})
include_directories(${CMAKE_CURRENT_LIST_DIR})

View File

@ -31,6 +31,7 @@
#include "qextserialport.h"
#include "qextserialport_p.h"
#include <QtCore/QThread>
#include <QtCore/QReadWriteLock>
#include <QtCore/QMutexLocker>
@ -403,3 +404,4 @@ void QextSerialPortPrivate::updatePortSettings()
SetCommTimeouts(handle, &commTimeouts);
settingsDirtyFlags = 0;
}