CMake find_path not working on MinGW - cmake

I have an issue when using find_path CMake command on windows and MinGW.
Consider the following code:
find_path(FINDPATH_TEST stdio.h)
message(STATUS "FINDPATH_TEST: "${FINDPATH_TEST})
It works perfectly on Linux, printing: FINDPATH_TEST: /usr/include.
However running this code on windows using "MinGW Makefiles" as CMake generator will output:
FINDPATH_TEST: FINDPATH_TEST-NOTFOUND
Why find_path not works in the same way on MinGW?

You could check this thread: http://www.cmake.org/pipermail/cmake/2007-November/017813.html It explains what are the default search paths for various operating systems. You should see which one is used in your case (mingw).
I also believe that you may need to use the cmake version compiled for mingw in order to get that working on your mingw environment. I am not 100% sure though because I didn't use cmake with mingw.

Related

wxWidgets CMake Windows Setup Troubles

I am really struggling to setup wxWidgets to work on Windows and CMake and would appreciate some help.
I have downloaded wxWidgets 3.1.4, run the setup (which extracted to C:\CPP_lib\wxWidgets) and then ran the following commands in the terminal:
cd C:\CPP_lib
mkdir wxWidgets-install
cmake C:\CPP_lib\wxWidgets -DCMAKE_INSTALL_PREFIX=C:\CPP_lib\wxWidgets-install -DwxBUILD_SHARED=OFF
cd wxWidgets-install
cmake --build . --target install
I have environment variables CMAKE_PREFIX_PATH set to C:\CPP_lib and wxWidgets_DIR and wxWidgets_ROOT_DIR both set to C:\CPP_lib\wxWidgets-install.
However, when I have a simple CMake project that calls find_package(wxWidgets), I get the following message in the terminal:
Found wxWidgets: winmm;comctl32;uuid;oleacc;uxtheme;rpcrt4;shlwapi;version;wsock32
missing components: core base png tiff jpeg zlib regex expat
Please help - I have been struggling for a while now :(
It turns out the issue was a very specific one related to vcpkg.
I had pointed CMake to my vcpkg toolchain file (even though wxWidgets was installed independent of vcpkg) and this was causing issues with finding wxWidgets i.e. vcpkg was preventing wxWidgets (a non-vcpkg installation) from being found.
I believe this is a vcpkg bug, although am not sure, but have reported it anyways.

How to use CMake with cygwin/mingw toolchain?

What is the current process to use the mingw toolchain that is included with cygwin?
There use to be a -mno-cygwin option used with gcc.
The mingw versions have x86_64-w64-mingw32- or i686-w64-mingw32- added to their exe names. Currently I just use these directly but I want to use cmake.
Cygwin also includes cmake. How would I configure it to use the mingw toolset that is included with cygwin? I also see some Qt5 *.cmake modules included in the Qt5 libraries for mingw.
Thanks.
I've found a temporary workaround. Just define these two environment variables:
set CC=/usr/bin/x86_64-w64-mingw32-gcc.exe
set CXX=/usr/bin/x86_64-w64-mingw32-g++.exe
Define them before running the cmake that is included with cygwin.
Seems to work.

Cmake on msys2 for someone who's unfamiliar with the environment

I'm trying to get cmake working on msys2. I try to compile some code that I've been given for another project and:
CMake Error: Could not create named generator MSYS Makefiles
I've found this thread and this thread and tried to follow the instructions...only to realize that the wiki that the threads eventually link back to never states where msys stores toolchains. Googling around didn't really help.
Even more oddly, the program that I'm trying to use somehow runs and produces valid data despite throwing an error due to the missing cmake. I don't get it.
I've never used msys before; as someone who's brand new to msys2/cygwin and can't even understand the lingo, how do I get cmake installed and working?
Sounds like you are specifying a -G "MSYS Makefiles" as the CMake generator, but CMake doesn't recognize that generator. When I use CMake on msys2 I just use the default Unix Makefiles generator and everything works just fine. Also, on my current msys2 install, CMake doesn't seem to have a MSYS Makefile generator that I can see (running cmake --help will list the available generators). Try running cmake without the -G option. Also, make sure make is installed first via pacman -Sy make.

Compiling latest release of CppUTest (3.7) with MinGw, pthreads missing

I'm trying to use CppUTest in Windows, first step is to get it to work and I already have problems. These are the things I've tried:
First Approach
With CMake, using the cmake GUI I can do the configure and generate command and I get something in the output directory, but no binaries and no libraries, just a bunch of cmakefiles. The CMake GUI says everything went OK during the configuration and generation steps, however the libraries (.lib files) are not generated in the output directory... is there something I am missing? I've never used CMake before.
Second approach
With MinGW and msys alone, running cmd in Windows and executing a MinGW shell by typing sh in the Windows terminal, afterwards I execute the following commands:
cd <CppUTest folder>
mount c:\mingw /mingw
./autogen.sh
./configure
make
The build process starts but it fails with a message indicating that pthread.h was not found in MinGW directory. If I install the pthread-win32 package with the MinGW package manager and repeat the same steps as above the build process starts but fails with a message indicating that the structure timespec is defined in time.h and pthread.h.
I've tried to follow this same procedure with CppUTest 3.6 and it works perfectly fine, I get the .lib files, so I guess I will have to continue with this for now.
Does anyone know how to build CppUTest 3.7 (latest release) with MinGW or CMake?
In the end I used Cygwin to compile it, I couldn't find a way to compile it with MinGW properly, I added a dirty trick to make it compile under MinGW (handled the timespec redifinition) but chances are that is going to cause issues.
Just make sure that you use Cygwin aswell to compile your tests, something that I found out after making this question (https://www.youtube.com/watch?v=oVmd0P85D8o).

CMake: find wxWidgets built with MinGW/MSYS?

I compiled wxWidgets 2.8.12 using MinGW. To actually do the build I invoked the autotools build files distributed with wxWidgets through the MSYS shell, using an install prefix of H:\MinGW-libs.
The result of this is that I have a Unix style file tree containing my wxWidgets headers and libs (which are .a files, not .dll) with root directory H:\MinGW-libs.
My problem is that I can't get CMake to find the files. When I try to use the "configure" button in the CMake gui it finds other dependencies (namely boost, for which I had to specify BOOST_ROOT, but it does not find wxWidgets. I see that wxWidgets_ROOT_DIR is an available constant that I can set but none of the obvious choices
H:\MinGW-libs (my install prefix for wxWidgets)
H:\MinGW-libs\lib
H:\MinGW-libs\include
fix the error.
There is an old post on the CMake mailing list about this issue but there isn't actually any information indicating how to fix it in this use case. The only hint I have is that there's a difference between looking for wxWidgets in "Unix style" file trees and "Windows style" file trees.
How can I get CMake to find wxWidgets installed in a Unix style file tree on Windows 7? Is there are way to get CMake to use wx-config? I ask this because from the MSYS command line using wx-config to get lib and header locations works just fine.
From FindwxWidgets.cmake:
if(WIN32 AND NOT CYGWIN AND NOT MSYS)
set(wxWidgets_FIND_STYLE "win32")
else()
if(UNIX OR MSYS)
set(wxWidgets_FIND_STYLE "unix")
endif()
endif()
So Unix-style tree is assumed for the "MSYS Makefiles" generator (cmake -G "MSYS Makefiles") but not for the "MinGW Makefiles" generator.
Which one do you use?