3

I have never used CMake before, but I'm trying out an IDE (CLion) that doesn't support any other build system, so am giving it a try. I get the following warning at the start of every build:

CMake Warning at /cygdrive/c/Users/admin/.clion10/system/cygwin_cmake/share/cmake-3.1.2/Modules/Platform/CYGWIN.cmake:15 (message): CMake no longer defines WIN32 on Cygwin!

(1) If you are just trying to build this project, ignore this warning or quiet it by setting CMAKE_LEGACY_CYGWIN_WIN32=0 in your environment or in the CMake cache. If later configuration or build errors occur then this project may have been written under the assumption that Cygwin is WIN32. In that case, set CMAKE_LEGACY_CYGWIN_WIN32=1 instead.

(2) If you are developing this project, add the line

set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required

at the top of your top-level CMakeLists.txt file or set the minimum required version of CMake to 2.8.4 or higher. Then teach your project to build on Cygwin without WIN32

I have tried both of the proposed solutions. Here are the first two lines of my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.1)
set(CMAKE_LEGACY_CYGWIN_WIN32 0)

yet I still get the warning. How do I get rid of it?

Jules
  • 14,841
  • 9
  • 83
  • 130
  • execute `-Wno-dev` option to disabe these warnings: `cmake -Wno-dev /path/to/source` – fenix688 Feb 23 '15 at 22:05
  • 2
    According to the manual, that option is intended to "suppress warnings that are meant for the author of the CMakeLists.txt files". As author of the CMakeLists.txt file, I'd rather not suppress warnings that are intended for me, especially as a newcomer to the environment who is likely to make mistakes with it... – Jules Feb 23 '15 at 23:03

3 Answers3

5

According to Nils Gladitz (is he on SO?) on the CMake mailing list:

The code that emits the warning is run by "project()". Since you do not have an explicit project() call in your top-level CMakeLists.txt CMake adds one to the top implicitly. [1]

A project file that explicitly calls project() after requiring CMake >= 2.8.4 should make the warning go away:

cmake_minimum_required(VERSION 2.8.8)

project(Foo)

And it seems to work.

Community
  • 1
  • 1
thoni56
  • 3,145
  • 3
  • 31
  • 49
  • 1
    Just one of the many design quirks and gotchas that makes this tool such a headache to use. – marknuzz Mar 02 '16 at 21:49
  • Agreed. Like many other tools it seems to have started with a sound idea, but got lost in all the details and special cases. Build tools seems inherently hard to keep simple and still do the work, `make` has fallen for that trap to. There are anumber of attempts out there that tried to do what`cmake` tried but have no traction. – thoni56 Mar 03 '16 at 07:00
  • I've spent so much time until I found this solution. Just put cmake_minimum_required before project!!! I hate CMake :-( – Bai Bing Jun 25 '21 at 10:15
1

Move set(CMAKE_LEGACY_CYGWIN_WIN32 0) to the top of the CMakeLists file. It must be evaluated BEFORE cmake_minimum_required in order to work properly in this context.

marknuzz
  • 2,847
  • 1
  • 26
  • 29
  • To me this seems like a bug, or at least flawed logic, in CMake. According to the message you should define `set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required`. To me the comment indicates that if I set `cmake_minimum_required(VERSION 3.1)` the message should go away (since 3.1 >= 2.8.4). The message then goes on to explicitly state `OR set the minimum required version of CMake to 2.8.4 or higher` (my capitalization). – thoni56 Mar 02 '16 at 07:02
0

My cmake file is used in both Cygwin & Linux. So for me the easiest solution was to edit my Cygwin .bashrc and add the line

export CMAKE_LEGACY_CYGWIN_WIN32=0

Now I don't have to leave Cygwin specific syntax in my cross-platform cmake file.

PfunnyGuy
  • 750
  • 9
  • 22