StuckPengiun
StuckPengiun

Reputation: 1

CMake import external library (GNU readline) using ExternalProject_Add()

I am really new (just a few weeks) to C and its bulding tools. Using the CMake documetation and some other guides I created a basic CMake project. This works as expectd. Now I wanted to use some libraries in my project (GNU readline and cJSON). The cJSON library also uses CMake so I managed to include it in my project without too much trouble. The GNU readline library on the other hand uses ninja and autotools (if I'm not mistaken). This is where I'm facing issues. I am trying to build the GNU readline library to link the static files later in my project.

In the CMake documetation I saw you could use ExternalProject_Add() for the purpose of configuring and building an external project. Just to test this I created a simple Project using CMake with ExternalProject_Add().

My test project has the following layout:

test
├── cmake-build-debug
│   ├── CMakeFiles
│   │   ├── 3.23.2
│   │   │   └── CompilerIdC
│   │   │       └── tmp
│   │   ├── CMakeTmp
│   │   ├── readline.dir
│   │   └── test.dir
│   ├── readline-prefix
│   │   ├── src
│   │   │   ├── readline-build
│   │   │   └── readline-stamp
│   │   └── tmp
│   └── Testing
│       └── Temporary
├── install_dir
└── libraries
    └── readline-8.2
        ├── doc
        ├── examples
        │   ├── autoconf
        │   └── rlfe
        ├── m4
        ├── shlib
        └── support

The library source files are located in test/libraries/readline-8.2. I want the build files to get installed in the test/install_dir.

With the following Code I manage to build the the files, but I get errors when building it.

This is the content of my CMakeLists.txt

cmake_minimum_required(VERSION 3.23)
project(test C)

set(CMAKE_C_STANDARD 11)
set(LIB_PATH ${CMAKE_SOURCE_DIR}/libraries)
set(READLINE_LIB_SRC ${LIB_PATH}/readline-8.2)
set(CONFIGURE_ARGS --enable-shared=no --enable-install-examples=no --prefix=${CMAKE_SOURCE_DIR}/install_dir)

add_executable(test main.c)

include(ExternalProject)
ExternalProject_Add(
        readline
        BUILD_IN_SOURCE TRUE
        BUILD_ALWAYS TRUE
        SOURCE_DIR ${READLINE_LIB_SRC}
        CONFIGURE_COMMAND ${READLINE_LIB_SRC}/configure ${CONFIGURE_ARGS}
        BUILD_COMMAND make
        INSTALL_COMMAND make install
        )

I also tried adding the BUILD_BYPRODUCTS option of the ExternalProject_Add, as I read that ninja could face problems detecting targets otherwise, but without success. The errors I get in the install step are:

mv: cannot stat '/home/devel/CLionProjects/test/install_dir/lib/libreadline.a': No such file or directory
mv: cannot stat '/home/devel/CLionProjects/test/install_dir/lib/libhistory.a': No such file or directory

But when I look at these directories the files exist.

The output of the build and the error message can be found here: https://gist.github.com/symb10sis/041f879ef5fbd02bcfd9200746101890 I couldn't include it in this question directly as it would get flagged as spam otherwise.

I spent hours reading the documetation, guides and questions here on stackoverflow but with my current knowledge of CMake I am stuck. What causes the build to think these files don't exist? Is my use of ExternalProject_Add() appropriate for this or am I missing something?

I would really appreciate any help :)

Upvotes: 0

Views: 330

Answers (0)

Related Questions