Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake -- let a subdirectory use its own Makefile

I have a project that primarily uses CMake.

However, there is a subdirectory from a 3rd party / legacy library. It has a Makefile that will compile itself into a 3rd_party.a library file.

Can my own CMakeLists.txt manage to call that Makefile, generate its 3rd_party.a library, and let my code link to it? I don't want to adapt its legacy Makefile into CMakeLists.txt

├── my_source_folder_1
├── my_source_folder_2
├── CMakeLists.txt
├── 3rd_party
│   ├── 3rd_party_source
│   ├── 3rd_party_make
│   |   ├── Makefile

Thanks!

like image 680
CuriousMind Avatar asked May 10 '15 01:05

CuriousMind


1 Answers

Related: http://www.cmake.org/pipermail/cmake/2010-November/040631.html

From the link above, it appears that you can use a special command to outline how CMake should make the target:

add_custom_target(
   extern_lib
   COMMAND make
   WORKING_DIRECTORY full_path to where Makefile is located
)
add_executable(myexecutable myexcutable.c)
target_link_libraries(myexecutable full_path_to_generated_library)
add_dependencies(myexecutable extern_lib)

This should be enough to get you off the ground.

like image 69
Cinch Avatar answered Sep 24 '22 22:09

Cinch