[CMake] Static lib in project
Eric Noulard
eric.noulard at gmail.com
Sat Jan 14 17:42:30 EST 2012
2012/1/14 Matthias Fulz <mfulz at olznet.de>:
> Hi,
>
> could anybody give me a hint or an example on how to
> use a static lib inside a project?
>
> I need to create a static lib, which is only used inside
> a project for different executables.
>
> Let's say a project like the following:
>
> src
> static_lib
> lib.cpp
> lib.hpp
> executable1
> main.cpp
> executable2
> main.cpp
>
> The lib should be static and used only inside this project.
src/CMakeList.txt
add_subdirectory(static_lib)
add_subdirectory(executable1)
add_subdirectory(executable2)
src/static_lib/CMakeLists.txt
add_library(InternalUse STATIC lib.cpp lib.hpp)
src/executable1/CMakeLists.txt
add_executable(exe1 main.cpp)
target_link_libraries(exe1 InternalUse)
install(TARGETS exe1 DESTINATION bin)
src/executable2/CMakeLists.txt
add_executable(exe2 main.cpp)
target_link_libraries(exe2 InternalUse)
install(TARGETS exe2 DESTINATION bin)
should work as expected.
"only inside this project" would mean
that you shouldn't install this library.
--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
More information about the CMake
mailing list