使用来自cmake的autotools构建库 [英] Building a library using autotools from cmake

查看:328
本文介绍了使用来自cmake的autotools构建库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次尝试cmake,如果可能,我想有一些反馈关于我做了一些问题仍然存在。



在CMakeLists。 txt的库文件夹,我创建了两个makefile目标: configure-antlr3c antlr3c 。第一个目标运行autotools配置shell脚本,第二个运行make可执行文件来构建库:

 #CMakeLists.txt in libantlr3c-3.1.3 
add_custom_target(
configure-antlr3c
$ {SHELL_EXECUTABLE} configure
WORKING_DIRECTORY $ {CMAKE_CURRENT_SOURCE_DIR}


add_custom_target(
antlr3c
$ {MAKE}
DEPENDS configure-antlr3c
WORKING_DIRECTORY $ {CMAKE_CURRENT_SOURCE_DIR}

主要的问题是 configure-antlr3c 目标总是过期即使没有发生变化也会被执行。此外,我需要在一个单独的目录(不是在我的项目的根目录)生成我的cmake makefile,以避免重写自动工具的库的Makefile ...



有任何人有这个问题(建立autotools项目与cmake)?



编辑:解决方案

/ strong>
在根CMakeLists.txt中:

  include(ExternalProject)
ExternalProject_Add $ b libantlr3c
SOURCE_DIR $ {CMAKE_CURRENT_SOURCE_DIR} /lib/libantlr3c-3.1.3
CONFIGURE_COMMAND $ {CMAKE_CURRENT_SOURCE_DIR} /lib/libantlr3c-3.1.3/configure --prefix = $ {CMAKE_CURRENT_SOURCE_DIR} / lib / libantlr3c-3.1.3
PREFIX $ {CMAKE_CURRENT_SOURCE_DIR} /lib/libantlr3c-3.1.3
BUILD_COMMAND make
BUILD_IN_SOURCE 1


解决方案

我认为你最好使用ExternalProject 功能。我想你有你的项目,并在一个子目录中有libantrl?

 项目
+ - libantlr
+ - mysrc
---- etc ----

你可以在顶层CMakeLists.txt中做这样的事情:

  cmake_minimum_required(VERSION 2.8)
project )
include(ExternalProject)
ExternalProject_Add(libantlr
SOURCE_DIR $ {CMAKE_CURRENT_SOURCE_DIR} / libantlr
CONFIGURE_COMMAND $ {CMAKE_CURRENT_SOURCE_DIR} / libantlr / configure --prefix =< INSTALL_DIR>
BUILD_COMMAND $ {MAKE})

< INSTALL_DIR& code>被扩展到像libantlr-prefix这样的东西,所以事情安装在你的构建树而不是/ usr / local,这是autotools会做没有前缀。


This is my first try with cmake and I would like to have, if possible, some feedbacks about what I did since some problems remain.

In the CMakeLists.txt of the library folder, I created two makefile targets: configure-antlr3c and antlr3c. The first target runs the autotools configuration shell script, the second one runs the make executable to build the library:

# CMakeLists.txt in libantlr3c-3.1.3 
add_custom_target(
  configure-antlr3c
  ${SHELL_EXECUTABLE} configure
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_custom_target(
  antlr3c
   ${MAKE}
   DEPENDS configure-antlr3c
   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

The main problem is thatconfigure-antlr3c target is always "out of date", so it will always be executed even if no changes happened. Moreover, I necessarily need to generate my cmake makefiles in a separate directory (not in the root directory of my project) to avoid overriding the autotools Makefile of the library...

Has anyone had this problem (building autotools projects with cmake) ? And if so, what have been your solutions ?

Thank you.

EDIT : Solution In the root CMakeLists.txt:

include(ExternalProject)
ExternalProject_Add(
  libantlr3c
  SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/libantlr3c-3.1.3
  CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/libantlr3c-3.1.3/configure --prefix=${CMAKE_CURRENT_SOURCE_DIR}/lib/libantlr3c-3.1.3
  PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/lib/libantlr3c-3.1.3
  BUILD_COMMAND make
  BUILD_IN_SOURCE 1
)

解决方案

I think that you'd be better off using the ExternalProject feature of cmake. I guess you have your project and have libantrl in a sub directory?

project
      +- libantlr
      +- mysrc
  ---- etc ----

If that's the case, you can do something like this in the top level CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
project(test)
include(ExternalProject)
ExternalProject_Add(libantlr
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libantlr
    CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/libantlr/configure --prefix=<INSTALL_DIR>
    BUILD_COMMAND ${MAKE})

The <INSTALL_DIR> is expanded to something like libantlr-prefix, so things are installed in your build tree rather than in /usr/local, which is what autotools would do without a prefix.

这篇关于使用来自cmake的autotools构建库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