[Cmake] Proper way to embed or nest a separate project into another project?

Andy Cedilnik andy.cedilnik at kitware.com
Fri, 12 Mar 2004 16:50:10 -0500


Hi Eric,

SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake)

OPTION(USE_SYSTEM_LUA "Use the installed LUA" OFF)
IF(USE_SYSTEM_LUA)
  FIND_PACKAGE(LUA)
ELSE(USE_SYSTEM_LUA)
  SUBDIRS(Utilities/LUA)
  SET(LUA_LIBRARIES myLua)
  SET(LUA_INCLUDE_PATH 
    "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/LUA"
    "${CMAKE_CURRENT_BINARY_DIR}/Utilities/LUA")
ENDIF(USE_SYSTEM_LUA)
    
Or something like this.

Then make sure to put FindLUA.cmake in
${CMAKE_CURRENT_SOURCE_DIR}/CMake.

BTW, CMAKE_MODULE_PATH is where FindLUA.cmake (FIND_PACKAGE(LUA)) will
be found, CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_BINARY_DIR are
exactly what they say they are.

Sounds good?

About autoconf, there is no autoconf on Windows, so the quick answer is
no. The full answer is, depending on how much work you want to do.
ParaView project includes TclTk in its repository and that works with
some trouble. 

That said, in most other cases, especially if the source is small
enough, I would write CMakeLists files. I did that for HDF5, Curl, ZLib,
Expat, LibTiff, ...

			Andy   

On Fri, 2004-03-12 at 16:40, Eric Wing wrote:
> Can somebody explain to me the "proper" or recommended
> method of embedding or nesting a separate project into
> a larger project?
> 
> More specifically, my project builds an executable
> that depends on the Lua library. Lua is small enough
> that I can include it with my project source. However,
> Lua may already be preinstalled on some systems. So in
> a nut shell, I would like to detect for Lua and link
> if preinstalled, otherwise build and link to the one
> that comes with my project (or give the user the
> option).
> 
> So to start with, Lua doesn't have a built in CMake
> build project. I suppose I could add one fairly easily
> because it's a pretty simple build system. I'm looking
> at embedding Lua in several other projects I have too,
> so I think it would be in my interest to write a
> standalone CMake build system for Lua rather than
> build one specialized integrated system. In this case,
> each of my projects will need to somehow interface
> with that Lua project. 
> 
> Can somebody explain to me how to actually do this?
> 
> And out of curiosity, hypothetically, if I had some
> other external project that used autoconf and wasn't
> so easy to build a CMake project for, would it be
> possible to leverage their native build system
> directly?