I have a big project where I want to introduce a new library, both are mantained by me so full access to the code, CMakeLists etc
In Linux it is really easy, I just install the library with make install and then add it to my project with find_package(mynewlib REQUIRED). Then I use it as any other external library, target_link_libraries, add the headers and everything goes fine.
In Windows, I cannot make install, so I add it as a git submodule and use it like this:
find_package(MYLIB QUIET)
if(MYLIB_FOUND)
set_property(GLOBAL APPEND PROPERTY CUSTOM_STATUS MYLIB)
set_property(GLOBAL APPEND PROPERTY CUSTOM_STATUS_MYLIB
" MYLIB:" "version ${MYLIB_VERSION}")
else()
add_subdirectory(modules/mylib)
endif()
set(ALL_LIBS
Qt5::Core
Qt5::Widgets
MYLIB)
It doesn't work, linker starts complaining about unresolved symbols in different parts of the code, not related with the new introduced library. For example:
[build] Main.cpp.obj : error LNK2019: unresolved external symbol "int __cdecl qInitResources_application(void)" (?qInitResources_application@@YAHXZ) referenced in function main [build] Main.cpp.obj : error LNK2001: unresolved external symbol "public: static struct Version const Version::SOFTWARE_VERSION" (?SOFTWARE_VERSION@Version@@2U1@B) [build] targetapp\targetappcore.dll : fatal error LNK1120: 52 unresolved externals
My question is, is my approach correct? MYLIB has a very big CMakeLists.txt I am currently analyzing in case it conflicts with the top level one, but if it was fine, is this how to do it?
I will consider using a package manager like vcpkg or conan in the future, but right now I would like to keep with git submodules.