mercredi 2 septembre 2015

CMake: C++11 not set with CXX_STANDARD

I want to compile a library using C++11. The library is a subproject. In its CMakeLists.txt I set the C++11 features with CXX_STANDARD and CXX_STANDARD_REQUIRED as seen here.

The cmake command it's executed without errors, but when I start the compilation I obtain errors related to C++11 features missing, like

In file included from /folder/OptionWidget.cpp:1:0:
/folder/OptionWidget.h:14:28: warning: defaulted and deleted functions only available with -std=c++0x or -std=gnu++0x [enabled by default]
/folder/OptionWidget.h:14:28: error: ‘virtual WTradeGui::OptionWidget::~OptionWidget()’ declared virtual cannot be defaulted in the class body
make[2]: *** [.../OptionWidget.cpp.o] Error 1

The error lies where I declare a default virtual destructor in header virtual ~OptionWidget() = default;

If I execute the command make VERBOSE=1 I can see that the C++11 flag is not set in compilation command:

 /usr/bin/c++   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I/folder/wtradegui -I/folder/wtradegui -I/folder/wtrade/src -isystem /qt/include -isystem /qt/QtWidgets -isystem /qt/QtGui -isystem /qt/QtCore -isystem -fPIC -o CMakeFiles/http://ift.tt/1JB5dEM -c /folder/OptionWidget.cpp

I use Ubuntu 15.04 with cmake version 3.3.1 and gcc version 4.6.3.

The same project is built without problems under windows, using MinGW (sorry I don't remember the version, it's the one shipped with Qt 5.5.0 release).

What I must do in order to build the project in Linux?

This is the main CMakeList.txt

# In order to work following variables must be set
#
# QT_DIR: Path to Qt installation.

cmake_minimum_required (VERSION 3.1.0)

# Variables that should be set before execution
if (WIN32)
    set (QT_DIR "" CACHE PATH "Qt library path")
else (WIN32)
    set (QT_DIR "/usr/include" CACHE PATH "Qt library path")
endif (WIN32)

message ("Generating WPlot project")
message ("Setting QT_DIR To ${QT_DIR}")

add_subdirectory (wplot)
add_subdirectory (demo)

And this is the CMakeLists.txt inside wplot folder

# wPlot project

cmake_minimum_required (VERSION 3.1.0)

project (wplot)

set (major_version 0)
set (minor_version 0)
set (bugfix_version 1)
set (project_version ${major_version}.${minor_version}.${bugfix_version})
set (OUTPUT_DIR "build")
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/export/lib)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/export/lib)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/export/bin)
set (INCLUDE_EXPORT_DIRECTORY ${CMAKE_BINARY_DIR}/export/include/wplot)
set (CMAKE_DOC_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/export/doc)
set (CMAKE_PREFIX_PATH ${QT_DIR}/lib/cmake)
set (CMAKE_AUTOMOC ON)
set (CMAKE_INCLUDE_CURRENT_DIR ON)

message ("=== Generating WPlot ===")
message ("Setting QT_DIR To ${QT_DIR}")
message ("CMAKE_PREFIX_PATH set to ${CMAKE_PREFIX_PATH}")
find_package (Qt5Widgets REQUIRED)
include_directories (${CMAKE_SOURCE_DIR} ${Qt5Widgets_INCLUDE_DIRS})
file (GLOB_RECURSE WPLOT_SOURCES "*.cpp")
file (GLOB WPLOT_PUBLIC_HEADERS "*.h")
file (COPY ${WPLOT_PUBLIC_HEADERS} DESTINATION ${INCLUDE_EXPORT_DIRECTORY})

# Compile project
add_definitions(-DWPLOT_LIBRARY)
add_library (wplot SHARED ${WPLOT_SOURCES})
target_link_libraries(wplot ${Qt5Widgets_LIBRARIES})
set_target_properties(
  wplot
  PROPERTIES
    VERSION ${project_version}
    SOVERSION ${project_version}
)
set_property(TARGET wplot PROPERTY CXX_STANDARD 11)
set_property(TARGET wplot PROPERTY CXX_STANDARD_REQUIRED ON)

Aucun commentaire:

Enregistrer un commentaire