Skip to content

Instantly share code, notes, and snippets.

@jlgerber
Last active December 31, 2016 23:44
Show Gist options
  • Save jlgerber/9250163d59f516664bf13393c0925c32 to your computer and use it in GitHub Desktop.
Save jlgerber/9250163d59f516664bf13393c0925c32 to your computer and use it in GitHub Desktop.
cmake - ad hoc locating of external library and includes. EG libyaml-cpp.a
#
# FIND libyaml-cpp.a
#
find_library(LIBYAML libyaml-cpp.a)
find_path(LIBYAML_INC yaml-cpp/yaml.h)
if(NOT LIBYAML)
# FATAL_ERROR will fail the CMakeLists.txt processing
message(FATAL_ERROR "Unable to find libyaml")
endif()
if(NOT LIBYAML_INC)
message(FATAL_ERROR "unable to find libyaml includes")
endif()
message(STATUS "Found LIBYAML:\n\t" ${LIBYAML})
message(STATUS "found libyaml includes:\n\t" ${LIBYAML_INC})
# We can now refer to the library path as ${LIBYAML_INC}
# eg
include_directories(${LIBYAML_INC})
# We can refer to the library as ${LIBYAML} in the target_link_libraries call
# eg
add_executable(resman ${CPPS} ${HPPS}}
target_link_libraries(resman ${LIBYAML})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment