[CMake] Build several targets using cmake --build <dir>

Gregoire Aujay gaujay at movea.com
Fri Mar 15 08:14:57 EDT 2013


Hello,

Thanks again.
In my case I cannot use your script. I have the constraint to be 'outside cmake' so I do not know any of internal values like CMAKE_MAKE_PROGRAM. I can only call 'cmake --build' to build stuff.

I filed a feature request : http://www.cmake.org/Bug/view.php?id=14014


Regards,
Gregoire

From: J Decker [mailto:d3ck0r at gmail.com]
Sent: vendredi 15 mars 2013 12:45
To: Gregoire Aujay
Cc: Nick Overdijk; John Drescher; cmake at cmake.org
Subject: Re: [CMake] Build several targets using cmake --build <dir>

My ugly macro looks like...  Build project macro creates targets 'build${PROJECT}' which can be depended on each other...

It writes to a output batch file, and then calls that batch.  The batch file contains a cmake execution for that target, and then ${CMAKE_MAKE_PROGRAM} command.

-----------------------------------

macro( BuildProject PROJECT SOLUTION PROJECT_SOURCE INSTALL_RESULT )

  set( LAST_TARGET Build${PROJECT} )
  if( CMAKE_BINARY_DIR MATCHES ${CMAKE_BUILD_TYPE}_solution\$ )
    set( INSTALL ${CMAKE_BINARY_DIR}/../${CMAKE_BUILD_TYPE}_out/${PROJECT} )
    set( BUILD ${CMAKE_BINARY_DIR}/../${CMAKE_BUILD_TYPE}_solution/${PROJECT} )
  else()
    set( INSTALL ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}_out/${PROJECT} )
    set( BUILD ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}_solution/${PROJECT} )
  endif( CMAKE_BINARY_DIR MATCHES ${CMAKE_BUILD_TYPE}_solution\$ )
  set( ${INSTALL_RESULT} ${INSTALL} )

  FILE( MAKE_DIRECTORY ${BUILD} )

  if( MSVC )
    if( NOT EXISTS ${BUILD}/${SOLUTION}.sln )
      FILE( WRITE ${BUILD}/${SOLUTION}.sln )
    endif()
    if( ${CMAKE_MAKE_PROGRAM} MATCHES .*[Mm][Ss][Bb]uild.* )
             build_command( BUILD_COMMAND CONFIGURATION ${CMAKE_BUILD_TYPE} PROJECT_NAME ${SOLUTION} TARGET INSTALL )
          SET( MORE_ARGS /m:4 /v:m )
    else()
             build_command( BUILD_COMMAND CONFIGURATION ${CMAKE_BUILD_TYPE} PROJECT_NAME ${SOLUTION} TARGET INSTALL.vcxproj )
    endif()
    SEPARATE_ARGUMENTS( BUILD_COMMAND WINDOWS_COMMAND ${BUILD_COMMAND} )
    SET( BUILD_COMMAND ${BUILD_COMMAND} ${MORE_ARGS} )
    SET( ADD_SOURCES  SOURCES ${BUILD}/${SOLUTION}.sln )
  else( MSVC )
    build_command( BUILD_COMMAND CONFIGURATION ${CMAKE_BUILD_TYPE} PROJECT_NAME ${SOLUTION} TARGET install )
    SEPARATE_ARGUMENTS( BUILD_COMMAND UNIX_COMMAND ${BUILD_COMMAND} )
  endif( MSVC )

  if( CMAKE_TOOLCHAIN_FILE )
    set( TOOLCHAIN -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} )
  endif( CMAKE_TOOLCHAIN_FILE )

  set( FAKE_ARGN1 ${ARGN})
  string (REPLACE ";" " " FAKE_ARGN2 "${FAKE_ARGN1}")
  FILE( WRITE  ${BUILD}/makeit.bat "\"${CMAKE_COMMAND}\" -G \"${CMAKE_GENERATOR}\" ${TOOLCHAIN} \"${PROJECT_SOURCE}\" -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${INSTALL} ${FAKE_ARGN2}\n" )
  string (REPLACE ";" " " FAKE_BUILD_COMMAND "${BUILD_COMMAND}")
  FILE( APPEND ${BUILD}/makeit.bat ${FAKE_BUILD_COMMAND} )

  add_custom_target( Build${PROJECT} ALL
          COMMAND makeit.bat
             WORKING_DIRECTORY ${BUILD}
          ${ADD_SOURCES}
  )
endmacro( BuildProject )
-----------------
usage is something like


set( PROJECT intershell )
set( EXTRA_FLAGS  -DSACK_SDK_ROOT_PATH=${SACK_SDK_ROOT_PATH} )
BuildProject( ${PROJECT} ${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../src/InterShell INTERSHELL_SDK_ROOT_PATH ${EXTRA_FLAGS} )
Add_custom_command( TARGET Build${PROJECT}
            COMMAND ${INTERSHELL_SDK_ROOT_PATH}/intershell_deploy${CMAKE_EXECUTABLE_SUFFIX} -nr
            WORKING_DIRECTORY ${INTERSHELL_SDK_ROOT_PATH}
)
add_dependencies( ${LAST_TARGET} Buildcore )

-----------------

Above sourced from

https://code.google.com/p/c-system-abstraction-component-gui/source/browse/cmake_all/CMakeLists.txt
and
https://code.google.com/p/c-system-abstraction-component-gui/source/browse/cmake_all/CMakeBuild.txt

--------------------


On Fri, Mar 15, 2013 at 4:37 AM, J Decker <d3ck0r at gmail.com<mailto:d3ck0r at gmail.com>> wrote:
If the dependencies are already satisfied, and the cmake_make_program can run mutliple in parallel, then it works great.

I have a cmake script that builds other cmake top level projects; and this ends up building in parallel on visual studio.

can't do it with any other compiler I use for windows (make can be aliased on linux to include a /j4).

On Fri, Mar 15, 2013 at 1:37 AM, Gregoire Aujay <gaujay at movea.com<mailto:gaujay at movea.com>> wrote:
Hello,

Thanks for your replies. I understand that I can only 'cmake --build' one target at a time.
I think that the solutions you propose do not benefit from tools, like ninja, that have parallel build capabilities.

I'll file a feature request.

Regards,
Greg

-----Original Message-----
From: Nick Overdijk [mailto:nick at astrant.net<mailto:nick at astrant.net>]
Sent: jeudi 14 mars 2013 19:10
To: John Drescher
Cc: Gregoire Aujay; cmake at cmake.org<mailto:cmake at cmake.org>
Subject: Re: [CMake] Build several targets using cmake --build <dir>

You can only 'cmake' a single-target. If you want to have more targets, create more directories: for each target one.

On 2013-14-03, at 19:07:36 , John Drescher wrote:

>> I use cmake 2.8.10 on windows.
>>
>>
>>
>> I would like to build several targets with cmake --build <dir> so
>> the underlying build tool to do parallel jobs.
>>
>>
>>
>> Currently it only seems to be possible to build one target at a time,
>> using --target .
>> (http://www.cmake.org/cmake/help/v2.8.10/cmake.html#opt:--builddir)
>>
>>
>>
>> Can someone tell me how I could achieve that with current cmake version?
>>
>>
> I execute more than 1 cmake --build at the same time on windows. I
> actually do this in a program called runjobs
>
> http://www.codeproject.com/Articles/25810/Run-All-Jobs-at-Once-Utility
>
> John
> --
>
> Powered by www.kitware.com<http://www.kitware.com>
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



--

Powered by www.kitware.com<http://www.kitware.com>

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130315/3e7e8e82/attachment.htm>


More information about the CMake mailing list