我在编写 cmake 文件时遇到问题。我有一个同时使用 Qt 和 WinSock2 的项目。但是当我将 set(CMAKE_AUTOMOC ON) 添加到 CMake 代码时,它给了我这些错误:
错误 4 错误 C2011: 'sockaddr' : 'struct' 类型重新定义 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h 212 错误 5 错误 C2059: 语法错误: '常量' C :\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h 390 错误 6 错误 C3805:'常量':意外令牌,应为 '}' 或 ',' C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h 390 ...
我的cmake文件如下:
PROJECT(RFIDVis-core)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
#INCLUDE(../cmake/commonconf.cmake)
set(CMAKE_AUTOMOC ON)
#set(CMAKE_INCLUDE_CURRENT_DIR ON)
MESSAGE(STATUS "Configuring RFIDVis Source")
# glob sources from core directories
FILE(GLOB RFIDVisSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
BusinessLogic/*.cpp
DataLayer/*.cpp
IrrlichtComponents/*.cpp
GeneratedFiles/Debug/*.cpp
Libraries/*.cpp
Presentation/*.cpp
main.cpp
)
FILE(GLOB RFIDVisHeaders RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
BusinessLogic/*.h
DataLayer/*.h
Libraries/*.h
Libraries/*.hpp
IrrlichtComponents/*.h
Presentation/*.h
)
FILE(GLOB CampvisApplicationForms
Presentation/*.ui
)
SET(RFIDVisApplicationToBeMocced
GeneratedFiles/ui_demomainwindow.h
)
#
# Qt related stuff:
#
QT5_WRAP_CPP(RFIDVisApplicationMoc ${RFIDVisApplicationToBeMocced})
LIST(APPEND RFIDVisApplicationSources ${RFIDVisApplicationMoc})
QT5_WRAP_UI(RFIDVisApplicationFormsHeaders ${RFIDVisApplicationForms})
LIST(APPEND RFIDVisApplicationSources ${RFIDVisApplicationFormsHeaders})
LINK_DIRECTORIES(${RFIDVisGlobalLinkDirectories} ${IRRLICHT_LIBRARY}
${RFIDVisHome}/ext/VISA/lib/msc/visa32.lib
${RFIDVisHome}/ext/VISA/lib/msc/rsspecan.lib
)
qt5_generate_moc(main.cpp main.moc)
ADD_EXECUTABLE(RFIDVis-application
${RFIDVisSources} ${RFIDVisHeaders} ${RFIDVisMocs}
)
ADD_DEFINITIONS(${RFIDVisGlobalDefinitions})
INCLUDE_DIRECTORIES(${RFIDVisGlobalIncludeDirs})
cmake_policy(SET CMP0020 NEW)
TARGET_LINK_LIBRARIES(RFIDVis-application Qt5::Core Qt5::Widgets ws2_32.lib
${RFIDVisHome}/ext/VISA/lib/msc/visa32.lib
${RFIDVisHome}/ext/VISA/lib/msc/rsspecan.lib
${IRRLICHT_LIBRARY})
qt5_use_modules(RFIDVis-application Core GUI Widgets)
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(RFIDVisSources ${RFIDVisHome} "")
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(RFIDVisHeaders ${RFIDVisHome} "")