Reputation: 18113
I'm on Windows 10 64 bit verson 1703. Recently I wanted to build Tesseract-OCR library from scratch for learning purposes. Along the way I had to build several other libraries put them into a single folder and named it "myLibrary" (C:/myLibrary) and set it in the Windows path variable. Even though the other libraries built successful I still had difficulties with CMake finding the libraries even when 'C:/myLibrary' is in the path. Is it that every time a new library is added a specific project's CMakeLists.txt file has to be modified to see the library? or can it be assumed that CMake has features to find the libraries as long they are in the path? Is it enough to just set 'C:/myLibrary' in the path or should I add the 'bin' and 'lib' folders of each compiled libraries for them to be found by CMake?
Upvotes: 1
Views: 14040
Reputation: 5241
Windows PATH won't help you detect libraries in CMake. If that even works at all, it's not by design and probably very error prone. In CMake, the best way to add libraries via LIST
manually. e.g.
target_link_libraries(${TARGET} PRIVATE
"${LIB_PATH}/foo.lib"
"${LIB_PATH}/baz.lib"
"${ANOTHER_LIB_PATH}/buzz.lib"
...
}
You can GLOB
for libraries in a path as well, but this is not encouraged as you would need to rerun CMake manually to pick up any new library. GLOB
can't detect new libraries on its own, but suppose you don't mind that:
file(GLOB LIBS "${LIB_PATH}/lib*.dll")
target_link_libraries(${TARGET} PRIVATE ${LIBS})
Another important thing to remember is you shouldn't rely on system specified paths for CMake, you need to specify the location with set
before target_link_libraries
e.g.
set(LIB_PATH "C:/myLibrary")
Upvotes: 2