I'm using CMake 2.6.4, Visual Studio 8 2005 generator. I'm going to use $(TargetPath) for now. The command is wrapped in a macro, so it's easy to replace it with a generator-independent way. Right now I just need to get this working in Visual Studio so I can roll CMake out to the rest of the team.
Thanks for helping. Daniel Tavares Programmer | Slipgate Ironworks http://www.slipg8.com -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Jacob Repp Sent: Friday, May 29, 2009 11:24 AM To: [email protected] Subject: Re: [CMake] Copy target from different configurations Unfortunately at least in version 2.6.4 the local visual studio 7 generator doesn't honor the cmake output path settings so some of the suggestions for that version at least will not work. If you're using the newer visual studio generator (you don't specify) you can take advantage of the VS macros expansions in your custom command: if (MSVC) add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD COMMAND copy "$(TargetPath)" "${YOUR_DEST_PATH}") endif () Notice that the $(TargetPath) is using $(FOO) notation rather than the cmake ${FOO} notation. There is a large collection of these 'macros' that you can access in custom commands when building under VS. In our situation I just wanted to skip the copy step because there are scenarios when it doesn't execute anyways and I wanted something like this: # Replacement for add_executable for servers macro (add_server NAME) add_executable (${NAME} ${ARGN}) set_target_properties (${NAME} PROPERTIES DEBUG_POSTFIX "_d") set_target_properties (${NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ROOT}/servers/bin) endmacro (add_server) I found that the VS7 local generator doesn't honor the *_OUTPUT_DIRECTORY properties so here's a modification that I added to our local version: =================================================================== --- cmLocalVisualStudio7Generator.cxx (revision 13158) +++ cmLocalVisualStudio7Generator.cxx (revision 13494) @@ -546,9 +546,6 @@ { mfcFlag = "0"; } - fout << "\t\t<Configuration\n" - << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n" - << "\t\t\tOutputDirectory=\"" << configName << "\"\n"; // This is an internal type to Visual Studio, it seems that: // 4 == static library // 2 == dll @@ -556,19 +553,23 @@ // 10 == utility const char* configType = "10"; const char* projectType = 0; + const char* outputDirectory = NULL; switch(target.GetType()) { case cmTarget::STATIC_LIBRARY: projectType = "typeStaticLibrary"; configType = "4"; + outputDirectory = target.GetProperty("ARCHIVE_OUTPUT_DIRECTORY"); break; case cmTarget::SHARED_LIBRARY: case cmTarget::MODULE_LIBRARY: projectType = "typeDynamicLibrary"; configType = "2"; + outputDirectory = target.GetProperty("RUNTIME_OUTPUT_DIRECTORY"); break; case cmTarget::EXECUTABLE: configType = "1"; + outputDirectory = target.GetProperty("RUNTIME_OUTPUT_DIRECTORY"); break; case cmTarget::UTILITY: case cmTarget::GLOBAL_TARGET: @@ -580,6 +581,15 @@ { configType = projectType; } + + if (!outputDirectory) + { + outputDirectory = configName; + } + fout << "\t\t<Configuration\n" + << "\t\t\tName=\"" << configName << "|" << this->PlatformName << "\"\n" + << "\t\t\tOutputDirectory=\"" << configName << "\"\n"; + std::string flags; if(strcmp(configType, "10") != 0) { On Fri, May 29, 2009 at 9:27 AM, Tyler Roscoe <[email protected]> wrote: > On Thu, May 28, 2009 at 04:02:35PM -0700, Daniel Tavares wrote: >> I'm trying to add a post build event using add_custom_command that will >> copy the target executable to a different directory, but I can't get the >> correct location of the executable created at build time, because it >> changes depending on the configuration being built. > > This has been discussed a lot recently. Maybe it's time for a FAQ entry > or, even better, an enhancement to CMake so that we can specify > custom_commands and custom_targets by BUILD_TYPE? > > A possible workaround from David Cole: > http://www.cmake.org/pipermail/cmake/2009-May/029618.html > > Another approach from James Bigler: > http://www.cmake.org/pipermail/cmake/2009-May/029526.html > > Clinton Stimpson replies to my thread on this topic, though his solution > might not help your case: > http://www.cmake.org/pipermail/cmake/2009-May/029476.html > > tyler > _______________________________________________ > 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 > _______________________________________________ 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 _______________________________________________ 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
