[CMake] Running a executable after generation

J Decker d3ck0r at gmail.com
Sat Dec 3 20:39:04 EST 2011


On Sat, Dec 3, 2011 at 3:58 PM, terje loe <terjeloe at hotmail.com> wrote:
> Is it possible to get cmake to run a executable or a script after it has
> generated the project/make files?
> I know of execute_process() , but this runs the process while generating.
>
> As it seems like cmake currently doesn't support what I want to do I would
> like to run a script after the generation to update my visual studio files
> manualy.
>
> http://www.itk.org/Bug/view.php?id=11902

could make a cmakelists that does a cmake to generate and thrn runs a
command after... then you get a solution that has all the solutions in
it....   At the end of the following macro there's 'add_custom_target'
which has two commands, one to cmake the project and the next to build
it... instead of doing a build you could work it so it does your
custom command...


macro( BuildProject PROJECT SOLUTION PROJECT_SOURCE INSTALL_RESULT )

  set( LAST_TARGET Build${PROJECT} )
  if( "$ENV{BUILD_COMMAND}" STREQUAL "" )
    set( INSTALL ${CMAKE_BINARY_DIR}/out/${PROJECT} )
    set( BUILD ${CMAKE_BINARY_DIR}/build/${PROJECT} )
  else()
    set( INSTALL ${CMAKE_BINARY_DIR}/../../${CMAKE_BUILD_TYPE}_out/${PROJECT} )
    set( BUILD ${CMAKE_BINARY_DIR}/../${PROJECT} )
  endif()
set( ${INSTALL_RESULT} ${INSTALL} )

FILE( MAKE_DIRECTORY ${BUILD} )

if( MSVC )
  if( NOT EXISTS ${BUILD}/${SOLUTION}.sln )
    FILE( WRITE ${BUILD}/${SOLUTION}.sln )
  endif()
  build_command( BUILD_COMMAND CONFIGURATION ${CMAKE_BUILD_TYPE}
PROJECT_NAME ${SOLUTION} TARGET INSTALL.vcxproj )
  SEPARATE_ARGUMENTS( BUILD_COMMAND WINDOWS_COMMAND ${BUILD_COMMAND} )
  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 )

add_custom_target( Build${PROJECT} ALL
	COMMAND cmake -G "${CMAKE_GENERATOR}" ${PROJECT_SOURCE}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${INSTALL} ${ARGN}
        COMMAND ${BUILD_COMMAND}
	WORKING_DIRECTORY ${BUILD}
        ${ADD_SOURCES}
)
endmacro( BuildProject )

set( PROJECT core )
set( EXTRA_FLAGS -DBUILD_MONOLITHIC=${BUILD_MONOLITHIC}
${DDIRECTX_SDK} ${SACK_REQUIREMENTS} ${DFORCE_MSVCRT} ${DBUILD_TESTS}
${DBUILD_UNICODE} )
BuildProject( ${PROJECT} sack ${CMAKE_CURRENT_LIST_DIR}/..
SACK_SDK_ROOT_PATH ${EXTRA_FLAGS} )
Add_custom_command( TARGET Build${PROJECT}
	COMMAND ${SACK_SDK_ROOT_PATH}/bin/${CMAKE_BUILD_TYPE}/sack_deploy.exe -nr
	WORKING_DIRECTORY ${SACK_SDK_ROOT_PATH}
)



>
> --
>
> Powered by 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


More information about the CMake mailing list