Search code examples
cmakecygwinmingwmingw-w64msys2

cmake cannot find an existing directory on mingw64 (msys2)


I am trying to compile a project under MSYS2 and CLANG64 environment.

I have previously compiled dependencies in /usr/local.

$ ls /usr/local/include
boost    compat-5.3.c  cryptopp  lauxlib.h    libmongoc-1.0  lua.hpp    luajit.h  mongocxx  yaml-cpp
bsoncxx  compat-5.3.h  gtest     libbson-1.0  lua.h          luaconf.h  lualib.h  tsl

$ ls /usr/local/lib
cmake                          libboost_filesystem-mt-s-x64.a       libbson-static-1.0.a  libmongoc-1.0.dll.a
libboost_atomic-mt-s-x64.a     libboost_program_options-mt-s-x64.a  libbsoncxx-static.a   libmongoc-static-1.0.a
libboost_atomic-mt-x64.a       libboost_regex-mt-s-x64.a            libcryptopp.a         libmongocxx-static.a
libboost_chrono-mt-s-x64.a     libboost_system-mt-s-x64.a           libgtest.a            libyaml-cpp.a
libboost_container-mt-s-x64.a  libboost_thread-mt-s-x64.a           libgtest_main.a       pkgconfig
libboost_context-mt-s-x64.a    libbson-1.0.dll.a                    liblua-compat.a

But when I create the project, I explicitly set the location of binaries with interface libraries as I don't want to rely on the find mechanism that has hurt me badly in the past - linking to unintended, old system libraries.

project(test)
cmake_minimum_required( VERSION 3.0 )

add_library( cryptopp STATIC IMPORTED GLOBAL )
set_target_properties( cryptopp PROPERTIES
    IMPORTED_LOCATION "/usr/local/lib/libcryptopp.a"
    INTERFACE_INCLUDE_DIRECTORIES "/usr/local/include"
    INTERFACE_COMPILE_DEFINITIONS "HAVE_CRYPTOPP"
)
add_executable( test test.cpp )
target_link_libraries( test cryptopp )

This works perfect under all Linux distros - Redhat, Ubuntu, etc but fails in MSYS2.

However when I run cmake, I get an error stating that /usr/local/include does not exist.

$ cmake ..
-- Building for: Ninja
-- The C compiler identification is Clang 14.0.4
-- The CXX compiler identification is Clang 14.0.4
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: G:/msys64/clang64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: G:/msys64/clang64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error in CMakeLists.txt:
  Imported target "cryptopp" includes non-existent path

    "/usr/local/include"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.
-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

I just cannot figure out why this is happening. Any clues?


Solution

  • Maybe it's a Windows path issue. Try replacing /usr/local with the output of cygpath -m /usr/local.