jeudi 30 mars 2017

Cmake did not use C++11 flag using CXX_STANDARD?

I'm fairly new to cmake and I'm trying to use the mongodb driver for C++ by using this tutorial: http://ift.tt/2oCnr38. The tutorial says you need C++11, so I tried the recommended way which is using CXX_STANDARD property. But it didn't work. I finally gave up and used add_definitions() and it worked!

The cmake file shows both approaches I tried. ie, add_definitions and the set property approach in the comment (which I tried first but failed to work).

It works with add_definitions() now, but everywhere I turn people recommend using CXX_STANDARD or let cmake use C++11 automatically by requesting a C++11 feature.

So, will this be a problem later on for some reason? And why didn't it work the first time around?

My cmake file:

cmake_minimum_required(VERSION 3.2)

project(testproj CXX)

file(GLOB SRC src/*.cpp)

add_library(testproj SHARED ${SRC})

add_definitions(--std=c++11)
#set(TARGET testproj PROPERTY CXX_STANDARD 11)
#set(TARGET testproj PROPERTY CXX_STANDARD_REQUIRED ON)

# include directories
include_directories(/usr/local/include/mongocxx/v_noabi)
include_directories(/usr/local/include/libmongoc-1.0)
include_directories(/usr/local/include/bsoncxx/v_noabi)
include_directories(/usr/local/include/libbson-1.0)

# library path
link_directories(/usr/local/lib)
target_link_libraries(testproj mongocxx bsoncxx)

Aucun commentaire:

Enregistrer un commentaire