0

I am using ncurses in a project and would like the project to pull ncurses from git and to be used in the project. The external project is set up like so:

ExternalProject_Add(ncurses-extern
    EXCLUDE_FROM_ALL TRUE
    INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ncurses
    GIT_REPOSITORY https://github.com/mirror/ncurses.git
    GIT_TAG master
    UPDATE_COMMAND ""
    CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix <INSTALL_DIR> --with-shared --without-debug --without-manpages --includedir <INSTALL_DIR>/include
    BUILD_COMMAND make -C <BINARY_DIR>
    INSTALL_COMMAND make -C <BINARY_DIR> install
)

then I would like to create a interface library to make linking targets to it simpler like so:

add_library(ncurses-lib INTERFACE)
add_dependencies(ncurses-lib ncurses-extern)
target_link_libraries(ncurses-lib INTERFACE ${CMAKE_SOURCE_DIR}/libs/ncurses/lib/libncurses.so)
target_include_directories(ncurses-lib INTERFACE ${CMAKE_SOURCE_DIR}/libs/ncurses/include)

I would think as ncurses-lib depends on ncurses-extern cmake would build ncurses-extern then try to make the library but it doesn't.

If ncurses-extern has been built and installed already then the cmake works, however if it cannot find libncurses.so (because the external project hasn't been run yet), it fails to build with the error:

ninja: error: '../libs/ncurses/lib/libncurses.so', needed by 'main', missing and no known rule to make it

How can I make it so the target_link_libraries only runs after the external project.

Thomas Briggs
  • 119
  • 1
  • 11
  • Please, add to the question post the **exact** error message. Without it the description "if it cannot find libncurses.so ..., it fails to build" is quite unclear. – Tsyvarev May 28 '22 at 16:56
  • When use Ninja as a built tool, you should carefully specify BUILD_BYPRODUCTS, like in [that answer](https://stackoverflow.com/a/43714505/3440745). – Tsyvarev May 28 '22 at 17:17

0 Answers0