Cmake c ++ 11 flag not included when creating makefile

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 ISO C ++ 2011 support . I run this command cmake . -G "Unix Makefiles"

to generate the files that I need and to create a makefile.

The problem is that when I run the command make

, it fails with the following error:

error: #error This file requires ISO C ++ 2011 compiler and library support. This support is currently experimental and should be enabled with the -std = C ++ 11 or -std = gnu ++ 11 compiler options.

This is because I have enabled the flag. What's even weirder is that on restarting cmake . -G "Unix Makefiles"

this problem is resolved and I can create my files without errors!

What could be causing this problem?

+3


source to share


2 answers


It might be overwritten somewhere else, as this CMake file is not official from PrismTech. Change this command to this:

set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

      



and place it at the end of your cmake file.

+3


source


There are differences in setting compiler flags before or after the call project()

.



  • When the flags are set before project()

    , you usually call the default override :

    set(CMAKE_CXX_FLAGS_INIT "<new-value>" CACHE STRING
       "Flags used by the compiler during all build types.")
    # ... some other assignments may be here ...
    project(<project-name>)
    
          

    Note _INIT

    suffix for variable: Actual flags are initialized at the time of invocation project()

    , and CMAKE_CXX_FLAGS_INIT provides a default value for them.

  • When flags are set after project()

    , you usually call append by default, or at user request:

    project(<project-name>)
    # ...
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} <additional-value>")
    
          

+2


source







All Articles