12

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!

1 Answer 1

8

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.