在Windows上为cmake配置Poco



我在Windows、Linux和MacOS上的几个项目中使用了Poco,这些项目中我手工制作了makefile。我正在努力成为一个好公民,并将这些转化为CMake项目,因为其他人更容易用这种方式构建我的代码。在Linux上,使用find_package(Poco, REQUIRED COMPONENTS Foundation Net Util)很容易,而且一切都可以找到。在Windows上,我必须对include目录和库目录进行硬编码。

如果我在Windows上尝试find_package,我会收到一个投诉,说在我的根目录中找不到PocoConfig.cmake。有一个cmake/PocoConfig.cmake.in,如果我把它复制到根目录,它就会抱怨PocoFoundationConfig.cmake

很明显,我错过了一步。我错过了什么步骤,会自动将所有这些PocoXxxx.cmake文件放在它们所属的位置?我觉得我离得很近。

我不知道您运行了哪些步骤,但我只是尝试了以下步骤。这是手动使用CMake包的最常见方式。

首先,我克隆了存储库并对其进行了配置。我没有安装可选的依赖项,但它还是通过了:

D:>git clone https://github.com/pocoproject/poco
...
D:>cmake -G Ninja -S poco -B poco-build -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is MSVC 19.28.29913.0
-- The CXX compiler identification is MSVC 19.28.29913.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.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: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Checking for C++14 compiler
-- Checking for C++14 compiler - available
-- Found message compiler: C:/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64/mc.exe
-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)
-- Could NOT find APR (missing: APR_INCLUDE_DIR APR_LIBRARY)
-- Could NOT find APRUTIL (missing: APRUTIL_INCLUDE_DIR APRUTIL_LIBRARY)
-- Could NOT find Apache2 (missing: APACHE2_INCLUDE_DIR)
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
The package name passed to `find_package_handle_standard_args` (MYSQL) does
not match the name of the calling package (MySQL).  This can lead to
problems in calling code that expects `find_package` result variables
(e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
cmake/FindMySQL.cmake:107 (find_package_handle_standard_args)
CMakeLists.txt:119 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.
-- Could NOT find MYSQL (missing: MYSQL_INCLUDE_DIR MYSQL_LIBRARY)
-- Could NOT find PostgreSQL (missing: PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR)
-- Found ODBC: C:/Program Files (x86)/Windows Kits/10/Lib/10.0.18362.0/um/x64/odbc32.lib
-- Building without tests & samples
-- Using internal sqlite, zlib, pcre, expat, ...
-- SQLite Support Enabled
-- MySQL Support Disabled
-- PostgreSQL Support Disabled
-- ODBC Support Enabled
-- CMake 3.20.0 successfully configured Poco using Ninja generator
-- Poco package version: 1.10.1
-- Building dynamic libraries
-- [cmake] Installation target path: C:/Program Files (x86)/Poco
-- [cmake] Bulid for OS type:           Windows
-- [cmake] Build for OS version:        10.0.19042
-- [cmake] Build for CPU type:          AMD64
-- [cmake] Build type:                          Release
-- [cmake] Build with cxx flags:        /MD /O2 /Ob2 /DNDEBUG /DWIN32 /D_WINDOWS /W3 /GR /EHsc
-- [cmake] Build with c flags:          /MD /O2 /Ob2 /DNDEBUG /DWIN32 /D_WINDOWS /W3
-- Building: Encodings
-- Building: XML
-- Building: JSON
-- Building: Util
-- Building: Net
-- Building: MongoDB
-- Building: Redis
-- Building: Data
-- Building: Zip
-- Building: PageCompiler
-- Building: File2Page
-- Configuring done
-- Generating done
-- Build files have been written to: D:/poco-build

然后我构建了库,并运行CMake-install命令将其安装到本地目录(D:poco-install(。它似乎复制了所有的*.cmake文件。

D:>cmake --build poco-build
...
[590/590] Linking CXX shared library binPocoDataSQLite.dll
D:>cmake --install poco-build --prefix poco-install
...
-- Installing: D://poco-install/cmake/PocoConfig.cmake
-- Installing: D://poco-install/cmake/PocoConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoFoundationTargets.cmake
-- Installing: D://poco-install/cmake/PocoFoundationTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoFoundationConfig.cmake
-- Installing: D://poco-install/cmake/PocoFoundationConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoEncodingsTargets.cmake
-- Installing: D://poco-install/cmake/PocoEncodingsTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoEncodingsConfig.cmake
-- Installing: D://poco-install/cmake/PocoEncodingsConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoXMLTargets.cmake
-- Installing: D://poco-install/cmake/PocoXMLTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoXMLConfig.cmake
-- Installing: D://poco-install/cmake/PocoXMLConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoJSONTargets.cmake
-- Installing: D://poco-install/cmake/PocoJSONTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoJSONConfig.cmake
-- Installing: D://poco-install/cmake/PocoJSONConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoUtilTargets.cmake
-- Installing: D://poco-install/cmake/PocoUtilTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoUtilConfig.cmake
-- Installing: D://poco-install/cmake/PocoUtilConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoNetTargets.cmake
-- Installing: D://poco-install/cmake/PocoNetTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoNetConfig.cmake
-- Installing: D://poco-install/cmake/PocoNetConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoMongoDBTargets.cmake
-- Installing: D://poco-install/cmake/PocoMongoDBTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoMongoDBConfig.cmake
-- Installing: D://poco-install/cmake/PocoMongoDBConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoRedisTargets.cmake
-- Installing: D://poco-install/cmake/PocoRedisTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoRedisConfig.cmake
-- Installing: D://poco-install/cmake/PocoRedisConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoDataTargets.cmake
-- Installing: D://poco-install/cmake/PocoDataTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoDataConfig.cmake
-- Installing: D://poco-install/cmake/PocoDataConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoDataSQLiteTargets.cmake
-- Installing: D://poco-install/cmake/PocoDataSQLiteTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoDataSQLiteConfig.cmake
-- Installing: D://poco-install/cmake/PocoDataSQLiteConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoDataODBCTargets.cmake
-- Installing: D://poco-install/cmake/PocoDataODBCTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoDataODBCConfig.cmake
-- Installing: D://poco-install/cmake/PocoDataODBCConfigVersion.cmake
-- Installing: D://poco-install/cmake/PocoZipTargets.cmake
-- Installing: D://poco-install/cmake/PocoZipTargets-release.cmake
-- Installing: D://poco-install/cmake/PocoZipConfig.cmake
-- Installing: D://poco-install/cmake/PocoZipConfigVersion.cmake
...

最后,我创建了一个文件D:poco-testCMakeLists.txt,其中包含以下内容:

cmake_minimum_required(VERSION 3.20)
project(test)
# note: I deleted the comma in your question
find_package(Poco REQUIRED COMPONENTS Foundation Net Util)

然后我运行:

D:poco-test>cmake -G Ninja -S . -B build -DPoco_ROOT=D:/poco-install
...
-- Configuring done
-- Generating done
-- Build files have been written to: D:/poco-test/build

这似乎很好用。

最新更新