1 | initial version |
To include a pre-existing static library in a project using CMake, follow these steps:
Create a directory for the static library and place the library files (.a, .lib) inside it.
In the CMakeLists.txt file of the project, use the add_library()
command to create a target for the static library. For example:
add_library(mylib STATIC IMPORTED)
IMPORTED_LOCATION
property of the target to the path of the static library file. For example:set_target_properties(mylib PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/path/to/the/static/library/libmylib.a)
target_link_libraries()
command. For example:target_link_libraries(myproject mylib)