[CMake] custom build

Chuck Atkins chuck.atkins at kitware.com
Fri Jul 29 11:42:16 EDT 2016


Hi Lev,

However, the target builds only if I explicitly say 'make foo_sqlite'. So
> far
> so good. Is there any way I can make it build if I just say 'make'?
>

See the add_custom_target documentation for the ALL option,
https://cmake.org/cmake/help/v3.6/command/add_custom_target.html


And, there are more then one sqlite database to build, how can I make the
> rule to be generic? Can I say *.sql, *.sqlite?
>

The problem with using wild cards is that they won't be sensitive to make
detecting file changes.  For example, if you add a new file then CMake
won't automatically re-run because the *.sql statement hasn't changed.  You
should also be able to replace the separate custom_target and
custom_command with a single custom_target:

add_custom_target(foo ALL sqlite3 -init foo.sql foo.sqlite)

You could also wrap the call in a macro for convience:

macro(add_sqlite_target name)
  add_custom_target(${name} ALL sqlite3 -init
${CMAKE_CURRENT_SOURCE_DIR}/${name}.sql
${CMAKE_CURRENT_BINARY_DIR}/${name}.sqlite BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/${name}.sqlite SOURCES ${name}.sql)
endmacro()

add_sqlite_target(fooA)
add_sqlite_target(fooB)
add_sqlite_target(fooC)
add_sqlite_target(fooD)

Note the addition of BYPRODUCTS and SOURCES.  This adds additional
dependency information if you decided to either a) make other targets that
consume the database or b) have other targets that produce the source code.

- Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160729/88c82cc6/attachment.html>


More information about the CMake mailing list