0

I'm trying to download, build and link external libraries using ExternalProject_Add(). Currently I'm trying to import Volk library https://github.com/zeux/volk with it. I got to the point, where I can download and build the library without any problem, but I can't link to it, because the library isn't downloaded and built yet (throws an ninja error). Before ExternalProject_Add() I used find_package(). It worked great, but it was processed at configuration stage and I don't have access to the library files until build stage. The Volk library also has dependecy on Vulkan and I have no idea on how to provide Vulkan lib files to it. It was all done automatically using the VolkConfig.cmake script.

My current code for the ExternalProject_Add():

ExternalProject_Add(
    VolkDownload
    GIT_REPOSITORY https://github.com/zeux/volk.git
    GIT_TAG b3bc21e584f97400b6884cb2a541a56c6a5ddba3
    PREFIX ${PROJECT_SOURCE_DIR}/External/VolkDownload
    CONFIGURE_COMMAND cmake ../VolkDownload -DVOLK_INSTALL=ON
    BUILD_COMMAND cmake --build . --config Release
    INSTALL_COMMAND cmake --install . --prefix ../../install
)

Externalproject_Get_Property(VolkDownload binary_dir)

set(VOLK_INCLUDE_DIR ${binary_dir}/../install/include)
set(VOLK_LIB_DIR ${binary_dir}/../install/lib)

add_library(volk STATIC IMPORTED)
set_target_properties(volk PROPERTIES IMPORTED_LOCATION ${VOLK_LIB_DIR}/volk.lib)
add_dependencies(volk VolkDownload)

add_library(testLib SHARED ${SRC_FILES})

add_dependencies(testLib volk)

target_include_directories(testLib PRIVATE ${VOLK_INCLUDE_DIR})
target_link_libraries(testLib volk)

The error I get:

[build] ninja: error: 'VolkDownload/src/install/lib/volk.lib', needed by 'bin/testLib.dll', missing and no known rule to make it

My question is how can I properly download and build the external libraries (in this case Volk) using ExternalProject_Add() and how to properly create library targets, which I can easily link to?

xarxarx
  • 21
  • 5
  • The code looks reasonable. "but I can't link to it, because the library isn't downloaded and built yet." - Do you got a error message? Include it to the question post. – Tsyvarev Aug 31 '23 at 23:04
  • Thank you for the notice. Edited the question. – xarxarx Aug 31 '23 at 23:10
  • So, it is ninja error. You need to specify the library file as `BUILD_BYPRODUCTS` for `ExternalProject_Add`. – Tsyvarev Aug 31 '23 at 23:17
  • Maybe it helped a bit, but I don't see any difference. Still the same error. It looks like the CMake is trying to link the Volk to the testLib before Volk is even built. Is there any way to add dependency for the Volk library? – xarxarx Aug 31 '23 at 23:50
  • "It looks like the CMake is trying to link the Volk to the testLib before Volk is even built." - 1. It is not CMake who emit the error, it is Ninja. 2. Ninja prints `... no known rule to make it`, which means that Ninja finds no rule which is marked as creator for that file. Are you sure that you correctly specify path to the library in BUILD_BYPRODUCTS? May be, `INSTALL_BYPRODUCTS` will be a better option, as the file is created during the installation. E.g. `INSTALL_BYPRODUCTS /../../install/lib/volk.lib`. (CMake will substitute `` automatically). – Tsyvarev Sep 01 '23 at 07:36
  • There is something strange in the installation paths: You specify `--prefix=/../../install` with **two** "go to the upper directory", but `VOLK_LIB_DIR` variable is defined as `${binary_dir}/../install/lib`, with **single** "go to the upper directory". Are you sure that the library is **actually** created by `ExternalProject_Add` in the place which you specify as `IMPORTED_LOCATION`? – Tsyvarev Sep 01 '23 at 07:45
  • `ExternalProject_Add` supports specification of `INSTALL_DIR` path, which you could refer to both in the `ExternalProject_Add` and after it. E.g., inside `ExternalProject_Add` command you could write `INSTALL_DIR ${PROJECT_SOURCE_DIR}/External/VolkDownload/install`, in the `INSTALL_COMMAND` write `cmake --install . --prefix `, and specify `INSTALL_BYPRODUCTS` as `/lib/volk.lib`. After the `ExternalProject_Add` you could extract install directory using `Externalproject_Get_Property(VolkDownload install_dir)`. – Tsyvarev Sep 01 '23 at 07:59
  • external project does not handle linkage "across" the "internal/external" boundary – starball Sep 01 '23 at 08:44
  • Thank you so much for your help. Finally got it working. I accidentally wrote a dot in the directory path, which broke it all. :D – xarxarx Sep 01 '23 at 15:38

0 Answers0