将AUTOMOC添加到cmake文件时,WinSock出现问题

时间:2014-08-27 16:29:34

标签: c++ qt cmake moc

我在编写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   文件(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} "")

1 个答案:

答案 0 :(得分:0)

问题是在添加AUTOMOC后,windows.h将被添加到项目中。因此,解决方案是将add_definitions(-DWIN32_LEAN_AND_MEAN)添加到cmake文件中。然后,windows.h将不包含winsock,您可以将它自己包含在项目中