Discussion:
[Cmake] ADD_CUSTOM_COMMAND and PRE_BUILD
Benjamin Rutt
2004-04-19 13:38:18 UTC
Permalink
I'm using cmake 1.8.3. I read that ADD_CUSTOM_COMMAND can be used in
the following way, quoted from 'cmake --help ADD_CUSTOM_COMMAND':

The second signature adds a custom command to a target such as a
library or executable. This is useful for performing an operation
before or after building the target:

ADD_CUSTOM_COMMAND(TARGET target
PRE_BUILD | PRE_LINK | POST_BUILD
COMMAND command
[ARGS [args...]]
[COMMENT comment])

This defines a new command that will be associated with building the
specified target. When the command will happen is determined by which
of the following is specified:

PRE_BUILD - run before all other dependencies
PRE_LINK - run after other dependencies
POST_BUILD - run after the target has been built

So I'd like to use the PRE_BUILD to get my custom command to run
before any of the dependencies for the named target are built.
Here's my sample project:

::::::::::::::
CMakeLists.txt
::::::::::::::
PROJECT(dummyproj)

ADD_LIBRARY(dummylib SHARED foo.cpp)

ADD_CUSTOM_COMMAND(
TARGET dummylib
PRE_BUILD
COMMAND cp
ARGS -v /etc/hosts ${dummyproj_BINARY_DIR})

::::::::::::::
foo.cpp
::::::::::::::
class Foo
{
int a;
int b;
};

So I'd like the 'cp' command to execute before any dependencies of
dummylib are built. Yet the output shows that the 'cp' command is
happening after foo.o and libdummylib.so are built. I'd like the 'cp'
command to happen before both of them are built. What am I doing
wrong?

$ cmake ../dummyproj
-- Check for working C compiler: gcc
-- Check for working C compiler: gcc -- works
-- Check for working CXX compiler: g++
-- Check for working CXX compiler: g++ -- works
-- Configuring done
-- Generating done
$ make
Building dependencies. cmake.depends...
cmake.depends is up-to-date
Building object file foo.o...
Building shared library libdummylib.so...
`/etc/hosts' -> `/home/rutt/dev/dummyproj/build/hosts'

Thanks,
--
Benjamin
Brad King
2004-04-19 13:53:44 UTC
Permalink
Post by Benjamin Rutt
I'm using cmake 1.8.3. I read that ADD_CUSTOM_COMMAND can be used in
The second signature adds a custom command to a target such as a
library or executable. This is useful for performing an operation
ADD_CUSTOM_COMMAND(TARGET target
PRE_BUILD | PRE_LINK | POST_BUILD
COMMAND command
[ARGS [args...]]
[COMMENT comment])
This defines a new command that will be associated with building the
specified target. When the command will happen is determined by which
PRE_BUILD - run before all other dependencies
PRE_LINK - run after other dependencies
POST_BUILD - run after the target has been built
So I'd like to use the PRE_BUILD to get my custom command to run
before any of the dependencies for the named target are built.
CMakeLists.txt
PROJECT(dummyproj)
ADD_LIBRARY(dummylib SHARED foo.cpp)
ADD_CUSTOM_COMMAND(
TARGET dummylib
PRE_BUILD
COMMAND cp
ARGS -v /etc/hosts ${dummyproj_BINARY_DIR})
foo.cpp
class Foo
{
int a;
int b;
};
So I'd like the 'cp' command to execute before any dependencies of
dummylib are built. Yet the output shows that the 'cp' command is
happening after foo.o and libdummylib.so are built. I'd like the 'cp'
command to happen before both of them are built. What am I doing
wrong?
$ cmake ../dummyproj
-- Check for working C compiler: gcc
-- Check for working C compiler: gcc -- works
-- Check for working CXX compiler: g++
-- Check for working CXX compiler: g++ -- works
-- Configuring done
-- Generating done
$ make
Building dependencies. cmake.depends...
cmake.depends is up-to-date
Building object file foo.o...
Building shared library libdummylib.so...
`/etc/hosts' -> `/home/rutt/dev/dummyproj/build/hosts'
Please send me the Makefile that is generated before the build occurs.

