CMakeExternalProject_Add() - 使用自定义的 CMakeLists.txt 进行构建

发布于 2024-12-06 13:00:20 字数 1295 浏览 1 评论 0原文

我正在将 lua 构建为外部项目,并且我想使用我自己的 CMakeLists.txt 而不是捆绑的 Makefile。这就是我的主 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}
    UPDATE_COMMAND ""
    PATCH_COMMAND ""
    INSTALL_COMMAND ""
)

为了使 BUILD 步骤正常工作,SOURCE_DIR 中必须有一个 CMakeLists.txt。我目前在 SOURCE_DIR 中有这个 CMakeLists.txt:

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})

这有效,但我不高兴让 lua 源文件混乱我的版本控制的 CMakeLists.txt。

有没有办法为 SOURCE_DIR 中不在的构建步骤指定自定义 CMakeLists.txt?

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}
    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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

番薯 2024-12-13 13:00:20

我自己想出来了。我现在将其用作 PATCH_COMMAND

    PATCH_COMMAND ${CMAKE_COMMAND} -E copy
      "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/lua/CMakeLists.txt" <SOURCE_DIR>/CMakeLists.txt

这使我可以在 thirdparty/lua 中拥有自定义 CMakeLists.txt,并将上游包下载到 thirdparty/lua /lua-${lua_RELEASE}。完美的!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文