I am building lua as an external project and I want to use my own CMakeLists.txt instead of the bundled Makefile. This is what I have in my main CMakeLists.txt:
include(ExternalProject)
set(lua_RELEASE 5.1.4)
ExternalProject_Add(
lua-${lua_RELEASE}
URL http://www.lua.org/ftp/lua-${lua_RELEASE}.tar.gz
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/download/lua-${lua_RELEASE}
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/lua/lua-${lua_RELEASE}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/build/lua-${lua_RELEASE}开发者_JAVA百科
UPDATE_COMMAND ""
PATCH_COMMAND ""
INSTALL_COMMAND ""
)
For the BUILD step to work there must be a CMakeLists.txt in the SOURCE_DIR. I have this CMakeLists.txt in the SOURCE_DIR at the moment:
cmake_minimum_required(VERSION 2.8)
project(lua)
set(lua_library
lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c
ltable.c ltm.c lundump.c lvm.c lzio.c
lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c
ltablib.c lstrlib.c loadlib.c linit.c
)
foreach(s ${lua_library})
set(lua_LIBRARY ${lua_LIBRARY} src/${s})
endforeach()
add_definitions(-DLUA_ANSI=1)
add_library(lua STATIC ${lua_LIBRARY})
This works but I am not happy about having the lua source files clutter my version controlled CMakeLists.txt.
Is there any way to specify a custom CMakeLists.txt for the build step that is not in SOURCE_DIR?
I figured it out myself. I am now using this as the PATCH_COMMAND
:
PATCH_COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/lua/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt
This allows me to have my custom CMakeLists.txt in thirdparty/lua
and the upstream package is downloaded to thirdparty/lua/lua-${lua_RELEASE}
. Perfect!
精彩评论