[cmake-developers] adding command line flags for CMAKE_MAKE_PROGRAM

Williams, Norman K norman-k-williams at uiowa.edu
Wed Jul 30 11:06:13 EDT 2014


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.
________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20140730/f5d135f7/attachment.html>


More information about the cmake-developers mailing list