Hi Chao,
As Konstantin alluded to, trying to pass "srtingified" shell scripting
through the layers of cmake and makefile escaping is bound to be fraught
with problems. The necessary escaping will very quickly become
unmaintainable. You're really best suited to place these in a separate
shell script (or cmake script to make it os-portable) and just call the
script from add_custom_command.
Hi Mr. Atkins,
Thanks a lot for your reply, and it worked well and help me a lot, there
still are some confusions about "for cyclic sentence".
I have tested some other case as below:
add_custom_target(temp_target ALL)
add_custom_command(TARGET temp_target
POST_BUILD
COMMAND
if [ "$(dir_name)" = "test_dir" ]\;
then
echo $(dir_name)\;
for x in $$\(cat
$(file_name).txt\)\;
do echo $$x \;
echo $(file_name)\;
done\;
fi)
Confusions:
1. I should use $$x in "for cyclic sentence", but i can not use $$(x) or
$$\(x\). And i can use "$$\(cat $(file_name).txt\)" and it worked well.
Even it worked when i use "$$x"(withdouble quote ).
2. When i make makefile, i use "make dir_name=test_dir
file_name=test_file", and i can get the value of dir_name and file_name by
use $(dir_name), $(file_name).
Thanks again for your help,
Chao Zhang
2016-04-19 22:20 GMT+08:00 Chuck Atkins <[email protected]>:
> Hi Chao,
>
>
>> I was using 'for cyclic sentence' in command add_custom_command(...), the
>> content of the CMakeLists.txt as below:
>> add_custom_command(TARGET temp_target
>> POST_BUILD
>> COMMAND for x in a b c\;
>> do echo $x \;
>> done\;)
>>
>
> The $x is getting parsed by the makefile so you need to escape it with the
> $ makefile escape sequence. Try:
>
> add_custom_command(TARGET temp_target
> POST_BUILD
> COMMAND for x in a b c\;
> do echo $$x \;
> done\;)
>
> You can see the difference in a make VERBOSE=1 :
>
> [100%] Linking C static library libtemp_target.a
> /home/
> khq.kitware.com/chuck.atkins/Code/CMake/build/master-release/bin/cmake -P
> CMakeFiles/temp_target.dir/cmake_clean_target.cmake
> /home/
> khq.kitware.com/chuck.atkins/Code/CMake/build/master-release/bin/cmake -E
> cmake_link_script CMakeFiles/temp_target.dir/link.txt --verbose=1
> /usr/bin/ar qc libtemp_target.a CMakeFiles/temp_target.dir/foo.c.o
> /usr/bin/ranlib libtemp_target.a
> *for x in a b c; do echo ; done;*
>
>
>
> make[2]: Leaving directory '/home/khq.kitware.com/chuck.atkins/tmp/bld'
>
> Now becomes:
>
> [100%] Linking C static library libtemp_target.a
> /home/
> khq.kitware.com/chuck.atkins/Code/CMake/build/master-release/bin/cmake -P
> CMakeFiles/temp_target.dir/cmake_clean_target.cmake
> /home/
> khq.kitware.com/chuck.atkins/Code/CMake/build/master-release/bin/cmake -E
> cmake_link_script CMakeFiles/temp_target.dir/link.txt --verbose=1
> /usr/bin/ar qc libtemp_target.a CMakeFiles/temp_target.dir/foo.c.o
> /usr/bin/ranlib libtemp_target.a
>
>
>
> *for x in a b c; do echo $x ; done;abc*
> make[2]: Leaving directory '/home/khq.kitware.com/chuck.atkins/tmp/bld'
>
> - Chuck
>
>
>
--
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