How to not make install step when building external project with cmake
Asked Answered
S

4

23

I'm building dependency project with cmake ExternalProject_Add command:

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)

but i get error:

[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.

I don't need to make install step, so my question is: how to disable it?

Spraddle answered 15/6, 2016 at 14:49 Comment(1)
Do you mean to delete " INSTALL_COMMMAND """ line? I've tried but result is the same.Spraddle
C
13

You can generate a target for the build step with STEP_TARGETS build and add dependency on this particular target. The step targets are named <external-project-name>-<step-name> so in this case the target representing the build step will be named CommonBaseProject-build.

You probably also want to exclude the CommonBaseProject from the "all" target with 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)
Cann answered 16/6, 2016 at 9:32 Comment(2)
Is there a way to later call the install step manually for the external project? For example as part of the main project's install step?Tonsure
You can add_dependencies(install CommonBaseProject-install) but that will not install the external project globally. If not changed this will install to local build dir.Missilery
F
18

You almost had it: Instead of INSTALL_COMMAND "" put something like

    INSTALL_COMMAND cmake -E echo "Skipping install step."
Frissell answered 1/10, 2016 at 20:35 Comment(2)
You could also use the true or : commands, which do nothing, i.e. INSTALL_COMMAND true. But it will still display Performing install step.Heavyset
this works! INSTALL_COMMAND "" is not enough, cmake will still run a install step.Skeptic
C
13

You can generate a target for the build step with STEP_TARGETS build and add dependency on this particular target. The step targets are named <external-project-name>-<step-name> so in this case the target representing the build step will be named CommonBaseProject-build.

You probably also want to exclude the CommonBaseProject from the "all" target with 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)
Cann answered 16/6, 2016 at 9:32 Comment(2)
Is there a way to later call the install step manually for the external project? For example as part of the main project's install step?Tonsure
You can add_dependencies(install CommonBaseProject-install) but that will not install the external project globally. If not changed this will install to local build dir.Missilery
K
0

Since at least CMake 3.10 the empty string is sufficient to suppress the install step:

Passing an empty string as the <cmd> makes the install step do nothing.

The same goes for the other stages; see the docs for more.

If you're still building with CMake <3.10 then you need to update CMake ;)

Kerek answered 7/12, 2021 at 11:3 Comment(0)
E
-1

Not relevant to your question, which it was already answered, but in my case I had the following ExternalProject_Add directive:

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

In this case cmake quits with very similar error (*** No rule to make target 'INSTALL'), but in this case it's the external project that is looking for incorrect uppercase INSTALL target: correct case is install instead. Apparently, that worked in Windows with MSVC but fails in unix operating systems.

Elson answered 6/5, 2018 at 23:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.