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

Andy Cedilnik andy.cedilnik at kitware.com
Thu, 18 Mar 2004 08:02:24 -0500


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.