Blob Blame History Raw
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9fd5ee3..19809c9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -23,6 +23,7 @@ ADD_DEFINITIONS(-DHAVE_CONFIG_H)
 
 INCLUDE(CheckIncludeFiles)
 INCLUDE(CheckFunctionExists)
+INCLUDE(CheckCCompilerFlag)
 
 CHECK_INCLUDE_FILES("arpa/inet.h" HAVE_ARPA_INET_H)
 CHECK_INCLUDE_FILES("limits.h" HAVE_LIMITS_H)
@@ -62,6 +63,13 @@ CHECK_FUNCTION_EXISTS(strpbrk HAVE_STRPBRK)
 CHECK_FUNCTION_EXISTS(strrchr HAVE_STRRCHR)
 CHECK_FUNCTION_EXISTS(strstr HAVE_STRSTR)
 
+CHECK_C_COMPILER_FLAG(-fPIE HAVE_FPIE_SUPPORT)
+if (HAVE_FPIE_SUPPORT)
+  set (WEECHAT_PIE_CFLAGS "-fPIE")
+  set (WEECHAT_PIE_LDFLAGS "-pie")
+else(HAVE_FPIE_SUPPORT)
+  message(STATUS "Your compiler doesn't support PIE flag")
+endif(HAVE_FPIE_SUPPORT)
 
 #needs to be splitted in subdirectories
 # FIXME: weechat_gui_common MUST be the first lib in the list
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index c1a22c8..78901f2 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -40,6 +40,8 @@ wee-upgrade-file.c wee-upgrade-file.h
 wee-utf8.c wee-utf8.h
 wee-util.c wee-util.h)
 
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WEECHAT_PIE_CFLAGS}")
+
 # Check for flock support
 INCLUDE(CheckSymbolExists)
 CHECK_INCLUDE_FILES("sys/file.h" HAVE_SYS_FILE_H)
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index c310ded..2f29318 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -36,6 +36,11 @@ gui-main.h
 gui-nicklist.c gui-nicklist.h
 gui-window.c gui-window.h)
 
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WEECHAT_PIE_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS
+    "${CMAKE_EXE_LINKER_FLAGS} ${WEECHAT_PIE_LDFLAGS}")
+
+
 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
 ADD_LIBRARY(weechat_gui_common STATIC ${LIB_GUI_COMMON_SRC})
 
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index e329c30..28ca7fa 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -27,6 +27,9 @@ plugin-config.h plugin-config.c)
 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
 ADD_LIBRARY(weechat_plugins STATIC ${LIB_PLUGINS_SRC})
 
+SET_TARGET_PROPERTIES(weechat_plugins
+  PROPERTIES COMPILE_FLAGS "${WEECHAT_PIE_CFLAGS}")
+
 SET(PLUGIN_INSTALL_DIR lib${LIB_SUFFIX}/${PROJECT_NAME}/plugins)
 
 INCLUDE(CheckIncludeFiles)