[cmake-developers] Ninja with multiple commands (was: CMAKE_ARGC and CMAKE_ARGVx)
Nicolas Desprès
nicolas.despres at gmail.com
Tue May 3 10:21:10 EDT 2011
2011/5/3 Brad King <brad.king at kitware.com>:
> On 04/28/2011 02:24 PM, Nicolas Desprès wrote:
>> Ninja accepts only one command per rule contrary to make.
>> So when several commands must be called (for example: ar and ranlib),
>> one possibility is to bundle the commands in a cmake scripts
>
> Instead of trying to pass this all through CMake language syntax and
> the execute_process command, I suggest you create a dedicated internal
> interface for it. See for example the cmake::ExecuteLinkScript method
> and the calls to it already used to execute long linker command lines.
>
I have tried to use it in the first place. But I would like to use
generic ninja rules short and to use the per target variable
overloading system provided by Ninja. Here an example for an
helloworld with a static and a shared library:
# Rule for compiling CXX files.
rule CXX_COMPILER
command = /usr/lib/ccache/g++ $CXX_DEFINES $CXX_FLAGS -o $out -c $in
description = Building CXX object $out
# Rule for linking CXX static library.
rule CXX_STATIC_LIBRARY_LINKER
command = /usr/bin/ar cr $out $LDFLAGS $in && /usr/bin/ranlib $out
description = Linking CXX static library $out
# Rule for linking CXX executable.
rule CXX_EXECUTABLE_LINKER
command = /usr/lib/ccache/g++ $CXX_FLAGS $LDFLAGS $in -o $out $LDLIBS
description = Linking CXX executable $out
# Rule for linking CXX shared library.
rule CXX_SHARED_LIBRARY_LINKER
command = /usr/lib/ccache/g++ -fPIC $CXX_FLAGS $LDFLAGS -shared
-Wl,-soname,$SONAME -o $out $in $LDLIBS
description = Linking CXX shared library $out
# Not that I can overload the CXX_FLAGS variable for each build statement.
build CMakeFiles/greeting.dir/src/greeting/greeting.cc.o: CXX_COMPILER
/home/despre_n/src/test/helloworld-static-cmake/src/greeting/greeting.cc
CXX_FLAGS = -g -I/home/despre_n/src/test/helloworld-static-cmake/src
build libgreeting.a: CXX_STATIC_LIBRARY_LINKER
CMakeFiles/greeting.dir/src/greeting/greeting.cc.o
CXX_FLAGS = -g
SONAME = libgreeting.a
build helloworld: CXX_EXECUTABLE_LINKER
CMakeFiles/helloworld.dir/src/main.cc.o libgreeting.a
CXX_FLAGS = -g
LDLIBS = -rdynamic
I will try to think more about it. Maybe generating something like
this using implicit shared library would work would work:
# Rule for linking CXX static library.
rule CXX_STATIC_LIBRARY_LINKER
command = $CMAKE_COMMAND -E cmake_link_script $in --verbose=$VERBOSE
description = Linking CXX static library $out
build libgreeting.a: CXX_STATIC_LIBRARY_LINKER
CMakeFiles/greeting.dir/link.txt |
CMakeFiles/greeting.dir/src/greeting/greeting.cc.o
But implicit dependencies have not exactly the same meaning of
explicit depencies (which appears in the $in variable). Here the
documentation http://martine.github.com/ninja/manual.html#_build_dependencies
Also there are some discussion about changing this behavior and to
make implicit dependencies similar to explicit ones expect that they
don't appears in the $in variables.
http://groups.google.com/group/ninja-build/browse_thread/thread/b0c239b63e04287e
For custom targets and custom commands calling several commands I will
have to generate cmake script anyway expect if Ninja changes is
behavior:
http://groups.google.com/group/ninja-build/browse_thread/thread/d7c0fffa54ab76ba
Thanks for the advices.
--
Nicolas Desprès
More information about the cmake-developers
mailing list