[CMake] Question about install()

Hugo Heden hugoheden at gmail.com
Tue Dec 9 18:49:05 EST 2008


2008/12/9 Robert Dailey <rcdailey at gmail.com>:
> On Tue, Dec 9, 2008 at 11:05 AM, Robert Dailey <rcdailey at gmail.com> wrote:
>>
>> Michael,
>>
>> Is there a way to call add_custom_command() on a specific configuration
>> for a specific target? If I can do this then I can use CMAKE to copy the
>> files  appropriately and your method would work perfectly.
>>
>> Thanks for your tme.
>
> After much research, I've found out that CMake cannot provide a custom
> command (Post build event) to a specific configuration in the case where
> CMake is used to generate a multi-configuration target, such as a visual
> studio project. This is a HUGE problem for me. Are there any work-arounds
> for this issue? Does this issue plan to be addressed in a future release
> (Hopefully soon)?
>

I wonder if you could use the "ctest --build-and-test" tool, telling
it to configure (run cmake on) some custom little CMakeLists.txt-file
that could perform the copying. The "ctest --build-and-test" tool can
be given the "--build-config-sample" flag, that helps figuring out
whether it is a Debug or Release build currently going on. ctest can
thusly set  the CMAKE_BUILD_TYPE variable when invoking cmake on that
custom CMakeLists.txt-file, so that the latter could perform the
copying based on that variable.

I'm not sure that I understand your problem correctly (and it's in the
middle of the night here) so I will not explain more now ... but take
a look at the following example and see if it is possible to
understand what it does .. (Note that it needs to be adapted for the
case where CMAKE_BUILD_TYPE is set as well in order to be generic, but
that is easy)

Best regards

Hugo Heden
Stockholm, Sweden


CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

PROJECT(test)

# Create some dummy source (on the fly, but that is not necessary) and
#make sure it is compiled using a subdirectory with a CMakeLists.txt.
#The "ctest --build-and-test" (below) will later use the directory in which
#the executable ends up to figure out what build type this is. This is what
#the --build-config-sample flag is for.

FILE( WRITE
  ${CMAKE_CURRENT_BINARY_DIR}/dummy_src/CMakeLists.txt
  "ADD_EXECUTABLE( dummy dummy.cpp )"
  )

FILE( WRITE
  ${CMAKE_CURRENT_BINARY_DIR}/dummy_src/dummy.cpp
  "int main(){}"
  )

ADD_SUBDIRECTORY(
  ${CMAKE_CURRENT_BINARY_DIR}/dummy_src/
  ${CMAKE_CURRENT_BINARY_DIR}/dummy_build/
  )

ADD_CUSTOM_TARGET( some_target
  ALL
  DEPENDS dummy
  COMMAND
    ${CMAKE_CTEST_COMMAND}
    --build-and-test ${CMAKE_CURRENT_BINARY_DIR}/tmp_custom_command
${CMAKE_CURRENT_BINARY_DIR}/tmp_custom_command
    --build-generator ${CMAKE_GENERATOR}
    --build-makeprogram ${CMAKE_BUILD_TOOL}
    --build-noclean
    --build-config-sample ${CMAKE_CURRENT_BINARY_DIR}/dummy_build/dummy
    #--build-config ${CMAKE_BUILD_TYPE}
)

# Ok, finally, this is the CMakeLists.txt that will be "invoked" by the
#ctest-command above.. (here we create it on the fly, but that is
# not necessary)

FILE( WRITE
  ${CMAKE_CURRENT_BINARY_DIR}/tmp_custom_command/CMakeLists.txt
  "
  MESSAGE( STATUS \"Wohoooooooo ----- There is a build going on with
build type: \${CMAKE_BUILD_TYPE}\")
  IF( \${CMAKE_BUILD_TYPE} STREQUAL \"Debug\" )
    MESSAGE( STATUS \"Wohoooooooo ----- here we could copy Debug-dll:s
to some Debug destination directory.\")
  ELSEIF( \${CMAKE_BUILD_TYPE} STREQUAL \"Release\" )
    MESSAGE( STATUS \"Wohoooooooo ----- here we could copy
Release-dll:s to some Release destination directory.\")
  ENDIF( \${CMAKE_BUILD_TYPE} STREQUAL \"Debug\" )
 "
)


More information about the CMake mailing list