Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile other external libraries (without CMakeLists.txt) with CMake

short -- Is it possible to build a external binary/library out of a project with CMake, when the binary/library only has a makefile given?

So you have your own project, a bunch of CMakeLists.txt in your src-tree and this external library with its source-files. Your sources depend on this library and some binaries/libraries want to link against it. How would one compile this external library if it has only a makefile or Visual Studio project file and no given CMakeLists.txt? Is there a chance to call configure/make out of CMake? Or run an batch-compile with VS under Windows? Or anything else?

Thanks for your help with this one...

like image 913
Patrik Avatar asked Aug 15 '10 20:08

Patrik


People also ask

Where can I find external libraries in cmakelists?

. ├── CMakeLists.txt ├── external │ └── CMakeLists.txt └── src ├── CMakeLists.txt └── main.cpp external directory will contain external libraries (like cli11, spdlog, etc.) which should be available in the src directory.

What are the cmakelists files in my project?

Here the myproject.h, myproject.cpp are the source code for your application that will use TBB and loadtbb.cpp is a unit test to check that you have loaded TBB correctly. The CMakeLists.txt files in each directory are for CMake to know how to handle the files in each directory.

What if a library is not built using Cmake?

This opens up a question: what if the library is not built using CMake, or maybe it is built using CMake, but the maintainer did not take care to enable proper installation? As an example, Boost is a common library that is not built using CMake, so in theory, we cannot depend on there being targets provided for it. There are two ways around this:

What is liblibminisat in CMake?

This CMakeLists.txt will build a static library and the two binaries that depend on it. However, if we build this project on Linux, the library will be named liblibminisat.a, because CMake knows that library files on Linux are prefixed with lib as a convention, and it tries to be helpful.


1 Answers

It sounds like you want CMake's external project. I have worked with it quite extensively when developing the Titan build system, and it provides a way of managing multiple out of source builds. You can include ExternalProject, and then something like the following would build the project:

ExternalProject_Add(Qt
   DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}
   URL ${qt_file}
   UPDATE_COMMAND ""
   SOURCE_DIR ${qt_source}
   BUILD_IN_SOURCE 1
   CONFIGURE_COMMAND ${qt_configure}
   BUILD_COMMAND ${qt_build}
   INSTALL_COMMAND "${qt_install}"
   )

There is an article about external projects in the October 2009 issue of the source too. Using external project you can call any make commands available on the host system, we build Qt using their supplied configure command on Windows, Mac and Linux.

like image 150
Marcus D. Hanwell Avatar answered Oct 27 '22 09:10

Marcus D. Hanwell