在 Windows 上为 cmake 配置 Poco
Configuring Poco for cmake on Windows
我在 Windows、Linux 和 MacOS 上的几个项目中使用了 Poco,其中我手工制作了 makefile。我正在努力成为一个好公民,并将这些变成 CMake 项目,因为其他人可以更轻松地以这种方式构建我的代码。在 Linux 上,使用 find_package(Poco, REQUIRED COMPONENTS Foundation Net Util)
很容易,一切都能找到。在 Windows 上,我必须对包含目录和库目录进行硬编码。
如果我在 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 安装命令以将其安装到本地目录 (D:\poco-install
)。它似乎复制了所有 *.cmake
个文件。
D:\>cmake --build poco-build
...
[590/590] Linking CXX shared library bin\PocoDataSQLite.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-test\CMakeLists.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
这似乎工作得很好。
我在 Windows、Linux 和 MacOS 上的几个项目中使用了 Poco,其中我手工制作了 makefile。我正在努力成为一个好公民,并将这些变成 CMake 项目,因为其他人可以更轻松地以这种方式构建我的代码。在 Linux 上,使用 find_package(Poco, REQUIRED COMPONENTS Foundation Net Util)
很容易,一切都能找到。在 Windows 上,我必须对包含目录和库目录进行硬编码。
如果我在 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 安装命令以将其安装到本地目录 (D:\poco-install
)。它似乎复制了所有 *.cmake
个文件。
D:\>cmake --build poco-build
...
[590/590] Linking CXX shared library bin\PocoDataSQLite.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-test\CMakeLists.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
这似乎工作得很好。