[CMake] How do I generate a preprocessed file?
Piotr Wyderski
piotr.wyderski at gmail.com
Thu May 7 10:57:11 EDT 2009
Hello,
my problem is as follow. I have a project composed of
four directories: base, io, rt and vm. The first three of them
are being built in a normal way, but the last one has some
fancy requirements. Namely, in the directory vm I want to
generate a file called inc.cpp, which is composed of all
the header files from base, io and rt, preprocessed
by the C++ compiler. So, in vm/CMakeLists.txt I specify:
ADD_DEFINITIONS(-DCONFIG_BUILDING_VM)
ADD_LIBRARY(vm SHARED inc.cpp)
Next, I indicate that inc.cpp is generated:
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/inc.cpp
PROPERTIES GENERATED 1)
Then I create a list of all the header files of interest:
FILE(
GLOB
_runtime_header_list
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/base/*.h
${PROJECT_SOURCE_DIR}/io/*.h
${PROJECT_SOURCE_DIR}/rt/*.h)
And specify a command to generate the file:
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/inc.cpp
COMMAND YYY >inc.cpp
DEPENDS ${_runtime_header_list}
)
but what shoud YYY be in order to achieve the following goal:
1. all the entries from _runtime_header_list are enumerated
and a single temporary file t1.cpp is created as follows:
#include "entry_1"
#include "entry_2"
...
#include "entry_n"
2. t1 is sent to the C++ compiler (with all its options,
definitions and include paths set as for a normal build),
but for preprocessing stage only (i.e. g++ -E). The resulting
C++ file is my inc.cpp.
How can I achieve that goal using CMake? Of course
it doesn't need to be done the way I specified above,
as I am pretty new to CMake. A functional equivalent
is all what I need, in particular I don't need t1.cpp.
Best regards
Piotr Wyderski
More information about the CMake
mailing list