我正在尝试使用CMake实现跨平台构建系统.现在该软件有一些依赖性.我自己编译并将它们安装在我的系统上.
安装的一些示例文件:
-- Installing: /usr/local/share/SomeLib/SomeDir/somefile
-- Installing: /usr/local/share/SomeLib/SomeDir/someotherfile
-- Installing: /usr/local/lib/SomeLib/somesharedlibrary
-- Installing: /usr/local/lib/SomeLib/cmake/FindSomeLib.cmake
-- Installing: /usr/local/lib/SomeLib/cmake/HelperFile.cmake
Run Code Online (Sandbox Code Playgroud)
现在,CMake有一个find_package()打开Find*.cmake文件并在系统上的库之后搜索并定义一些变量等SomeLib_FOUND.
我的CMakeLists.txt包含这样的内容:
set(CMAKE_MODULE_PATH "/usr/local/lib/SomeLib/cmake/;${CMAKE_MODULE_PATH}")
find_package(SomeLib REQUIRED)
Run Code Online (Sandbox Code Playgroud)
第一个命令定义了CMake在搜索之后搜索的位置,Find*.cmake并且我添加SomeLib了FindSomeLib.cmake可以找到的目录,因此find_package()按预期工作.
但这find_package()有点奇怪,因为存在的原因之一是远离非跨平台硬编码路径.
这通常是怎么做的?我应该将cmake/目录复制SomeLib到我的项目中并设置CMAKE_MODULE_PATH相对吗?
我在 Windwos 上试图让 Mingw-w64 与 CMake 一起工作,因为我的 MSVC 不知何故根本无法工作(使用 Windows10 64bit.
基本上我将参数添加-DCMAKE_CXX_COMPILER="C:/MinGW-w64/mingw64/bin/g++.exe" -DCMAKE_C_COMPILER="C:/MinGW-w64/mingw64/bin/gcc.exe"到我对设置相应编译器的 CMake 的调用中。
但是我收到这些错误:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: C:/MinGW-w64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/MinGW-w64/mingw64/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"C:/MinGW-w64/mingw64/bin/gcc.exe"
is not able to compile a simple test program.
Run Code Online (Sandbox Code Playgroud)
我怎么能让这个工作?