Thanks,
-Brad
Brad King
2004-04-19 14:11:45 UTC
Permalink
Post by Brad King
Please send me the Makefile that is generated before the build occurs.
See attached.
It looks like the PRE_BUILD rules do not work correctly for the Unix
Makefiles generator. The rules are added to the same list as the
POST_BUILD rules. Please submit this as a bug:

http://www.cmake.org/Bug

Thinking about this in more detail, I'm not sure this is possible to
implement in Makefiles. The "fix" for the bug may simply be to remove
the feature from the documentation. Instead you'll have to add this
custom command's output as an "OBJECT_DEPENDS" source-file property of
the source that needs it:

SET_SOURCE_FILES_PROPERTIES(foo.cpp PROPERTIES
OBJECT_DEPENDS "${dummyproj_BINARY_DIR}/hosts")

Then use the first signature of ADD_CUSTOM_COMMAND listed in the help.

Thanks,
-Brad
Ken Martin
2004-04-19 14:19:25 UTC
Permalink
PRE_BUILD and PRE_LINK are the same for Visual Studio 6 and all makefiles.
They both act like PRE_LINK. (Brad said they were POST_BUILD which if so we
need to change to PRE_LINK) Thanks for the reminder. We intended to modify
the rules for the Makefile to support PRE_BUILD but looking into it quickly
I'm not sure makefiles can handle PRE_BUILD. PRE_BUILD can be pretty useful
but if only Visual Studio 7 can handle it then we may have to remove it.

Thanks
Ken
Post by Benjamin Rutt
PRE_BUILD - run before all other dependencies
PRE_LINK - run after other dependencies
POST_BUILD - run after the target has been built
So I'd like to use the PRE_BUILD to get my custom command to run
before any of the dependencies for the named target are built.
CMakeLists.txt
PROJECT(dummyproj)
ADD_LIBRARY(dummylib SHARED foo.cpp)
ADD_CUSTOM_COMMAND(
TARGET dummylib
PRE_BUILD
COMMAND cp
ARGS -v /etc/hosts ${dummyproj_BINARY_DIR})
foo.cpp
class Foo
{
int a;
int b;
};
So I'd like the 'cp' command to execute before any dependencies of
dummylib are built. Yet the output shows that the 'cp' command is
happening after foo.o and libdummylib.so are built. I'd like the 'cp'
command to happen before both of them are built. What am I doing
wrong?
$ cmake ../dummyproj
-- Check for working C compiler: gcc
-- Check for working C compiler: gcc -- works
-- Check for working CXX compiler: g++
-- Check for working CXX compiler: g++ -- works
-- Configuring done
-- Generating done
$ make
Building dependencies. cmake.depends...
cmake.depends is up-to-date
Building object file foo.o...
Building shared library libdummylib.so...
`/etc/hosts' -> `/home/rutt/dev/dummyproj/build/hosts'
Bernhard Zach
2004-04-20 11:28:54 UTC
Permalink
Hi!

It seams that the generators (except the makefile-based ones) ignores the
CMAKE_STANDARD_LIBRARIES variable.

A workaround would be:
IF (CMAKE_GENERATOR MATCHES "Visual Studio 7 .NET 2003")
LINK_LIBRARIES (user32.lib kernel32.lib ws2_32.lib advapi32.lib)
ENDIF (CMAKE_GENERATOR MATCHES "Visual Studio 7 .NET 2003")

Bernhard
Brad King
2004-04-21 19:27:02 UTC
Permalink
Post by Bernhard Zach
Hi!
It seams that the generators (except the makefile-based ones) ignores the
CMAKE_STANDARD_LIBRARIES variable.
Please submit a bug report here:

http://www.cmake.org/Bug

Thanks,
-Brad

Continue reading on narkive:
Loading...