Thanks Roman for the detailed response. I would like the hash generated when I 
use “make package” command, not “make install”. I can see that my hgHash.cmake 
is included,  but it does not run on “make package”.

Thanks,
Sasha

From: Roman Bolshakov [mailto:[email protected]]
Sent: Wednesday, February 18, 2015 8:23 PM
To: Shyrokov, Sasha
Cc: [email protected]
Subject: Re: [CMake] How to force package target generate a file before 
proceeding

add_custom_command is rather used for operations performed during build phase 
(which is completely separate off packaging)

You could create hgHash.txt during packaging by using install(SCRIPT) command:
install(SCRIPT hgHash.cmake)
install(
  FILES hgHash.txt
  DESTINATION yourapp
)

Hypothetical hgHash.cmake would be quite straightforward:
message(STATUS "Getting hg hash")
execute_process(
  COMMAND hg --debug id -i
  OUTPUT_FILE hgHash.txt
)

That would create hgHash.txt unconditionally during each cpack/make 
install/cmake -P cmake_install.cmake invocation

-Roman


On Wed, Feb 18, 2015 at 12:55 AM, Shyrokov, Sasha 
<[email protected]<mailto:[email protected]>> wrote:

Hi,

I would like to include a generated file into a package. I have something like 
that:
include(CPack)

add_custom_command (OUTPUT hgHash.txt
COMMAND hg --debug id -i >hgHash.txt
COMMENT "Getting hg hash")

add_custom_target (hg_hash
DEPENDS hgHash.txt
COMMENT "hg_hash target")

Now the following would solve my problems, but it does not work:
add_dependencies(package hg_hash)

I get:
Cannot add target-level dependencies to non-existent target "package".

I know I have CPack configured properly, because if I create the file manually 
it gets included. I also can add the dependency on one of my libraries, but I 
only want to generate this file when package is executed.

What am I missing?

Thanks,
Sasha


-- 

Powered by www.kitware.com

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

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

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

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to