I was trying to get ExternalProjects generated with the Ninja generator to do a
better job of handling multiple CPUs and load, so I tried the naïve solution
below.
I needed to add flags to the program named in CMAKE_MAKE_PROGRAM. This is
difficult because CMAKE_MAKE_PROGRAM is a string; I can pass it as part of an
ExternalProjects’ CMAKE_ARGS, but then the resulting build tries to run
“/usr/bin/ninja –j 32” as the command, instead of adding –j 32 to ninja’s
command line.
Any ideas, or am I asking for a CMAKE_MAKE_PROGRAM_FLAGS command? Or to modify
the generator?
the only alternative is to explicitly set the BUILD_COMMAND for every
ExternalProject_add command.
#------------------------------
# For ninja generator, propagate ninja flags
#------------------------------
if(CMAKE_GENERATOR MATCHES ".*Ninja.*")
if(NOT DEFINED PROCESSOR_COUNT)
# Unknown:
set(PROCESSOR_COUNT 1)
# Linux:
if(CMAKE_SYSTEM_NAME MATCHES ".*Linux.*")
set(cpuinfo_file "/proc/cpuinfo")
if(EXISTS "${cpuinfo_file}")
file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$")
list(LENGTH procs PROCESSOR_COUNT)
endif()
# Mac:
elseif(APPLE)
find_program(cmd_sys_pro "system_profiler")
if(cmd_sys_pro)
execute_process(COMMAND ${cmd_sys_pro} OUTPUT_VARIABLE info)
string(REGEX REPLACE "^.*Total Number Of Cores: ([0-9]+).*$" "\\1"
PROCESSOR_COUNT "${info}")
endif()
# Windows:
elseif(WIN32)
set(PROCESSOR_COUNT "$ENV{NUMBER_OF_PROCESSORS}")
endif()
endif()
set(CMAKE_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM} -l ${PROCESSOR_COUNT})
endif()
________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the
Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and
may be legally privileged. If you are not the intended recipient, you are
hereby notified that any retention, dissemination, distribution, or copying of
this communication is strictly prohibited. Please reply to the sender that you
have received the message in error, then delete it. Thank you.
________________________________
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake