-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cmake
109 lines (92 loc) · 3.23 KB
/
common.cmake
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
105
106
107
108
109
if(CMAKE_VERSION VERSION_LESS 3.1)
function(target_compile_features one two three)
string(FIND ${ARGV2} c_ position)
if(0 EQUAL position)
set(STANDARD C_STANDARD)
endif()
string(FIND ${ARGV2} cxx_ position)
if(0 EQUAL position)
set(STANDARD CXX_STANDARD)
endif()
string(FIND ${ARGV2} _ position REVERSE)
math(EXPR position "${position} + 1")
string(SUBSTRING ${ARGV2} ${position} -1 STANDARD_VERSION)
set_property(TARGET ${ARGV0} PROPERTY ${STANDARD} ${STANDARD_VERSION})
endfunction()
endif()
macro(get_compiler_version)
if(MSVC)
if(MSVC14)
string(SUBSTRING ${MSVC_TOOLSET_VERSION} 0 2 VERSION_PREFIX)
string(SUBSTRING ${MSVC_TOOLSET_VERSION} 2 -1 VERSION_SUFFIX)
string(FIND "${CMAKE_C_COMPILER}" "${VERSION_PREFIX}.${VERSION_SUFFIX}" position REVERSE)
if(-1 EQUAL position)
set(COMPILER_VERSION "${VERSION_PREFIX}.${VERSION_SUFFIX}")
else()
string(SUBSTRING "${CMAKE_C_COMPILER}" ${position} -1 COMPILER_VERSION)
string(FIND "${COMPILER_VERSION}" "/" position)
string(SUBSTRING "${COMPILER_VERSION}" 0 ${position} COMPILER_VERSION)
endif()
else()
string(SUBSTRING ${MSVC_TOOLSET_VERSION} 0 2 COMPILER_VERSION)
endif()
set(COMPILER_VERSION "MSVC ${COMPILER_VERSION}")
if(CMAKE_CL_64)
set(COMPILER_VERSION "${COMPILER_VERSION} x64")
else()
set(COMPILER_VERSION "${COMPILER_VERSION} x86")
endif()
elseif(MINGW)
set(COMPILER_VERSION "MinGW-w64 ${CMAKE_C_COMPILER_VERSION} x64")
else()
if("GNU" STREQUAL "${CMAKE_C_COMPILER_ID}")
set(COMPILER_VERSION "gcc")
elseif("Clang" STREQUAL "${CMAKE_C_COMPILER_ID}")
set(COMPILER_VERSION "clang")
else()
message(WARNING "CMAKE_C_COMPILER_ID -> ${CMAKE_C_COMPILER_ID}")
set(COMPILER_VERSION "${CMAKE_C_COMPILER_ID}")
endif()
if(ANDROID)
set(COMPILER_VERSION "${COMPILER_VERSION} ${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION} ${CMAKE_ANDROID_ARCH} ${CMAKE_ANDROID_ARCH_ABI} ${CMAKE_SYSTEM_PROCESSOR}")
else()
set(COMPILER_VERSION "${COMPILER_VERSION} ${CMAKE_C_COMPILER_VERSION} x64")
endif()
endif()
endmacro()
macro(append_to_flags_from_outside)
if(CMAKE_VERSION VERSION_LESS 3.0)
if(DEFINED ENV{CFLAGS})
list(APPEND CMAKE_C_FLAGS $ENV{CFLAGS})
endif()
if(DEFINED ENV{CPPFLAGS})
list(APPEND CMAKE_CXX_FLAGS $ENV{CPPFLAGS})
endif()
if(DEFINED ENV{CXXFLAGS})
list(APPEND CMAKE_CXX_FLAGS $ENV{CXXFLAGS})
endif()
if(DEFINED ENV{LDFLAGS})
list(APPEND LINK_FLAGS $ENV{LDFLAGS})
endif()
if(DEFINED CFLAGS)
list(APPEND CMAKE_C_FLAGS ${CFLAGS})
endif()
if(DEFINED CPPFLAGS)
list(APPEND CMAKE_CXX_FLAGS ${CPPFLAGS})
endif()
if(DEFINED CXXFLAGS)
list(APPEND CMAKE_CXX_FLAGS ${CXXFLAGS})
endif()
if(DEFINED LDFLAGS)
list(APPEND LINK_FLAGS ${LDFLAGS})
endif()
string(REPLACE ";" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REPLACE ";" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE ";" "" LINK_FLAGS "${LINK_FLAGS}")
endif()
endmacro()
macro(set_position_independent_code)
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
endmacro()