[CMake] How to get custom commands to build in parallel ?
Glenn Coombs
glenn.coombs at gmail.com
Tue Sep 23 11:05:56 EDT 2014
I have the following code in one of my CMakeLists.txt files:
set(feature_files_h)
set(feature_files_cpp)
macro(create_feature_files NAME)
add_custom_command(
OUTPUT ${FEATURES_OUTPUT_DIR}/${NAME}.cpp
${FEATURES_OUTPUT_DIR}/${NAME}.h
DEPENDS ${FEATURES_INPUT_DIR}/${NAME}.txt
WORKING_DIRECTORY ${SIM_ROOT}/tools/features
COMMAND perl ${FEATURES_PERL_PATH} "-s${FEATURES_INPUT_DIR}"
"-d${FEATURES_OUTPUT_DIR}" "-f${NAME}"
)
list(APPEND feature_files_h ${FEATURES_OUTPUT_DIR}/${NAME}.h)
list(APPEND feature_files_cpp ${FEATURES_OUTPUT_DIR}/${NAME}.cpp)
endmacro()
create_feature_files(example_features)
create_feature_files(fme_core_features)
create_feature_files(fme_features)
create_feature_files(front_end_features)
create_feature_files(inloop_filter_features)
add_library(${PROJECT_NAME} STATIC ${feature_files_cpp} ${feature_files_h}
${SIM_ROOT}/tools/features/cpp-code/cfeatures.cpp)
which creates a library from an existing source file called cfeatures.cpp
and from a bunch of auto-generated .cpp and .h files. The whole thing
works fine and runs the perl script to create each of the auto-generated
files before creating the library. The only problem I have with it is that
it is quite slow and I would like to speed it up by having it run the perl
commands to create the auto-generated files in parallel. Currently, each
of the auto-generated cpp files is generated sequentially, then they are
all compiled in parallel and the library created in the final step.
I'm using cmake 3.0.0 with Visual Studio 2013 Express Edition. And I've
added the /MP option so that Visual Studio will do parallel builds. I've
also set the "Projects and Solutions=>Build and Run=>maximum number of
parallel project builds" option to 4. This works well with all the normal
cpp files in other projects and I easily see all 4 cpu cores maxxed out.
But when building this project only 1 cpu core is used.
Can anybody tell me how to change it so that the auto-geneated files are
created in parallel as well ?
--
Glenn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140923/f4ba163f/attachment.html>
More information about the CMake
mailing list