CMake 3.19.2 performance issue in the project generation
Hello CMake developers,
I am maintaining my personal project hosted here: https://gitlab.com/DO-CV/sara.
I have noticed that CMake has become a lot slower upon generating a project. I upgraded from CMake 3.18.2 to 3.19.2 via brew upgrade
. I haven't found any similar issues on stack overflow or the CMake mailing list to the best of my knowledge.
[Besides another minor issue is that my custom bin
folder is created incorrectly. My custom binary folder is created as a file instead of a folder apparently, which I was able to work around it manually.]
Just to make sure the problem does not come from homebrew
, I double-checked with the binaries provided at the project page: https://cmake.org/download/ to compare the running times on my project.
Here is the performance difference:
$ export PATH=~/Downloads/cmake-3.19.2-macos-universal/CMake.app/Contents/bin:$PATH
$ time cmake ../sara ${cmake_options}
real 13m24.989s
user 2m27.519s
sys 1m35.741s
$ export PATH=~/Downloads/cmake-3.18.5-Darwin-x86_64/CMake.app/Contents/bin:$PATH
$ time cmake ../sara ${cmake_options}
real 1m20.260s
user 0m27.778s
sys 0m19.891s
As you can see, generating my Xcode project has slowed down by a factor of more than 10, which worries me a bit.
I haven't really investigated thoroughly where the issues could come from. Currently I have suspicions on some of my unconventional CMake scripting, where I replaced the command file(GLOB_RECURSE ...)
with custom macros (more details at https://gitlab.com/DO-CV/sara/-/blob/master/cmake/sara_macros.cmake#L180-226):
macro (sara_append_subdir_files _parentdir _child_dir _hdr_list_var _src_list_var)
get_filename_component(parentdir_name "${_parentdir}" NAME)
set(hdr_sublist_var DO_Sara_${parentdir_name}_${_child_dir}_HEADER_FILES)
set(src_sublist_var DO_Sara_${parentdir_name}_${_child_dir}_SOURCE_FILES)
file(GLOB ${hdr_sublist_var} FILES ${_parentdir}/${_child_dir}/*.hpp)
file(GLOB ${src_sublist_var} FILES ${_parentdir}/${_child_dir}/*.cpp)
source_group("${_child_dir}" FILES
${${hdr_sublist_var}} ${${src_sublist_var}})
list(APPEND ${_hdr_list_var} ${${hdr_sublist_var}})
list(APPEND ${_src_list_var} ${${src_sublist_var}})
#message("${hdr_sublist_var} = ${${hdr_sublist_var}}")
endmacro ()
macro(sara_glob_directory _curdir)
#message(STATUS "Parsing current source directory = ${_curdir}")
file(GLOB curdir_children RELATIVE ${_curdir} ${_curdir}/*)
get_filename_component(curdir_name "${_curdir}" NAME)
#message("Directory name: ${curdir_name}")
file(GLOB DO_Sara_${curdir_name}_HEADER_FILES FILES ${_curdir}/*.hpp)
file(GLOB DO_Sara_${curdir_name}_SOURCE_FILES FILES ${_curdir}/*.cpp)
foreach (child ${curdir_children})
if (IS_DIRECTORY ${_curdir}/${child} AND NOT "${child}" STREQUAL "build")
#message("Parsing child directory = '${child}'")
sara_append_subdir_files(${_curdir} ${child}
DO_Sara_${curdir_name}_HEADER_FILES
DO_Sara_${curdir_name}_SOURCE_FILES)
endif ()
endforeach ()
set(DO_Sara_${curdir_name}_MASTER_HEADER ${DO_Sara_SOURCE_DIR}/${curdir_name}.hpp)
source_group("Master Header File" FILES ${DO_Sara_${curdir_name}_MASTER_HEADER})
list(APPEND DO_Sara_${curdir_name}_HEADER_FILES
${DO_Sara_${curdir_name}_MASTER_HEADER})
#message(STATUS "Master Header:\n ${DO_Sara_${curdir_name}_MASTER_HEADER}")
#message(STATUS "Header file list:\n ${DO_Sara_${curdir_name}_HEADER_FILES}")
#message(STATUS "Source file list:\n ${DO_Sara_${curdir_name}_SOURCE_FILES}")
endmacro()
If these macros are really the culprits, well I guess I'll have to workaround it. I'll try to provide more information otherwise when I have time.
HTH.