一旦编译了相应的外部项目,如何找到包?

时间:2011-06-03 13:49:18

标签: build-automation cmake

有没有办法在编译外部项目后才能找到一个包,因为一旦这个外部项目被编译就会创建要查找的包?

现在,我有:

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
)

find_library(
  antlr3c
  libantlr3c.a
  HINTS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libantlr3c-3.1.3
)

当然失败了。

谢谢。

1 个答案:

答案 0 :(得分:3)

由于您可以控制库的创建位置,因此无需使用find_library。您可以直接使用link_directories。您可能希望include目录中的相同内容将include路径添加到编译行。像这样的东西应该这样做:

include(ExternalProject)
set(antlr3c_LIBRARIES
    ${CMAKE_CURRENT_SOURCE_DIR}/lib/libantlr3c-3.1.3)
set(antlr3c_INCLUDE_DIRS
    ${CMAKE_CURRENT_SOURCE_DIR}/lib/libantlr3c-3.1.3/include)
externalproject_add(
  libantlr3c
  ....
)
link_directories(${antlr3c_LIBRARIES})
include_directories(${antlr3c_INCLUDE_DIRS})
add_executable(my_exe ${SOURCES})
target_link_libraries(my_exe antlr) # or antlr3c or whatever -lantlr is needed