If you ever built a program using CMake, you must have encountered errors like:
- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
- Could NOT find Libidn (missing: LIBIDN_LIBRARY LIBIDN_INCLUDE_DIR)
- Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)
- Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR)
- Could NOT find Fontconfig (missing: Fontconfig_LIBRARY Fontconfig_INCLUDE_DIR)
Yes, the libraries are not installed on your system. CMake does not bother to install them automatically, you should do it yourself. How to install those libs? You can download them from the Internet and install them one by one. But more convenient way is to use vcpkg to install them such as
vcpkg install zlib:x64-windows
Best part of using vcpkg is if the lib to be installed depends on other libs, vcpkg will install them automatically for you. vcpkg installs packages as follows:
- download the package’s source code to C:\vcpkg\downloads\
- extract the source code to C:\vcpkg\buildtrees\
- build the lib to C:\vcpkg\packages\
- install the lib to C:\vcpkg\installed\
But even after you install the required libs using vcpkg, CMake will still complain it cannot find the lib. You should tell CMake where to find the vcpkg-installed packages using the CMAKE_TOOLCHAIN_FILE macro:
cmake C:\yourproject -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
Note that you should install the needed packages using vcpkg, then execute the above command. CMake won’t call vcpkg automatically for you when it wants a package.
However, with the CMAKE_TOOLCHAIN_FILE definition alone, you will still encounter the error when compiling your project:
error C1083: Cannot open include file: ‘podofo/podofo.h’: No such file or
directory
The CMAKE_TOOLCHAIN_FILE variable only lets CMake know the location that vcpkg puts its installed packages. (if you put a vcpkg.json file in your project directory listing the libs your project depends on, the execution of cmake C:\yourproject -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake will automatically start vcpkg to download and install the dependent packages in the vcpkg_installed directory in your build directory, not in normal vcpkg install directory.) You will still have to call the find_package command explicitly in your project’s CMakeLists.txt such as find_package(podofo CONFIG REQUIRED) to call the podofo-config.cmake file provided by vcpkg to set some important variables(such as the lib and include directories) for the lib podofo. You do not need to call include_directories($PODOFO_INCUDE_DIRS), which will be done by vcpkg generated .cmake file for the library.