使用cmake构建外部项目时如何不进行安装步骤

时间:2016-06-15 14:49:16

标签: cmake dependencies install project

我正在使用cmake ExternalProject_Add命令构建依赖项目:

include(ExternalProject)
...
set(COMMON_BASE_PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../CommonBase)

ExternalProject_Add(CommonBaseProject
  SOURCE_DIR ${COMMON_BASE_PROJECT_DIR}
  BINARY_DIR ${COMMON_BASE_PROJECT_DIR}/build
  INSTALL_COMMMAND ""
)   

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${COMMON_BASE_PROJECT_DIR}/include)

add_library(
    ${LIBRARY_NAME}
    SHARED
    ${SRC_FILES}
    ${INCLUDE_FILES}
)

target_link_libraries (Bios ${COMMON_BASE_PROJECT_DIR}/build/libCommonBase.dll)
add_dependencies(Bios CommonBaseProject)

但我收到错误:

[100%] Linking CXX shared library libCommonBase.dll
[100%] Built target CommonBase
[ 50%] Performing install step for 'CommonBaseProject'
make[3]: *** No rule to make target 'install'.  Stop.

我不需要进行安装步骤,所以我的问题是:如何禁用它?

3 个答案:

答案 0 :(得分:9)

您可以使用STEP_TARGETS build为构建步骤生成目标,并为此特定目标添加依赖项。步骤目标名为<external-project-name>-<step-name>,因此在这种情况下,表示构建步骤的目标将命名为CommonBaseProject-build

您可能还想从&#34; all&#34;中排除CommonBaseProject。目标为EXCLUDE_FROM_ALL TRUE

ExternalProject_Add(CommonBaseProject
  SOURCE_DIR ${COMMON_BASE_PROJECT_DIR}
  BINARY_DIR ${COMMON_BASE_PROJECT_DIR}/build
  STEP_TARGETS build
  EXCLUDE_FROM_ALL TRUE
)

add_dependencies(Bios CommonBaseProject-build)

答案 1 :(得分:6)

你几乎拥有它:而不是INSTALL_COMMAND ""放置像

这样的东西
    INSTALL_COMMAND cmake -E echo "Skipping install step."

答案 2 :(得分:0)

与你已经回答的问题无关,但就我而言,我有以下ExternalProject_Add指令:

ExternalProject_Add(external_project
    # [...]
    # Override build/install command
    BUILD_COMMAND ""
    INSTALL_COMMAND
        "${CMAKE_COMMAND}"
        --build .
        --target INSTALL    # Wrong casing for "install" target
       --config ${CMAKE_BUILD_TYPE}
)

在这种情况下,cmake退出的错误非常相似(*** No rule to make target 'INSTALL'),但在这种情况下,它正在寻找不正确的大写INSTALL目标的外部项目:正确的情况是{{ 1}}而不是。显然,这在Windows中使用MSVC但在unix操作系统中失败。