summaryrefslogtreecommitdiff
path: root/cmake/os.cmake
blob: e24059dd5b3bea21f90339314793fc73261eed2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
##
## Author: Hank Anderson <hank@statease.com>
## Description: Ported from portion of OpenBLAS/Makefile.system
##              Detects the OS and sets appropriate variables.

if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  set(EXTRALIB "${EXTRALIB} -lm")
  set(NO_EXPRECISION 1)
endif ()

if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|OpenBSD|NetBSD|DragonFly|Darwin")
  set(EXTRALIB "${EXTRALIB} -lm")
  set(NO_EXPRECISION 1)
endif ()

if (${CMAKE_SYSTEM_NAME} STREQUAL "AIX")
  set(EXTRALIB "${EXTRALIB} -lm")
endif ()

# TODO: this is probably meant for mingw, not other windows compilers
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")

  set(NEED_PIC 0)
  set(NO_EXPRECISION 1)

  set(EXTRALIB "${EXTRALIB} -defaultlib:advapi32")

  # probably not going to use these
  set(SUFFIX "obj")
  set(PSUFFIX "pobj")
  set(LIBSUFFIX "a")

  if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
    set(CCOMMON_OPT	"${CCOMMON_OPT} -DMS_ABI")
  endif ()

  if (${CMAKE_C_COMPILER_ID} STREQUAL "GNU")

    # Test for supporting MS_ABI
    # removed string parsing in favor of CMake's version comparison -hpa
    execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
    if (${GCC_VERSION} VERSION_GREATER 4.7 OR ${GCC_VERSION} VERSION_EQUAL 4.7)
      # GCC Version >=4.7
      # It is compatible with MSVC ABI.
      set(CCOMMON_OPT "${CCOMMON_OPT} -DMS_ABI")
    endif ()
  endif ()

  # Ensure the correct stack alignment on Win32
  # http://permalink.gmane.org/gmane.comp.lib.openblas.general/97
  if (X86)
    if (NOT MSVC AND NOT ${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
      set(CCOMMON_OPT "${CCOMMON_OPT} -mincoming-stack-boundary=2")
    endif ()
    set(FCOMMON_OPT "${FCOMMON_OPT} -mincoming-stack-boundary=2")
  endif ()
  
endif ()

if (${CMAKE_SYSTEM_NAME} STREQUAL "Interix")
  set(NEED_PIC 0)
  set(NO_EXPRECISION 1)
  
  set(INTERIX_TOOL_DIR STREQUAL "/opt/gcc.3.3/i586-pc-interix3/bin")
endif ()

if (CYGWIN)
  set(NEED_PIC 0)
  set(NO_EXPRECISION 1)
endif ()

if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Interix" AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Android")
  if (USE_THREAD)
    set(EXTRALIB "${EXTRALIB} -lpthread")
  endif ()
endif ()

if (QUAD_PRECISION)
  set(CCOMMON_OPT "${CCOMMON_OPT} -DQUAD_PRECISION")
  set(NO_EXPRECISION 1)
endif ()

if (X86)
  set(NO_EXPRECISION 1)
endif ()

if (DYNAMIC_ARCH)
if (TARGET)
if (${TARGET} STREQUAL "GENERIC")
  set(NO_EXPRECISION 1)
endif ()
endif ()
endif ()

if (UTEST_CHECK)
  set(CCOMMON_OPT "${CCOMMON_OPT} -DUTEST_CHECK")
  set(SANITY_CHECK 1)
endif ()

if (SANITY_CHECK)
  # TODO: need some way to get $(*F) (target filename)
  set(CCOMMON_OPT "${CCOMMON_OPT} -DSANITY_CHECK -DREFNAME=$(*F)f${BU}")
endif ()