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

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


Hello again,
I'm still trying to get this right. As you suggested,
I added the keyword FORCE to my SET commands. This did
allow me to override things, but now I'm having the
opposite problem of overriding my overrides.

So consider the following example:


IF( USE_NATIVE_LUA_LIBRARY )
#SET(LUA_PROGRAM "LUA_PROGRAM-NOTFOUND" CACHE PATH
"Location and name of Lua executable" FORCE)
	FIND_PROGRAM(
		LUA_PROGRAM
		lua${EXE_EXTENSION}
		/usr/bin
		/usr/local/bin
	)

ELSE( USE_NATIVE_LUA_LIBRARY )
	SET(LUA_PROGRAM
${wxLua_BINARY_DIR}/lua501/src/lua/Lua${EXE_EXTENSION}
CACHE PATH "Location and name of the Lua executable"
FORCE)

ENDIF( USE_NATIVE_LUA_LIBRARY )


So in the above example, presuming the default action
is not to use the Native (System) Lua, then I follow
the ELSE branch and manually SET the path. My problem
is now that if the user wants to change the OPTION to
use the native Lua, the IF branch is taken, but the
LUA_PROGRAM still is set to what I had set it to
before. If I uncomment the line that FORCE sets it to
NOT_FOUND, the problem is that the FIND_PROGRAM
command will not override the NOT_FOUND and the
FIND_PROGRAM call does notthing.

Is there a way to correct this?

Thanks,
Eric



--- Andy Cedilnik <andy.cedilnik at kitware.com> wrote:
> Hi Eric,
> 
> You can use SET force...
> 
> SET(LUA_PROGRAM
> 
>
${wxLua_BINARY_DIR}/lua501/src/lua/Lua${EXE_EXTENSION}
>  CACHE PATH "Location and name of the Lua
> executable" FORCE)
> 
> If you want CMake to complain about LUA_LIBRARIES
> not being set, you can
> do either of two things:
> 
> IF(NOT LUA_LIBRARIES)
>   MESSAGE(SEND_ERROR "LUA libraries not set")
> ENDIF(NOT LUA_LIBRARIES)
> 
> The other option is that you start using them:
> 
> TARGET_LINK_LIBRARIES(myexec ${LUA_LIBRARIES})
> 
> If LUA_LIBRARIES are set to LUA_LIBRARIES-NOTFOUND
> (default when doing
> FIND_*), then CMake will complain.
> 
> 			Andy
> 
> On Wed, 2004-03-17 at 14:07, Eric Wing wrote:
> > 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.
> 
>