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...
. ├── 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.
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.
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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With