CMake ExternalProject_Add with GNU autoconf

219 Views Asked by At

I'm trying to build a project using cmake, which uses the libmpg123 library. I read that I could use cmake's externalproject module to automatically download and configure external libraries, but libmpg123 doesn't use cmake, it uses autotools. I'd like my directory structure to look like this

├── build
│  └── ...
├── CMakeLists.txt
├── libs
│  └── libmpg123
│     └── ...
│  └── <more libraries>
└── main.cpp

So whenever the user invokes make (after cmake), all libraries that I'm using are download into the libs folder. I only want the sources of my dependencies in the libs directory, not their object files, or anything else. That should go in the build directory when the user uses make. Currently, my CMakeLists.txt looks like this

# minimum CMake version required
cmake_minimum_required(VERSION 3.15)

project(proj VERSION 1.0 DESCRIPTION "desc")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 
include(FetchContent)
include(ExternalProject)

ExternalProject_Add(libmpg123
    GIT_REPOSITORY          "https://github.com/gypified/libmpg123.git"
    GIT_TAG                 "master"
    GIT_SHALLOW             true
    UPDATE_DISCONNECTED     true

    SOURCE_DIR              "${CMAKE_BINARY_DIR}/libmpg123-src"
    BINARY_DIR              "${CMAKE_BINARY_DIR}/libmpg123-bin"

    CONFIGURE_COMMAND       "<SOURCE_DIR>/configure"
    BUILD_COMMAND           "${MAKE}"
    INSTALL_COMMAND         "echo" # Do nothing
)
add_library(mpg123 INTERFACE IMPORTED GLOBAL)

set(SOURCES
    main.cpp
)

add_executable(${PROJECT_NAME} ${SOURCES})
 
target_link_libraries(${PROJECT_NAME}
    mpg123
)
add_dependencies(${PROJECT_NAME} libmpg123)
 
target_include_directories(${PROJECT_NAME} PRIVATE
    include
)
 

set_target_properties(${PROJECT_NAME} PROPERTIES
    CXX_STANDARD 17
    CXX_STANDARD_REQUIRED ON
)

However, this isn't working. It invokes autoconf fine, but for some reason, skips the build step, saying No build step for libmpg123, and I also believe this isn't an acceptable way of achieving what I want.

What should I change about my project?

0

There are 0 best solutions below