Cmake external library .a

c++, cmake, gnu-make, makefile

Solution

So it makes sense that cmake can't figure out the dependencies here: it would have to parse the makefile and find the output. You have to tell it the output someone. Nearest I can figure, the best way to do this is to use a custom_command rather than a custom target:

add_custom_command(
    OUTPUT ${CMAKE_SOURCE_DIR}/thirdparty/yaml-cpp/build/libyaml-cpp.a
    COMMAND make
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/thirdparty)
 add_custom_target(
   yaml-cpp
   DEPENDS ${CMAKE_SOURCE_DIR}/thirdparty/yaml-cpp/build/libyaml-cpp.a)
 ...
 add_dependencies(load_balancer_node yaml-cpp)
 target_link_libraries(load_balancer_node ${CMAKE_SOURCE_DIR}/thirdparty/yaml-cpp/build/libyaml-cpp.a)

I was having linker troubles though (stupid windows machine), but cmake worked and made the libraries before trying to link.

Problem

I have an external library here: `${PROJECT_SOURCE_DIR}/thirdparty/yaml-cpp/` It is made by a Makefile: `thirdparty/Makefile`. I am executing that makefile like so: ``` add_custom_target( yaml-cpp COMMAND make WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/thirdparty ) ``` I am then attempting to link the library, which builds to `thirdparty/yaml-cpp/build/libyaml-cpp.a`. This is the part that is not working: ``` target_link_libraries(load_balancer_node ${CMAKE_SOURCE_DIR}/thirdparty/yaml-cpp/build/libyaml-cpp.a) ``` I get the error: ``` Target "yaml-cpp" of type UTILITY may not be linked into another target. One may link only to STATIC or SHARED libraries, or to executables with the ENABLE_EXPORTS property set. ``` How do I execute that makefile and link the `.a` file?

Original source