[CMake] Invoke a target on a separate project in a generic way?

Hugo Heden hugoheden at gmail.com
Thu Dec 4 07:08:54 EST 2008


2008/12/4 Hugo Heden <hugoheden at gmail.com>:
> Good day all,
>
> I am looking for a way within a CMakeLists.txt make sure that:
>
> -- at *build* time
>
> -- cmake is invoked on a *separate* project, and then also the
> "all"-target is invoked
>
> How do I do that?
>

Before anyone else answers this: I think I should be looking at
try_compile, it seems to do what I am looking for. (I will get back
here and report, for future reference if nothing else.)

http://cmake.org/cmake/help/cmake2.6docs.html#command:try_compile

<quote>
try_compile: Try compiling some code.

  try_compile(RESULT_VAR bindir srcdir
              projectName <targetname> [CMAKE_FLAGS <Flags>]
              [OUTPUT_VARIABLE var])

Try compiling a program. In this form, srcdir should contain a
complete CMake project with a CMakeLists.txt file and all sources. The
bindir and srcdir will not be deleted after this command is run. If
<target name> is specified then build just that target otherwise the
all or ALL_BUILD target is built.
...
...
</quote>





> The following is a first rough sketch (that is not good enough, I believe):
>
> ADD_CUSTOM_TARGET(
>  build_separate_project
>  WORKING_DIRECTORY separate_project/build
>  COMMAND ${CMAKE_COMMAND} ../src
>  COMMAND ${CMAKE_BUILD_TOOL} all
> )
>
> -- The above only works for a ${CMAKE_BUILD_TOOL} that happens to
> accept a commandline that contains a target and nothing else (like
> GNU-make does).
>
> So is there a more *generic* way to, at build time, invoke cmake and
> then the "all"-target on a separate project?
>
> (The following is a bit of background: We have a project called "FOO"
> that generates source code that eventually also needs to be compiled.
> The generated source files end up in a *directory* that is known
> CMake-time, but the *filenames* are not known until *build*-time. Thus
> there is no way with in project "FOO" to create a target to compile
> the generated source-code. (Doing FILE(GLOB...) within project FOO
> will not work, because the globbing will take place at cmake-time, at
> which time there are no files there). Therefore, together with the
> generated source files we generate a CMakeLists.txt that defines a
> *separate* project called "BAR" that contains a target to compile the
> generated source code. Hence the question above -- how do I invoke the
> all target in the BAR project in a way that works for all build-tools,
> not only GNU-make?)
>
> Best Regards
>
> Hugo Heden
>


More information about the CMake mailing list