Tim Roberts
Tim Roberts

Reputation: 54698

Configuring Poco for cmake on Windows

I use Poco on Windows, Linux, and MacOS in several projects where I've handcrafted makefiles. I'm trying to be a good citizen and turn these into CMake projects, because it's easier for others to build my code that way. On Linux, it's easy to use find_package(Poco, REQUIRED COMPONENTS Foundation Net Util), and everything gets found. On Windows, I have to hardcode include directories and library directories.

If I try find_package on Windows, I get a complaint that PocoConfig.cmake is not found in my root. There's a cmake/PocoConfig.cmake.in, and if I copy that to the root, then it complains about PocoFoundationConfig.cmake.

Clearly, I have missed a step. What step have I missed that would automatically have placed all of these PocoXxxx.cmake files where they belong? I feel like I'm very close.

Upvotes: 2

Views: 2640

Answers (1)

Alex Reinking
Alex Reinking

Reputation: 19916

I don't know what steps you ran, but I just tried the following. This is the most common way to manually consume a CMake package.

First, I cloned the repository and configured it. I don't have the optional dependencies installed, but it went through, anyway:

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

Then I built the library and ran the CMake install command to install it to a local directory (D:\poco-install). It seemed to copy all the *.cmake files.

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
...

Finally, I created a file D:\poco-test\CMakeLists.txt with the following contents:

cmake_minimum_required(VERSION 3.20)
project(test)

# note: I deleted the comma in your question
find_package(Poco REQUIRED COMPONENTS Foundation Net Util)

and then I ran:

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

which seemed to work just fine.

Upvotes: 5

Related Questions