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

Eric Wing ewing2121 at yahoo.com
Wed, 17 Mar 2004 11:07:38 -0800 (PST)


Hi Andy,
I'm still having some problems with this. Following
your suggestion, I used a simple if block to set the
system variables. However, when the user changes the
default options, I'm having problems because options I
need to be reset are not being reset when I need them
to be. 

Here's an example: If I use the system's Lua, I need
to find the Lua executable. If not, I hard code it
using SET to the one I build. The first time I run
Cmake, and a system Lua is not found, then the
hardcoded SET is used. But, if the user changes the
option to use a system Lua, the variable to the lua
program is unchanged and still points to the hardcoded
path (which won't exist since it's not going to be
built). The FIND_PROGRAM call seems to do nothing.

Here's some of my code:

# Will set LUA_FOUND if found and set up variables
like
# LUA_LIBARIES
INCLUDE(${wxLua_SOURCE_DIR}/FindLua.cmake)

IF(LUA_FOUND)
	OPTION(USE_NATIVE_LUA_LIBRARY "Use the system's Lua
library." ON)
ELSE(LUA_FOUND)
	OPTION(USE_NATIVE_LUA_LIBRARY "Use the system's Lua
library." OFF)
ENDIF(LUA_FOUND)

IF( USE_NATIVE_LUA_LIBRARY )
	# Find the lua runtime interpreter.
	# The ${EXE_EXTENSION} will automatically determine
if a .exe is needed
	# or not based on the platform.
	FIND_PROGRAM(
		LUA_PROGRAM
		lua${EXE_EXTENSION}
		/usr/bin
		/usr/local/bin
	)
    # Go through my project directories
	SUBDIRS(Import Library Standalone)

ELSE( USE_NATIVE_LUA_LIBRARY )
    # Manually set the location of the Lua executable
	SET(LUA_PROGRAM
${wxLua_BINARY_DIR}/lua501/src/lua/Lua${EXE_EXTENSION}
CACHE PATH "Location and name of the Lua executable")
	# Go through the Lua directory and my project
directories
	SUBDIRS(lua501 Import Library Standalone)
ENDIF( USE_NATIVE_LUA_LIBRARY )


An additional problem is that when I override the
default behavior to use the system Lua after it set
the default to use the bundled Lua (after not finding
Lua on my system), my CMake doesn't seem to be
demanding that I fill in what the LUA_LIBRARIES are.

Thanks,
Eric



--- Andy Cedilnik <andy.cedilnik at kitware.com> wrote:
> Hi Eric,
> 
> If LUA has CMake files, then you are all set. If
> not, then you have to
> do some magic. Looking through LUA 5.0 source
> (Debian apt-get source
> lua50), looks like it should not take you (or
> anybody) too much time to
> convert it to CMake. Right now you have to do manual
> edit of file
> "config", but that could be substitute by some try
> compiles...
> 
> On Fri, 2004-03-12 at 18:13, Eric Wing wrote:
> > So does this mean that I can't take a
> self-standing
> > Lua/CMake project as-is and then embed it in my
> > project?
> 
> Substitute MESSAGE for whatever you want to do in
> that case. If LUA is
> found, then I guess SET(USE_SYSTEM_LUA ON).
> Otherwise
> SUBDIRS(Utilities/Lua).
> 
> In VTK, Xdmf, ITK, ParaView, ... we usually provide
> options to use
> system libraries and there are no problems. You just
> have to make sure
> the FindLUA.cmake does set the same variables as
> your alternative case
> (when you build it yourself).
> 
> 			Andy
> 
> > Substituting MESSAGE(...) for
> > SET_OPTION(USE_SYSTEM_LUA OFF or ON), will this
> cause
> > me problems? So if Lua is found, but the user
> decides
> > to use the bundled one instead, won't this cause a
> > conflict when the user hits 'c' for configure
> again
> > because the above code will be rerun and reset the
> > state back to the system Lua?
> 
>