0

In my cmake project I need to integrate a library that uses configure and make for building. I was trying to use ExternalProject_Add, however cmake does not call the CONFIGURE step (anymore - I could swear it worked earlier).

# copy folder, because ExternalProject_Add apparently does not by itself
file(COPY ${CMAKE_SOURCE_DIR}/contrib/vendor/driver/libmyhardware
     DESTINATION ${CMAKE_BINARY_DIR}/contrib/vendor/driver)

include(ExternalProject)
ExternalProject_Add(
  myhardware1
  SOURCE_DIR ${CMAKE_BINARY_DIR}/contrib/vendor/driver/libmyhardware
  DOWNLOAD_COMMAND ""
  CONFIGURE_COMMAND
    COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/contrib/vendor/driver/libmyhardware/../build
    COMMAND make
    COMMAND make install
  BUILD_COMMAND ""
  INSTALL_COMMAND ""
  BUILD_IN_SOURCE 1
)

set(ENV{PKG_CONFIG_PATH} "${CMAKE_BINARY_DIR}/contrib/vendor/driver/build/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
find_package(PkgConfig REQUIRED)
pkg_check_modules(MYHW REQUIRED IMPORTED_TARGET myhardware)



PkgConfig::MYHW


target_link_libraries(main PRIVATE PkgConfig::MYHW)

After trying for hours, I am really out of ideas. Do I have to make pkg_check_modules dependent on ExternalProject_Add(myhardware1 somehow? I have already tried with BUILD_BYPRODUCTS, but not luck.

btw- the reason I am using find_package(PkgConfig REQUIRED) and pkg_check_modules(MYHW REQUIRED IMPORTED_TARGET myhardware) is because the library makes a .pc file available.

(of course, when I manually run configure and make, everything works)

juwalter
  • 11,472
  • 5
  • 19
  • 18
  • All COMMANDs specified in the `ExternalProject_Add` are executed when the main project is being **built**. But `pkg_check_modules` reads a `.pc` file at the **configuration** stage. See e.g. [that question](https://stackoverflow.com/questions/37553280/how-to-build-cmake-externalproject-while-configurating-main-one) about building external project at the configuration time. – Tsyvarev Apr 10 '23 at 19:04

0 Answers0