Fix madmutt for stupid terms with only 64 colors.
[apps/madmutt.git] / cmake / Modules / CMakeDetermineDCompiler.cmake
1 #
2 # CMakeD - CMake module for D Language
3 #
4 # Copyright (c) 2007, Selman Ulug <selman.ulug@gmail.com>
5 #                     Tim Burrell <tim.burrell@gmail.com>
6 #
7 # All rights reserved.
8 #
9 # See Copyright.txt for details.
10 #
11 # Modified from CMake 2.6.5 CMakeDetermineCCompiler.cmake
12 # See http://www.cmake.org/HTML/Copyright.html for details
13 #
14
15 # determine the compiler to use for D programs
16 # NOTE, a generator may set CMAKE_D_COMPILER before
17 # loading this file to force a compiler.
18 # use environment variable DC first if defined by user, next use 
19 # the cmake variable CMAKE_GENERATOR_D which can be defined by a generator
20 # as a default compiler
21
22 IF(NOT CMAKE_D_COMPILER)
23
24   # prefer the environment variable DC
25   IF($ENV{DC} MATCHES ".+")
26     GET_FILENAME_COMPONENT(CMAKE_D_COMPILER_INIT $ENV{DC} PROGRAM PROGRAM_ARGS CMAKE_D_FLAGS_ENV_INIT)
27     IF(CMAKE_D_FLAGS_ENV_INIT)
28       SET(CMAKE_D_COMPILER_ARG1 "${CMAKE_D_FLAGS_ENV_INIT}" CACHE STRING "First argument to D compiler")
29     ENDIF(CMAKE_D_FLAGS_ENV_INIT)
30     IF(EXISTS ${CMAKE_D_COMPILER_INIT})
31     ELSE(EXISTS ${CMAKE_D_COMPILER_INIT})
32       MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable C:\n$ENV{DC}.") 
33     ENDIF(EXISTS ${CMAKE_D_COMPILER_INIT})
34   ENDIF($ENV{DC} MATCHES ".+")
35
36   # next try prefer the compiler specified by the generator
37   IF(CMAKE_GENERATOR_D) 
38     IF(NOT CMAKE_D_COMPILER_INIT)
39       SET(CMAKE_D_COMPILER_INIT ${CMAKE_GENERATOR_D})
40     ENDIF(NOT CMAKE_D_COMPILER_INIT)
41   ENDIF(CMAKE_GENERATOR_D)
42
43   # finally list compilers to try
44   IF(CMAKE_D_COMPILER_INIT)
45     SET(CMAKE_D_COMPILER_LIST ${CMAKE_D_COMPILER_INIT})
46   ELSE(CMAKE_D_COMPILER_INIT)
47     SET(CMAKE_D_COMPILER_LIST gdc dmd)  
48   ENDIF(CMAKE_D_COMPILER_INIT)
49
50   # Find the compiler.
51   FIND_PROGRAM(CMAKE_D_COMPILER NAMES ${CMAKE_D_COMPILER_LIST} DOC "C compiler")
52   IF(CMAKE_D_COMPILER_INIT AND NOT CMAKE_D_COMPILER)
53     SET(CMAKE_D_COMPILER "${CMAKE_D_COMPILER_INIT}" CACHE FILEPATH "C compiler" FORCE)
54   ENDIF(CMAKE_D_COMPILER_INIT AND NOT CMAKE_D_COMPILER)
55 ENDIF(NOT CMAKE_D_COMPILER)
56 MARK_AS_ADVANCED(CMAKE_D_COMPILER)  
57 GET_FILENAME_COMPONENT(COMPILER_LOCATION "${CMAKE_D_COMPILER}" PATH)
58
59 FIND_PROGRAM(CMAKE_AR NAMES ar PATHS ${COMPILER_LOCATION} )
60
61 FIND_PROGRAM(CMAKE_RANLIB NAMES ranlib)
62 IF(NOT CMAKE_RANLIB)
63    SET(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
64 ENDIF(NOT CMAKE_RANLIB)
65 MARK_AS_ADVANCED(CMAKE_RANLIB)
66
67 # do not test for GNU if the generator is visual studio
68 IF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
69   SET(CMAKE_COMPILER_IS_GDC_RUN 1)
70 ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio") 
71
72
73 IF(NOT CMAKE_COMPILER_IS_GDC_RUN)
74   # test to see if the d compiler is gdc
75   SET(CMAKE_COMPILER_IS_GDC_RUN 1)
76   IF("${CMAKE_D_COMPILER}" MATCHES ".*gdc.*" )
77     SET(CMAKE_COMPILER_IS_GDC 1)
78     FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
79       "Determining if the D compiler is GDC succeeded with "
80       "the following output:\n${CMAKE_D_COMPILER}\n\n")
81     EXEC_PROGRAM(${CMAKE_D_COMPILER} ARGS "--version" OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT)
82     IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*mingw.*" )
83       SET(CMAKE_COMPILER_IS_MINGW 1)
84     ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*mingw.*" )
85     IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
86       SET(CMAKE_COMPILER_IS_CYGWIN 1)
87     ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
88   ELSE("${CMAKE_D_COMPILER}" MATCHES ".*dmd.*" )
89     SET(CMAKE_COMPILER_IS_DMD 1)
90     FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
91       "Determining if the D compiler is DMD succeeded with "
92       "the following output:\n${CMAKE_D_COMPILER}\n\n")
93   ENDIF("${CMAKE_D_COMPILER}" MATCHES ".*gdc.*" )
94 ENDIF(NOT CMAKE_COMPILER_IS_GDC_RUN)
95
96
97 # configure variables set in this file for fast reload later on
98 IF(EXISTS ${CMAKE_SOURCE_DIR}/cmake/Modules/CMakeDCompiler.cmake.in)
99         CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/Modules/CMakeDCompiler.cmake.in 
100                "${CMAKE_PLATFORM_ROOT_BIN}/CMakeDCompiler.cmake" IMMEDIATE)
101 ELSE(EXISTS ${CMAKE_SOURCE_DIR}/cmake/Modules/CMakeDCompiler.cmake.in)
102         CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeDCompiler.cmake.in 
103                "${CMAKE_PLATFORM_ROOT_BIN}/CMakeDCompiler.cmake" IMMEDIATE)
104 ENDIF(EXISTS ${CMAKE_SOURCE_DIR}/cmake/Modules/CMakeDCompiler.cmake.in)
105
106 MARK_AS_ADVANCED(CMAKE_AR)
107 SET(CMAKE_D_COMPILER_ENV_VAR "DC")
108