1
1
cmake_minimum_required (VERSION 2.8.12 )
2
2
project (CoreFX C )
3
3
4
+ cmake_policy (SET CMP0083 NEW )
5
+
6
+ include (CheckPIESupported )
7
+
8
+ # All code we build should be compiled as position independent
9
+ check_pie_supported (OUTPUT_VARIABLE PIE_SUPPORT_OUTPUT LANGUAGES C )
10
+ if (NOT MSVC AND NOT CMAKE_C_LINK_PIE_SUPPORTED )
11
+ message (WARNING "PIE is not supported at link time: ${PIE_SUPPORT_OUTPUT} .\n "
12
+ "PIE link options will not be passed to linker." )
13
+ endif ()
14
+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
15
+
4
16
set (CMAKE_MACOSX_RPATH ON )
5
17
set (CMAKE_INSTALL_PREFIX $ENV{__CMakeBinDir} )
6
18
set (CMAKE_INCLUDE_CURRENT_DIR ON )
@@ -28,7 +40,6 @@ endif()
28
40
add_compile_options (-Werror )
29
41
30
42
if (CMAKE_SYSTEM_NAME STREQUAL Emscripten )
31
- # Build a static library so no -fPIC
32
43
set (CLR_CMAKE_PLATFORM_WASM 1 )
33
44
add_definitions (-D_WASM_ )
34
45
# The emscripten build has additional warnings so -Werror breaks
@@ -37,7 +48,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
37
48
add_compile_options (-Wno-alloca )
38
49
add_compile_options (-Wno-implicit-int-float-conversion )
39
50
else ()
40
- add_compile_options (-fPIC )
41
51
set (GEN_SHARED_LIB 1 )
42
52
endif (CMAKE_SYSTEM_NAME STREQUAL Emscripten )
43
53
@@ -125,9 +135,6 @@ endif ()
125
135
126
136
if (CMAKE_SYSTEM_NAME STREQUAL Linux )
127
137
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE" )
128
- set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack" )
129
- set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--build-id=sha1" )
130
- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id=sha1" )
131
138
endif ()
132
139
133
140
if (CMAKE_SYSTEM_NAME STREQUAL Linux )
@@ -141,8 +148,7 @@ endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
141
148
if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD )
142
149
set (CLR_CMAKE_PLATFORM_UNIX 1 )
143
150
add_definitions (-D_BSD_SOURCE ) # required for getline
144
- set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld -Xlinker --build-id=sha1" )
145
- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld -Xlinker --build-id=sha1" )
151
+ add_link_options (-fuse-ld=lld )
146
152
endif (CMAKE_SYSTEM_NAME STREQUAL FreeBSD )
147
153
148
154
if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD )
@@ -164,6 +170,12 @@ endif(CMAKE_SYSTEM_NAME STREQUAL SunOS)
164
170
# ./build-native.sh cmakeargs -DCLR_ADDITIONAL_COMPILER_OPTIONS=<...> cmakeargs -DCLR_ADDITIONAL_LINKER_FLAGS=<...>
165
171
#
166
172
if (CLR_CMAKE_PLATFORM_UNIX )
173
+ if (CMAKE_SYSTEM_NAME STREQUAL Darwin )
174
+ add_link_options (-Wl,-bind_at_load )
175
+ else (CMAKE_SYSTEM_NAME STREQUAL Darwin )
176
+ add_compile_options ($< $< COMPILE_LANGUAGE:ASM> :-Wa,--noexecstack> )
177
+ add_link_options (-Wl,--build-id=sha1 -Wl,-z,relro,-z,now )
178
+ endif (CMAKE_SYSTEM_NAME STREQUAL Darwin )
167
179
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CLR_ADDITIONAL_LINKER_FLAGS} " )
168
180
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CLR_ADDITIONAL_LINKER_FLAGS} " )
169
181
add_compile_options (${CLR_ADDITIONAL_COMPILER_OPTIONS} )
0 commit comments