[CMake] win32 wrongly set on linux when using subdirectories

Stephen Sinclair radarsat1 at gmail.com
Wed Oct 1 17:10:45 EDT 2008


Hi,

This is strange.
I'm using CMake on Fedora Core 9.  I have a few .c files that should
only be included when my project is compiled on Windows, but for some
reason it was including them on Linux.  I paired this down to a
minimal example that goes wrong.  It seems that my subdirectory has
the WIN32 variable set for some reason, while the top level directory
does not.  If I cd to the subdirectory, it works fine.  Same thing
happens using SUBDIRS instead of ADD_SUBDIRECTORY.

$ cmake --version
cmake version 2.6-patch 1

$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
PROJECT(MyProj C)
ADD_SUBDIRECTORY(src)

$ cat src/CMakeLists.txt
cmake_minimum_required(VERSION 2.6)

if(WIN32)
   message(FATAL_ERROR windows detected wrongly)
endif(WIN32)

$ cmake .
CMake Error at src/CMakeLists.txt:4 (message):
  windowsdetectedwrongly


-- Configuring done

$ cd src/
$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ssteve/project/src


Apologies if this has already been fixed in a later version, but it's
a bit of a showstopper right now.  I'd like to port my project to
CMake if possible.  Thanks for any help you can offer.

Steve


More information about the CMake mailing list