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
Do not set CMAKE_CXX_FLAGS
explicitly.
Use this instead:
set(CMAKE_CXX_STANDARD 14)
This will definitely set the standard to be used for each target.
As suggested in the comments, the following should be considered too:
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
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
and CXX_EXTENSIONS
can also be used for a per-target configuration.
See the links above for further details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With