CXX_EXTENSIONS as usage requirement
I have an (IMPORTED
) INTERFACE
library target "HeaderOnlyLib
" which requires the C++11 standard. Therefore, I need to propagate this usage-requirement to other targets that use this header-only library.
Because I try to compile with GCC, I want CMake (v3.9.1) to add the commandline-option -std=c++11
.
However, using the following approach CMake adds -std=gnu++11
instead:
add_library( HeaderOnlyLib INTERFACE IMPORTED GLOBAL )
set_target_properties( HeaderOnlyLib PROPERTIES
INTERFACE_COMPILE_FEATURES cxx_std_11
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include
)
Output:
$ cd /tmp/build
$ cmake ../source -G"Unix Makefiles"
...
$ VERBOSE=1 make
...
[ 50%] Building CXX object CMakeFiles/test.dir/main.cpp.o
/usr/bin/g++ -isystem /tmp/source/include -std=gnu++11 -o CMakeFiles/test.dir/main.cpp.o -c /tmp/build/main.cpp
...
When I instead try to additionally set the target-property CXX_EXTENSIONS
to OFF
cmake-ing fails:
add_library( HeaderOnlyLib INTERFACE IMPORTED GLOBAL )
set_target_properties( HeaderOnlyLib PROPERTIES
INTERFACE_COMPILE_FEATURES cxx_std_11
CXX_EXTENSIONS OFF
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include
)
Output:
$ cd /tmp/build
$ cmake ../source -G"Unix Makefiles"
...
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /tmp/source/CMakeLists.txt:50 (set_target_properties):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "CXX_EXTENSIONS" is not allowed.
-- Configuring incomplete, errors occurred!
See also "/tmp/build/CMakeFiles/CMakeOutput.log".
So, I would love to get CXX_EXTENSIONS
white-listed for INTERFACE_LIBRARIES.
I also tried the following which successfully cmakes but seems to have no effect:
add_library( HeaderOnlyLib INTERFACE IMPORTED GLOBAL )
set_target_properties( HeaderOnlyLib PROPERTIES
INTERFACE_COMPILE_FEATURES cxx_std_11
INTERFACE_COMPILE_FEATURES "CXX_EXTENSIONS OFF"
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include
)
Only setting the global variable CMAKE_CXX_EXTENSIONS
in the cache to OFF
had an effect. But this is not the solution I am interested in. I want that setting per-target.