I am trying to build a 3rd-party dependency using ExternalProject_Add
(in this case libpqxx
):
ExternalProject_Add(libpqxx_ext
GIT_REPOSITORY
https://github.com/jtv/libpqxx
GIT_TAG
tags/7.4.1
GIT_SHALLOW
true
PREFIX
ext
BINARY_DIR
build
CMAKE_ARGS
-DSKIP_BUILD_TEST=on
INSTALL_COMMAND
""
BUILD_ALWAYS
OFF
)
Once this step completes, the libpqxx artifacts I then need to use in my project are located at:
- header files:
${CMAKE_CURRENT_BINARY_DIR}/ext/src/libpqxx_ext/include
- static library:
${CMAKE_CURRENT_BINARY_DIR}/build/src/libpqxx.a
Use the results in my project:
How do I make these artifacts available to my project?
I have tried the following:
set(LIB_PQXX_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/ext/src/libpqxx_ext)
set(LIB_PQXX_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/build/src)
add_library(libpqxx STATIC IMPORTED GLOBAL)
set_property(TARGET libpqxx APPEND PROPERTY IMPORTED_LOCATION ${LIB_PQXX_BIN_DIR}/libpqxx.a)
set_property(TARGET libpqxx APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${LIB_PQXX_SRC_DIR}/include)
set_property(TARGET libpqxx APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PostgreSQL_LIBRARIES})
add_dependencies(libpqxx libpqxx_ext)
This doesn't work because at configure time the ${LIB_PQXX_SRC_DIR}/include
doesn't exist yet.
CMake Error in
foo/CMakeLists.txt
: Imported target "libpqxx
" includes non-existent path"/home/steve/src/foo/build/3rd-party/pqxx/ext/src/libpqxx_ext/include"
in its
INTERFACE_INCLUDE_DIRECTORIES
. Possible reasons include:
The path was deleted, renamed, or moved to another location.
An install or uninstall procedure did not complete successfully.
The installation package was faulty and references files it does not provide.
Adding add_dependencies
to tell cmake that libpqxx_ext
needs to be built before libpqxx
doesn't work.
Note that if I remove libpqxx
altogether, and then build my project (so that libpqxx_ext
is built), and then add it, now everything works, because the ExternalProject_Add
step has run... but obviously this breaks when I do a clean checkout, so it's not viable.
I also tried to tell cmake that the include dir is generated, but that had no effect
set_source_files_properties(${LIB_PQXX_SRC_DIR}/include PROPERTIES GENERATED TRUE)
Questions:
Is my use of
add_library(libpqxx STATIC IMPORTED GLOBAL)
to import the artifacts the correct / recommended way of using the result ofExternalProject_Add
?If it is, how can I tell cmake that
${LIB_PQXX_SRC_DIR}/include
is a generated directory?If it is not, what is the recommended way of making the result of
ExternalProject_Add
available to my project?