CMake compiles a C ++ file in a user command

I am trying to precompile the header file in GCC with the following command:

ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/all.hpp.gch COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} -o ${CMAKE_BINARY_DIR}/all.hpp.gch ${CMAKE_CURRENT_SOURCE_DIR}/all.hpp DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/all.hpp COMMENT "Generating precompiled headers" ) 

However, I am not getting CMAKE_CXX_FLAGS to extend the flags that I set using CMake add_definitions (). What is the correct way to compile in add_custom_command ()?

+4
source share
1 answer

I do not think add_definitions() adds its arguments to CMAKE_CXX_FLAGS . In fact, as far as I can tell, they are not saved anywhere (except for arguments starting with -D or /D , which are added to COMPILE_DEFINITIONS ).

The easiest way to solve this would be, by calling add_definitions() , also manually add these flags to CMAKE_CXX_FLAGS .

To find out what is in CMAKE_CXX_FLAGS anywhere, you can do

 message(STATUS ${CMAKE_CXX_FLAGS}) 

or check CMakeCache.txt in the build directory (either via ccmake or cmake-gui ).

+1
source

Source: https://habr.com/ru/post/1302230/


All Articles