CMake find_library can't find an existing library on MSVC

Viewed 78

I made a project and tried to build it under GCC (Linux) and MinGW (Windows) using CMake. Now I'm trying to do the same under Visual Studio 2019 (for reasons) and it seems that CMake that is shipped with VS can't find libraries installed with MSVC.

I'm using a script which unfortunately I can't find again on the Net, so I can't give you a link to it. But I tried to isolate what is causing the problem. So, here is the code:

if(MY_LIB_PATH)
  set(MYLIB_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH)
endif()

find_library(MY_LIBRARY
  NAMES myLibrary
  HINTS
    ENV MY_ENV
    ${MYLIB_NO_DEFAULT_PATH_CMD}
  PATH_SUFFIXES lib lib/x64
  PATHS ${MY_LIB_PATH}
  DOC ""
)

(the code is much complicated than that, but that is what it looks after all variable substitutions)

If I don't set the MY_LIB_PATH variable it can't find the library (which is located in the lib/x64 folder in the MSVC installation folder). But when I call CMake like this:

cmake "-DMY_LIB_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\lib\x64" 

it "miraculously" finds it.

Yes it works but...wasn't CMake made to avoid writing all that path in the first place? Besides, there is yet another problem: there are many such libraries in my project, all of which use the same above code for finding, and I have to write all that path multiple times, so CMake can find them.

Either the authors of my CMake script did something wrong or I installed my libraries not where CMake is expecting them.

0 Answers
Related