I am setting the following flags in my CMakeLists.txt
set(CMAKE_CXX_FLAGS "-std=c++14 -g -O0")
I am then using find_package
to locate Qt5Test
find_package(Qt5Test REQUIRED)
I am then creating a Model Test library
add_library (modeltest STATIC ${SRCS})
target_link_libraries(modeltest Qt5::Test)
For some reason I'm getting -fPIC -std=gnu++11
added to my compiler flags
CMakeFiles/modeltest.dir/flags.make:CXX_FLAGS = -std=c++14 -g -O0 -fPIC -std=gnu++11
This is clobbering my -std=c++14
flag, causing all the c++14 features in my program to end up as compiler errors:
error: ‘foo’ function uses ‘auto’ type specifier without trailing return type
constexpr auto foo()
^
note: deduced return type only available with -std=c++14 or -std=gnu++14
- Is there a way to fix this?
- I'm using the latest version of Qt 5.7 downloaded from their site today
Do not set
CMAKE_CXX_FLAGS
explicitly.Use this instead:
This will definitely set the standard to be used for each target.
As suggested in the comments, the following should be considered too:
See this link for further details.
Thanks to @CraigScott for that pointed it out.
As mentioned in the comments by @wasthishelpful, properties
CXX_STANDARD
,CXX_STANDARD_REQUIRED
andCXX_EXTENSIONS
can also be used for a per-target configuration.See the links above for further details.