How to use CMake with cygwin/mingw toolchain? - cmake

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.

Related

How do I create my own cmake target with pkg-config settings?

My project is shared library, and I would like to create installation target with settings for pkg-config.
Currently it builds by only one, very simple rule:
add_library(mylib SHARED src/mylib.cxx)
And here I'm stuck with further configuration because every installation rule should be dependent on the preconfigured installation paths and flags. To keep it simple, let's say, the target will be installed to include and lib directories and preconfigured .pc rules will be something like -lmylib -I/...include -L/....lib
How can I configure cmake's installation targets with pkg-config support ? I guess it does not have builtin support of pkg-config and I need your help to find a proper solution.
CMake can interoperate with pkg-config in both directions, though it's a little bit clunky.
FindPkgConfig allows you to find and use libraries using their pkg-config files.
To have cmake generate a pkg-config file for your own library, you'll have to use configure_file and have a template pkg-config file.

MSYS2, change the gcc toolchain PATH to "C:\TDM-GCC-32" instead of using the default MinGW-w64 one?

To use MSYS2 shell, how to change the gcc toolchain PATH to "C:\TDM-GCC-32" instead of using the default MinGW-w64 one ?
How to tell MSYS2 to use "C:\TDM-GCC-32" toolchain instead of the default ?
Thank you for your understanding.
You can add that toolchain to your path by running this command in an MSYS2 Bash shell:
export PATH=/c/TDM-GCC-32/bin:$PATH
I'm assuming the TDM-GCC-32 folder has a "bin" folder inside it with executables. If that's not the case, you will need the command above.
Note that, in general, adding a folder to your PATH with arbitrary executables and DLLs could cause problems with MSYS2, because those executables and DLLs might be used instead of their default counterparts with the same name.
Also note that the binaries generated by TDM-GCC might not necessarily be compatible with the binaries generated by MSYS2's MinGW toolchain.

CMake fails looking up mingw headers

Trying to change FindSDL.make to work with SDL2. The problem is that using mingw it doesn't find SDL2_INCLUDE_DIR, even though SDL2 is installed.
I've change the whole file, but the problems is in this line:
find_path(SDL2_INCLUDE_DIR
NAMES
SDL.h
PATH_SUFFIXES
include/SDL2
)
Thought it should look up MinGW folder, but it looks like it doesn't.
Actually, even this one doesn't work:
find_path(TEST_PATH stdio.h)
So what is the proper way to use find_path under mingw on Windows? Can it be related to mingw install path (preferred one is C:\MinGW, but I've installed it to E:\Programs\MinGW)?
Should I always explicitly write -DCMAKE_INCLUDE_PATH=<my path to mingw>\include or use environment variable that points to mingw folder and use it as a HINT to find_path?

llvm's cmake integration

I'm currently building a compiler/interpreter in C/C++.
When I noticed LLVM I thought it would fit greatly to what I needed and so I'm trying to integrate LLVM in my existing build system (I use CMake).
I read this bout integration of LLVM in CMake. I copy and pasted the example CMakeLists.txt, changed the LLVM_ROOT to ~/.llvm/ (that's where I downloaded and build LLVM and clang) and it says it isn't a valid LLVM-install. Best result I could achieve was the error message "Can't find LLVMConfig" by changing LLVM_ROOT to ~/.llvm/llvm.
My ~/.llvm/ folder looks like this:
~/.llvm/llvm # this folder contains source files
~/.llvm/build # this folder contains object, executable and library files
I downloaded LLVM and clang via SVN. I did not build it with CMake.
Is it just me or is something wrong with the CMakeLists.txt?
This CMake documentation page got rotted, but setting up CMake for LLVM developing isn't different from any other project. If your headers/libs are installed into non-standard prefix, there is no way for CMake to guess it.
You need to set CMAKE_PREFIX_PATH to the LLVM installation prefix or CMAKE_MODULE_PATH to prefix/share/llvm/cmake to make it work.
And yes, use the second code snippet from documentation (under Alternativaly, you can utilize CMake’s find_package functionality. line).

CMake find_path not working on MinGW

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.