Reputation: 31
I'm working on a main project, having several third party libraries. My goal is to import all of these as imported target for clarity sake, but I can't get one to work. It's basically a set of static libraries (.lib / lib.a) and their headers.
For the sake of discussion, Main is the main target, Third is the imported third party.
I manage to generate a proper Visual Studio solution on Windows, but things are not working as intended on Linux. When building the solution, I end up with this error:
"No rule to make target 'Third-NOTFOUND', needed by '../Bin/Main'"
Here are some code snippets from my CMakeLists.txt's.
Main's CMakeLists.txt:
project(Main)
[...]
add_subdirectory(ThirdParty/Third)
set_property(TARGET Third PROPERTY FOLDER "thirdparty")
[...]
add_executable(Main ${SOURCES})
target_link_libraries(Main PRIVATE Third)
Third's CMakeLists.txt:
project(Third)
[...]
# Helper function
function(append_lib target lib_debug_dir lib_release_dir name)
set_property(TARGET ${target} APPEND PROPERTY IMPORTED_LOCATION_DEBUG "${lib_debug_dir}/${LIB_NAME}")
set_property(TARGET ${target} APPEND PROPERTY IMPORTED_LOCATION_RELEASE "${lib_release_dir}/${LIB_NAME}")
endfunction()
[...]
add_library(Third STATIC IMPORTED GLOBAL)
set_property(TARGET Third APPEND PROPERTY PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${INCLUDE_DIR}")
append_lib(Third ${LIB_DIR_DEBUG} ${LIB_DIR_RELEASE} libMyLib1.a)
NB: The code for Linux and Windows are the same, except the name of the static library it self (MyLib1.lib replaces libMyLib1.a)
What am I doing wrong? Thanks :)
Upvotes: 1
Views: 2463
Reputation: 31
I've finally managed to get what I wanted, even though I could not find a way to get a method that works on both systems.
On Windows, I stick to what I described in my question.
On Linux however, I've found some workaround. I'm importing one libraries as IMPORTED_LOCATION and all the others as INTERFACE_LINK_LIBRARIES. That's not great, but if I don't specify an imported location, I get the Third-NOTFOUND error.
As Antonio suggested, I use CMAKE_BUILD_TYPE to link different libraries on different configuration.
Thank you both for you help!
Upvotes: 2
Reputation: 20266
If it works in Windows and not in Unix, that's very likely because of path casing: namely, you have inconsistent use of uppercase and lowercase characters in your folder names. This is tolerated in Windows, but ruthlessly punished in Unix :)
Solution: Check how you have spelled thirdparty
all around your project (Here I see thirdparty
and ThirdParty
).
Upvotes: 0