Using External Project to built and add non-cmake library to project

Hello I’m currently trying to build a library using CMake and I would
like to add a specific library to it.

My goal is to be able to bundle the sources with my library source and
make them build alongside my own.

I found out about ExternalProject but I have a hard time understanding
the way to use it.

My current project file is organised as such:


.

./include

./src

./external

./external/libA/

./external/libA/CMakeLists.txt

./external/libB/

./CMakeLists.txt

libA is built using Cmake so I had not much trouble adding it.

However libB using plain makefiles, and to built it I roughly must use
the following command:


make -f <specific make file>

I tried the following:

ExternalProject_Add(libB
     PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libB
     SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${LIBB_DIR}
     BUILD_COMMAND make -f Makefile.linux.alt
     BUILD_IN_SOURCE 1
)

Once I tried running make I get the following:


CMake Error: The source directory "LIBD_DIR" does not appear to contain 
CMakeLists.txt.

Which sounds weird to me because that is exactly what I wanted to avoid
using in the first place.

Can someone explain me what am I doing wrong ?

You probably want to pass CONFIGURE_COMMAND and INSTALL_COMMAND parameters as empty strings to disable them.

It worked!!!

Thanks you

I just noticed a thing. While my lib build without error, while checking the built mylib.a I noticed that none of libB.a symbols are available.

In order to link the built libB to mine I used the following command:


ExternalProject_Get_property(LIBB SOURCE_DIR)
target_link_libraries(${PROJECT_NAME} PUBLIC ${SOURCE_DIR}/libB.a)
target_include_directories(${PROJECT_NAME} PUBLIC ${SOURCE_DIR}/liB_include)

using nm -gC mylib.a | grep <specific libB symbols> none are displayed.

I also noticed that building a program that includes mylib result in a


make[2]: *** No rule to build target « mylib/${SOURCE_DIR}/libB.a », required for « project ». Stopping.

Any idea what I’ve overlooked ?

mylib.a looks to be an archive library so it doesn’t have a linking step. None of the symbols of libB would be expected to show up. If you made mylib a shared library then there is usually a linking step and you would see the libB symbols. I don’t think CMake supports combining archive files.

The thing is some of the features of mylib.a must uses features from libB.a.

Maybe I’m doing this wrong, it’s my first “big” project and library.

The thing is some of the features of mylib.a must uses features from libB.a.

Maybe I’m doing this wrong, it’s my first “big” project and library.