11cmake_minimum_required (VERSION 2.8.12)
22project (CoreFX C)
33
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+
416set (CMAKE_MACOSX_RPATH ON )
517set (CMAKE_INSTALL_PREFIX $ENV{__CMakeBinDir} )
618set (CMAKE_INCLUDE_CURRENT_DIR ON )
@@ -28,7 +40,6 @@ endif()
2840add_compile_options (-Werror)
2941
3042if (CMAKE_SYSTEM_NAME STREQUAL Emscripten)
31- # Build a static library so no -fPIC
3243 set (CLR_CMAKE_PLATFORM_WASM 1)
3344 add_definitions (-D_WASM_)
3445 # The emscripten build has additional warnings so -Werror breaks
@@ -37,7 +48,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
3748 add_compile_options (-Wno-alloca)
3849 add_compile_options (-Wno-implicit-int-float-conversion)
3950else ()
40- add_compile_options (-fPIC)
4151 set (GEN_SHARED_LIB 1)
4252endif (CMAKE_SYSTEM_NAME STREQUAL Emscripten)
4353
@@ -125,9 +135,6 @@ endif ()
125135
126136if (CMAKE_SYSTEM_NAME STREQUAL Linux)
127137 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" )
131138endif ()
132139
133140if (CMAKE_SYSTEM_NAME STREQUAL Linux)
@@ -141,8 +148,7 @@ endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
141148if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
142149 set (CLR_CMAKE_PLATFORM_UNIX 1)
143150 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)
146152endif (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
147153
148154if (CMAKE_SYSTEM_NAME STREQUAL OpenBSD)
@@ -164,6 +170,12 @@ endif(CMAKE_SYSTEM_NAME STREQUAL SunOS)
164170# ./build-native.sh cmakeargs -DCLR_ADDITIONAL_COMPILER_OPTIONS=<...> cmakeargs -DCLR_ADDITIONAL_LINKER_FLAGS=<...>
165171#
166172if (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)
167179 set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CLR_ADDITIONAL_LINKER_FLAGS} " )
168180 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CLR_ADDITIONAL_LINKER_FLAGS} " )
169181 add_compile_options (${CLR_ADDITIONAL_COMPILER_OPTIONS} )
0 commit comments