0

I have a problem while I am writing the cmake file. I have a project which both uses the Qt and WinSock2. But when I add set(CMAKE_AUTOMOC ON) to the CMake code, it gives me these errors:

Error 4 error C2011: 'sockaddr' : 'struct' type redefinition C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h 212 Error 5 error C2059: syntax error : 'constant' C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h 390 Error 6 error C3805: 'constant': unexpected token, expected either '}' or a ',' C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h 390 ...

And my cmake file is as follows:

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} "")
Cœur
  • 37,241
  • 25
  • 195
  • 267
mmostajab
  • 1,937
  • 1
  • 16
  • 37
  • Answer: The problem is that the windows.h is going to be added to the project after adding the AUTOMOC. So, the solution is to add **add_definitions(-DWIN32_LEAN_AND_MEAN)** to the cmake file. Then, the windows.h will not include the winsock and you can include it by yourself in your project – mmostajab Aug 28 '14 at 13:02

1 Answers1

0

The problem is that the windows.h is going to be added to the project after adding the AUTOMOC. So, the solution is to add add_definitions(-DWIN32_LEAN_AND_MEAN) to the cmake file. Then, the windows.h will not include the winsock and you can include it by yourself in your project

mmostajab
  • 1,937
  • 1
  • 16
  • 37