I'm not the first to run into libpng issues, especially when I want to link to self-built sources on Windows. I'm using the libpng1638 sources from https://github.com/glennrp/libpng. Semi official - the reason for this version is it has a CMake build/install script.
zlib is built/found and the library installs in c:\Program Files\libpng (I have set CMAKE_INSTALL_PREFIX for this)
The problem occurs when doing a find_package(PNG 16). With debug flag on, a number of search directories is listed, but ultimately it fails to find the PNG-config.cmake script that can link up to the installed paths and files.
It doesn't seem to help when I set CMAKE_PREFIX_PATH to the correct folder, and the reason is explained below.
This the command I used in the script (zlib is already found):
set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package(PNG 16 PATHS "C:\\Program Files\\libpng\\lib\\libpng")
set(CMAKE_FIND_DEBUG_MODE FALSE)
This is the output of the debug trace:
...
find_package considered the following locations for the Config module:
...
C:/Program Files/CMake/PNGConfig.cmake
C:/Program Files/CMake/png-config.cmake
C:/Program Files (x86)/PNGConfig.cmake
C:/Program Files (x86)/png-config.cmake
C:/Program Files/libpng/lib/libpng/PNGConfig.cmake
C:/Program Files/libpng/lib/libpng/png-config.cmake
Indeed, no png-config.cmake file can be found anywhere on my system. In the source CMakeLists.txt of libpng, the section to create these XXX-config.cmake scripts has been deliberately disabled for Win_32 systems:
# Install the pkg-config files.
if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
Since I don't want to dabble in the source files (which ultimately are pulled from the web directly), I want to understand. Why would this be disabled for native Win32 builds? (most of the online info uses the Linux subsystem or a package manager.. )
Other packages like zlib have their XXX-config.cmake files properly copied to the install folders where FindXXX.cmake scripts can pick them up properly.
For completeness, here is the output of the libpng build (msvc)
-- Install configuration: "Debug"
-- Installing: C:/Program Files/libpng/lib/libpng16d.lib
-- Installing: C:/Program Files/libpng/bin/libpng16d.dll
-- Installing: C:/Program Files/libpng/lib/libpng16_staticd.lib
-- Installing: C:/Program Files/libpng/include/png.h
-- Installing: C:/Program Files/libpng/include/pngconf.h
-- Installing: C:/Program Files/libpng/include/pnglibconf.h
-- Installing: C:/Program Files/libpng/include/libpng16/png.h
-- Installing: C:/Program Files/libpng/include/libpng16/pngconf.h
-- Installing: C:/Program Files/libpng/include/libpng16/pnglibconf.h
-- Installing: C:/Program Files/libpng/bin/pngfix.exe
-- Installing: C:/Program Files/libpng/bin/png-fix-itxt.exe
-- Installing: C:/Program Files/libpng/share/man/man3/libpng.3
-- Installing: C:/Program Files/libpng/share/man/man3/libpngpf.3
-- Installing: C:/Program Files/libpng/share/man/man5/png.5
-- Installing: C:/Program Files/libpng/lib/libpng/libpng16.cmake
-- Installing: C:/Program Files/libpng/lib/libpng/libpng16-debug.cmake
All insight greatly appreciated!
Update 1
After fiddling with the install commands, I have to conclude that libpng-libpng16.zip from https://github.com/glennrp/libpng is not maintained with Windows as build target in mind.
lpng1637.zip from https://sourceforge.net/projects/libpng/ has the same problem.
Update2 :
So far I have tried setting PNG_DIR, setting the CMAKE_PREFIX_PATH and a number of other things that failed. Just one seems to work, which is setting the environment PNG_ROOT variable to the correct installation folder. This is dead ugly, but it seems to be the only option that works.
So, for people who, like me, are trying to use freetype2 in a Windows project, here's how to build the dependencies:
make sure your zlib is built and installed also in the C:\Program Files\Zlib folder
zlib can usually be found without issues. To be sure, remove all other occurrences especially those under C:\Program Files (x86) if you have them. This will make sure find_package(..) cannot confuse between the different targets. Use -DCMAKE_INSTALL_PREFIX to force building/installing into that directory.
set the environment PNG_ROOT environment variable to C:\Program Files\libpng
set the environment BZIP2_ROOT environment variable to C:\Program Files\bzip2
set the environment ZLIB_ROOT environment variable to C:\Program Files\zlib
I did the same for dependencies Brotli and Harfbuzz, but no luck so far. Harfbuzz seems to have some strange chicken/egg relationship to freetype2.
For setting up the build for freetype2 with CMake, after building the dependencies, these flags work:
-DFT_DISABLE_HARFBUZZ=True
-DFT_REQUIRE_PNG=True
-DFT_DISABLE_BROTLI=True
-DFT_REQUIRE_BZIP2=True
-DCMAKE_PREFIX_PATH="C:\Program Files\libpng;C:\Program Files\bzip2;C:\Program Files\brotli;C:\Program Files\zlib;C:\Program Files\harfbuzz"
Note that libpng pulls in zlib as dependency, so there's no real need to specify that flag imho, so I'm not touching it.
Related
I have tried without success to use the find_package function in CMake to make use of a pre-built "system wide" version of GTest in Windows. Here is a minimal, reproducible example of my CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
find_package(GTest REQUIRED)
if(NOT GTEST_LIBRARY)
message("GTest not found!")
endif()
I try to generate build files using the following command:
cmake .. -G"Visual Studio 14 2015" -DGTEST_ROOT="c:\Libs\googletest"
The c:\Libs\googletest path contains my pre-built GTest (with header files and binaries). I have studied the FindGTest.cmake file in my CMake installation (I use CMake version 3.13.3) and tried all kinds of folder structure, but I always get the following error message:
CMake Error at C:/Program Files/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR
GTEST_MAIN_LIBRARY)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.13/Modules/FindGTest.cmake:196 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:2 (find_package)
Has anyone succeeded in using find_package for GTest in Windows? If so, how did you do it?
First you must build AND install Googletest using CMake build system
Then try to locate the GTestConfig.cmake file in the installation directory
So now you can add this path to the CMAKE_PREFIX_PATH variable.
Thus configuring your project using CMake, it should be able to find_package(GTest) using the usual search procedure.
So you just have to use GTest::GTest to consume it (i.e. target_link_libraries(.... GTest::GTest) ).
note: For people using FetchContent/add_subdirectory(googletest) beware google/googletest still not provide ALIAS target see https://github.com/google/googletest/issues/2429
I'm trying to install Fbthrift, But I am getting this error:
-- Boost version: 1.58.0
-- Found the following Boost libraries:
-- context
-- filesystem
-- program_options
-- regex
-- system
-- thread
-- chrono
-- date_time
-- atomic
-- Found folly: /usr/local
-- Found YARPL: /usr/local
-- Found rsocket: /usr/local
-- Found fizz: /usr/local
-- Found wangle: /usr/local
-- Found Zstd: /usr/lib/x86_64-linux-gnu/libz.so
-- ZLIB: /usr/include
-- Found Zstd: /usr/local/lib/libzstd.so
-- ZSTD: /usr/local/include
CMake Warning at CMakeLists.txt:144 (find_package):
By not providing "Findpython-six.cmake" in CMAKE_MODULE_PATH this
project
has asked CMake to find a package configuration file provided by
"python-six", but CMake did not find one.
Could not find a package configuration file provided by "python-six" with
any of the following names:
python-sixConfig.cmake
python-six-config.cmake
Add the installation prefix of "python-six" to CMAKE_PREFIX_PATH or set
"python-six_DIR" to a directory containing one of the above files. If
"python-six" provides a separate development package or SDK, be sure it has
been installed.
-- Python dependencies not found, will not build thrift/lib/py
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sarath/lib/fbthrift/_build
I have installed all dependencies as mentioned in official FbThrift page
Also I have installed cuda 8.0 and cuDNN 5.0 along with Torch 7 and its dependencies.
If I ignore this error and proceed to THPP installation, It shows THRIFT_LIBRARY missing and aborts installation. How to solve this problem?
This issue has been solved by installing all dependencies in Ubuntu 14.02 LTS.
Environment:
Windows 10
CMake 3.12.4
Boost 1.68.0 installed from pre-compiled binary "boost_1_68_0-msvc-14.0-64.exe" downloaded from here.
Problem:
When calling find_package(Boost COMPONENTS ...), FindBoost.cmake reports an error:
CMake Error at C:/Program
Files/CMake/share/cmake-3.12/Modules/FindBoost.cmake:1535
(_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS):
Unknown CMake command
"_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS".
How to fix it? Thanks.
I want to compile a source code on windows using CMake, it uses wxWigets library.
I downloaded the wxWigets from the page: https://www.wxwidgets.org/
After building by Visual Studio, I got the library /lib file.
I have already set PATH for wxWidgets_LIBRARIES and wxWidgets_INCLUDE_DIRS. But the following errors cannot be resolved.
CMake Error at C:/Program Files/CMake/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
wxWidgets_INCLUDE_DIRS)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.11/Modules/FindwxWidgets.cmake:953 (find_package_handle_standard_args)
CMakeLists.txt:52 (find_package)
I also read the thread about this problem in: CMake could not find wxWidgets on Windows
But there is no solution for my case.
You may specify wxWidgets_ROOT_DIR variable to point to your wxWidgets installation.
As far as I understand, you may set either CMake variable via -D option to cmake:
cmake -DwxWidgets_ROOT_DIR:PATH=D:/path/to/wxWidgets/ ...
or you may set environment variable
set wxWidgets_ROOT_DIR=D:\path\to\wxWidgets\ ...
(Note that CMake path variables use "universal" directory separator '/', but environment variables use native directory separator, '\' for Windows).
This variable is described in documentation for FindwxWidget.
Using wxWidgets_LIB_DIR variable could be tricky, see that question.
I have a solution witch can solve this problem.
there is something wrong with the FindwxWidgets.cmake File
Firstly, delete the file
C:/Program Files/CMake/share/cmake-3.11/Modules/FindwxWidgets.cmake
instead, you can find the package by using wxWidetsConfig.cmake file
YOUR_PATH\wxWidgets\lib\cmake\wxWidgets\wxWidgetsConfig.cmake.
add the flowing codes in your CMakeLists.txt and you can use wxWidgets
# set(CMAKE_PREFIX_PATH C:/dev/wxWidgets) also works
set(CMAKE_PREFIX_PATH C:/dev/wxWidgets/lib/cmake/wxWidgets)
find_package(wxWidgets COMPONENTS core base REQUIRED)
add_executable(wxwdemo WIN32 main.cpp)
target_link_libraries(wxwdemo ${wxWidgets_LIBRARIES})
target_include_directories(wxwdemo PUBLIC ${wxWidgets_INCLUDE_DIRS})
then it works
I'm trying to compile OpenCV with Cmake on Windows 7 (64-bit). It is to be used with Eclipse and CDT, for which I read somewhere that youhave to specify Unix Makefiles regardless of the compiler.
Now, given that I have cygwin as well (for Android NDK stuff), I first tried using its compilers, and I successfully configure CMake and generate makefiles, but only get to 63% of compiling, when OpenCV spits an error (about ffmpeg and HMODULE). So I switched to MinGW (HelloWorld with it was also a pain, I had to specify a full path to MinGW g++ regardless of the PATH variable setting), but now I cannot even configure CMake. I get the following error:
The C compiler identification is GNU
The CXX compiler identification is GNU
CMake Error: your RC compiler: "CMAKE_RC_COMPILER-NOTFOUND" was not found. Please set CMAKE_RC_COMPILER to a valid compiler path or name.
Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeRCInformation.cmake:22 (GET_FILENAME_COMPONENT):
get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-GNU.cmake:59 (enable_language)
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-GNU-C.cmake:1 (include)
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:56 (INCLUDE)
CMakeLists.txt:2 (PROJECT)
CMake Error: CMAKE_RC_COMPILER not set, after EnableLanguage
CMake Error: Internal CMake error, TryCompile configure of cmake failed
Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test program.
It fails with the following output:
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:47 (project)
Configuring incomplete, errors occurred!
If anyone has any idea what might be a problem (conflict with cygwin shell?), I'd appreciate any input. Thanks in advance!
We ran into the same problem with the "Unix Makefiles" Generator. We solved it by using the "MSYS Makefiles" generator (Msys is a shell environment around MinGW, like [a very small] cygwin).
This error message text:
CMake Error: your RC compiler: "CMAKE_RC_COMPILER-NOTFOUND" was not found.
Please set CMAKE_RC_COMPILER to a valid compiler path or name.
indicates that "windres" (for mingw and cygwin gcc-based build trees) is not in the PATH.
windres support, to compile Windows resource (*.rc) files was recently added in CMake 2.8.4. Perhaps windres is not available in your MinGW environment?