In my project I ship a compiled static library foo.lib I want to link to from my main.cpp executable. I want to import the compiled library as an IMPORTED library.
File structure:
external/foo/lib/foo.lib
external/foo/include/foo.h
external/CMakeLists.txt
src/CMakeLists.txt
src/main.cpp
CMakeList.txt
external/CMakeLists.txt:
add_library(foolib STATIC IMPORTED GLOBAL)
set_target_properties(foolib PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/foo/lib/"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/foo/include/"
)
Currently when I try to compile I get the error:
could not open '../../../external/foo/lib/': no such file or directory
so maybe using ${CMAKE_CURRENT_LIST_DIR}
is not the correct approach.
- What cmake variable should I use to define the path of the library?
- Is this approach correct, or should I write a FindFoo.cmake module to locate this library (even if within my project)?
- Can I use
target_include_directories
instead of settingINTERFACE_INCLUDE_DIRECTORIES
directly?