[CMake] win32 wrongly set on linux when using subdirectories

Bill Hoffman bill.hoffman at kitware.com
Wed Oct 1 17:33:15 EDT 2008


Stephen Sinclair wrote:
> 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
> 

I am unable to reproduce this.

hoffman at hythloth:~/testit/b$ ~/cmake-2.6.1-Linux-i386/bin/cmake ..
-- The C compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
hello from subdir
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hoffman/testit/b


Where did you get the cmake binary?  Try the one from 
http://www.cmake.org/cmake/resources/software.html

You don't need to be root to install, just untar anywhere and use a full 
path to cmake.

-Bill



More information about the CMake mailing list