2
votes

I'm trying to cross compile some c++ library for QNX neutrino using cmake. In CMakeLists.txt file I specified CMAKE_CXX_STANDARD 14 required, but the resulting compiler command line does not contain the -std=c++14 option.

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

I've tried using target compile features:

target_compile_features(my_library PRIVATE cxx_std_14)

but that gives me the following error:

CMake Error at CMakeLists.txt:53 (target_compile_features):
    target_compile_features no known features for CXX compiler

    "QCC"

    version 5.4.0.

When I'm using check_cxx_compiler_flag feature, it seems to recognize the option:

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-std=c++14 CXX14_SUPPORT)
if(CXX14_SUPPORT)
  message("c++14 support found")
else()
  message("c++14 unsupported")
endif()

This outputs message

c++14 support found

Running qcc manually it accepts the -std=c++14 option just fine and the code using std::make_unique compiles just fine.

Also using the native compiler (Ubuntu 18.04, gcc) everything work fine with cmake generated makefiles. make VERBOSE=1 displays the following command line (I removed some directories):

/usr/local/bin/c++  -Dshm_transfer_EXPORTS -I...  -fPIC   -std=gnu++14 -o CMakeFiles/shm_transfer.dir/src/SharedMemoryTransfer.cpp.o -c .../SharedMemoryTransfer.cpp

as opposed to the command line using qcc toolchain:

.../qnx700/host/linux/x86_64/usr/bin/qcc -lang-c++ -Vgcc_ntox86_64 -lang-c++ -Dshm_transfer_EXPORTS -I...  -fPIC   -o CMakeFiles/shm_transfer.dir/src/SharedMemoryTransfer.cpp.o -c .../SharedMemoryTransfer.cpp

I would have expected the cmake command to recognize that qcc supports the -std=c++14 option and generates the corresponding command lines because of the CMAKE_CXX_STANDARD setting.

1

1 Answers

4
votes

Use

set_property(TARGET ${PROJECT_NAME} PROPERTY LINKER_LANGUAGE CXX)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)

. Using this you can stick the compiler setting to the target, while global flags are dis encouraged and can be overwritten by other cmake consumers. This the reason I assume why the deprecated set(CMAKE_CXX_STANDARD 14) did not help you: I can not see your full CMakeLists.txt and bet you have many sub folders and other targets, which could reset the CMAKE_CXX_STANDARD them selfs. Also make sure of the ordering of the CMake commands.

And you can replace ${PROJECT_NAME} with my_library if you want.