[CMake] How to calculate a value "on the fly" for use with gcc compiler option?
Tyler Roscoe
tyler at cryptio.net
Fri Jul 17 15:35:00 EDT 2009
On Fri, Jul 17, 2009 at 08:32:38PM +0200, Jörg Förstner wrote:
> We use gcc's option "-frandom-seed=<value>", which uses a given value as a starting point for it's random number generator.
> As every file shall have a unique random seed, we calculate the MD5 checksum of each source file "on the fly".
> This checksum is then used as a value for the option "-frandom-seed".
This sounds pretty crazy. Not really relevant to your question, but why
do you need to do all this? Are you trying obfuscate your object files
to prevent decompilation or something?
> Here's how the current compile rule in the old Makefile looks like:
> $(CC) -frandom-seed=$(shell md5sum $< | sed 's/\(.*\) .*/\1/') $(CCFLAGS) -c $< -o $@
>
> I tried to do this in cmake, but I only have this command:
> ADD_DEFINITIONS(
> "-frandom-seed=$(shell md5sum $< | sed 's/\(.*\) .*/\1/')"
> )
>
> But how can I determine the current filename and replace "$<" by the filename?
> How can this be made using cmake?
I would move all the md5sum and sed complexity into a script and then
just iterate over your source files, sending each to the script and
getting the appropriate output. Something like this:
foreach (_file ${src_files})
execute_process (my_md5sum_sed_script ${_file}
OUTPUT_VARIABLE _seed)
add_definitions (...)
endforeach ()
hth,
tyler
More information about the CMake
mailing list