I have the following CMakeLists file:
################# # Com Project # ################# CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(CMAKE_MODULE_PATH /home/loay/Desktop/V5) SET(CMAKE_CXX_FLAGS "-std=c++11") PROJECT (Sync) FIND_PACKAGE (OpenSplice REQUIRED) ##################### # Modele de donnees # ##################### SET (idls Communication.idl ) # Extraction des fichiers a partir du .idl execute_process(COMMAND idlpp -S -l cpp ./Communication.idl) FOREACH(idl ${idls}) OpenSplice_IDLGEN (${idl}) STRING (REGEX REPLACE "\(.*\).idl" "\\1.cpp" VARS_1 ${idl}) STRING (REGEX REPLACE "\(.*\).idl" "\\1.h" VARS_2 ${idl}) STRING (REGEX REPLACE "\(.*\).idl" "\\1Dcps.cpp" VARS_3 ${idl}) STRING (REGEX REPLACE "\(.*\).idl" "\\1Dcps.h" VARS_4 ${idl}) STRING (REGEX REPLACE "\(.*\).idl" "\\1Dcps_impl.cpp" VARS_5 ${idl}) STRING (REGEX REPLACE "\(.*\).idl" "\\1Dcps_impl.h" VARS_6 ${idl}) STRING (REGEX REPLACE "\(.*\).idl" "\\1SplDcps.cpp" VARS_7 ${idl}) STRING (REGEX REPLACE "\(.*\).idl" "\\1SplDcps.h" VARS_8 ${idl}) STRING (REGEX REPLACE "\(.*\).idl" "ccpp_\\1.h" VARS_9 ${idl}) SET(OpenSplice_SYNC ${OpenSplice_SYNC} ${VARS_1} ${VARS_2} ${VARS_3} ${VARS_4} ${VARS_5} ${VARS_6} ${VARS_7} ${VARS_8} ${VARS_9}) ENDFOREACH(idl) ########################### # Fichiers de code source # ########################### SET (APP_SOURCES arduino.cpp Controller.cpp CheckStatus.cpp Controller.cpp ListenerReader.cpp main.cpp Publisher.cpp Subscriber.cpp rs232.c ) # Inclure dossier des sources des librairies a linker INCLUDE_DIRECTORIES( ${OpenSplice_INCLUDE_DIRS} ) # Inclure dossier des binaires des librairies a linker link_directories ( ${LIBRARY_OUTPUT_PATH} ) ############################# # Construction des binaires # ############################# SET (APP_EXE start) SET (SYNC Sync) ADD_EXECUTABLE (${APP_EXE} ${APP_SOURCES}) ADD_LIBRARY (${SYNC} SHARED ${OpenSplice_SYNC}) ADD_DEFINITIONS ( ${OpenSplice_DEFINITIONS} ${DEFINITIONS} ) TARGET_LINK_LIBRARIES (${SYNC} ${OpenSplice_LIBRARIES} ) TARGET_LINK_LIBRARIES (${APP_EXE} ${OpenSplice_LIBRARIES} ${SYNC} ) As you can see I added this line SET(CMAKE_CXX_FLAGS "-std=c++11") to enable support for ISO c++ 2011. I run this command cmake . -G "Unix Makefiles" to generate the files I need and to generate the makefile.
The problem is that when I run make command it fails with the following error:
error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
This is weired because I did include the flag. What makes things even weirder is that when I re-run cmake . -G "Unix Makefiles" this problem is solved and I am able to build my files with no error!
What could be the cause of this problem ?
CMAKE_CXX_STANDARD(plus relatedCMAKE_CXX_STANDARD_REQUIREDandCMAKE_CXX_EXTENSIONS) which control this at native CMake level. With these, you wouldn't have to go through flags manually.