Skip to content

This is a working example project to demonstrate how to use an external library (libfoo) within a cmake project.

License

Notifications You must be signed in to change notification settings

a-kuntz/cmake-external-lib-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cmake external lib example

This is a working example project to demonstrate how to define a cmake target for a non-cmake external library.

scenario

Our main file src/main.cpp is part of a cmake project, defined in CMakeLists.txt. It depends on a non-cmake library libfoo. We compile libfoo with a simple makefile foo/Makefile. To use libfoo in any project, the compiler and linker need to find the header file, and the archive file libfoo.a.

We would like to have a cmake target Foo::Foo for libfoo to make it accessible like any other cmake based library. This target is defined in cmake/FindFoo.cmake, which is used by cmake to find libfoo. See line find_package(Foo REQUIRED) of CMakeLists.txt.

build instructions

The easiest way to build the example is to simply run build.sh which contains the instructions below.

Build dependency libfoo via makefile located in folder foo.

make -C foo

Compile src/main.cpp using cmake. libfoo is found through FindFoo.cmake.

cmake -Bbuild -H.
make -C build

Invoke the built executable.

./build/main

Have fun exploring the example code.

references

About

This is a working example project to demonstrate how to use an external library (libfoo) within a cmake project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published