Reputation: 6042
I'm trying to precompile a 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 don't get CMAKE_CXX_FLAGS to expand into flags I've set using CMake's add_definitions(). What is the correct way of compiling in add_custom_command()?
Upvotes: 4
Views: 2181
Reputation: 1534
I don't believe that add_definitions()
adds its arguments to CMAKE_CXX_FLAGS
. In fact, as far as I can tell they aren't saved anywhere (apart from arguments beginning with -D
or /D
which get added to COMPILE_DEFINITIONS
).
The simplest way to solve that would be to, whenever calling add_definitions()
, to also manually add those flags to CMAKE_CXX_FLAGS
.
To see what is in CMAKE_CXX_FLAGS
at any point, you can do
message(STATUS ${CMAKE_CXX_FLAGS})
or check the CMakeCache.txt
in the build directory (or via ccmake
or cmake-gui
).
Upvotes: 1