Hello,

we are porting a larger set of projects (~70) to CMake. The current build has a 
feature to integrate the current timestamp of the build into the final binary / 
target. If a target is relinked, a header (id.h) is created with the current 
timestamp, a user provided C file (id.c), including that header is recompiled 
and linked into the target as well.

While thinking about how to provide a similar solutions, we came up with some 
ideas:

1) add_custom_command()

The projects have to move id.c into a separate library. For the main target, 
all depending targets (excluding the library containing id.c) are determined. A 
add_custom_command() creates id.h and depends on the list of determined, 
depending targets.

The drawback that I see here, is that other, additional dependencies (like 
introduced with add_custom_command()) are not taken into account and that we 
have to recreate the algorithm to determine all direct and indirect depending 
targets.

2) add_custom_command(TARGET <target> PRE_LINK…)

The generation of both, id.h and id.c are excluded from the main target and are 
build by the add_custom_command(). The resulting object file is added as 
GENERATED, EXTERNAL_OBJECT source file to the main target.

The drawback here is, that the custom command have to compile the id.c file, 
using the right compiler, the right flags, include paths etc.

To me it doesn’t sound to be a very special requirement to have some kind of 
hash (timestamp in this case) over the compiled files in the resulting binary. 
How do others solve this or similar problems? Any comments to our ideas?

TIA,

Torsten

Attachment: signature.asc
Description: Message signed with OpenPGP

-- 

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:
https://cmake.org/mailman/listinfo/cmake

Reply via email to