--- a/CMakeLists.txt Thu Jun 13 14:44:28 2013 +0200
+++ b/CMakeLists.txt Thu Jun 13 15:37:52 2013 +0200
@@ -53,7 +53,8 @@
message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})")
-
+#general utilities
+include(${CMAKE_MODULE_PATH}/utils.cmake)
#platform specific init code
include(${CMAKE_MODULE_PATH}/platform.cmake)
include(${CMAKE_MODULE_PATH}/paths.cmake)
@@ -138,7 +139,6 @@
)
endif()
-include(${CMAKE_MODULE_PATH}/utils.cmake)
#lua discovery
if (${LUA_SYSTEM})
--- a/cmake_modules/compilerchecks.cmake Thu Jun 13 14:44:28 2013 +0200
+++ b/cmake_modules/compilerchecks.cmake Thu Jun 13 15:37:52 2013 +0200
@@ -33,32 +33,21 @@
set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack")
check_c_compiler_flag("" HAVE_NOEXECSTACK)
if(HAVE_NOEXECSTACK)
- list(APPEND pascal_flags "-k-z" "-knoexecstack")
- list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+ append_linker_flag("-znoexecstack")
endif()
#check for full relro on ELF, Debian security
-set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now")
+set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro,-znow")
check_c_compiler_flag("" HAVE_RELROFULL)
if(HAVE_RELROFULL)
- list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know")
- list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+ append_linker_flag("-zrelro")
+ append_linker_flag("-znow")
else()
#if full relro is not available, try partial relro
- set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro")
+ set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro")
check_c_compiler_flag("" HAVE_RELROPARTIAL)
if(HAVE_RELROPARTIAL)
- list(APPEND pascal_flags "-k-z" "-krelro")
- list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+ append_linker_flag("-zrelro")
endif()
endif()
@@ -66,33 +55,21 @@
set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
check_c_compiler_flag("" HAVE_WINASLR)
if(HAVE_WINASLR)
- list(APPEND pascal_flags "-k--nxcompat")
- list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+ append_linker_flag("--nxcompat")
endif()
#check for DEP on Windows XP SP2 or later, requires binutils >= 2.20
set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
check_c_compiler_flag("" HAVE_WINDEP)
if(HAVE_WINDEP)
- list(APPEND pascal_flags "-k--dynamicbase")
- list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+ append_linker_flag("--dynamicbase")
endif()
#this is actually an optimisation
set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed")
check_c_compiler_flag("" HAVE_ASNEEDED)
if(HAVE_ASNEEDED)
- list(APPEND pascal_flags "-k--as-needed")
- list(APPEND haskell_flags "-optl" "${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
- set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
+ append_linker_flag("--as-needed")
endif()
#always unset or these flags will be spread everywhere
--- a/cmake_modules/paths.cmake Thu Jun 13 14:44:28 2013 +0200
+++ b/cmake_modules/paths.cmake Thu Jun 13 15:37:52 2013 +0200
@@ -50,11 +50,11 @@
set(CMAKE_INSTALL_RPATH_ESCAPED "$$ORIGIN/../${target_library_install_dir}/:$$ORIGIN/:${CMAKE_INSTALL_PREFIX}/${target_library_install_dir}/")
if(UNIX AND NOT APPLE)
- list(APPEND pascal_flags "-k-rpath" "-k'${CMAKE_INSTALL_RPATH_ESCAPED}'" "-k-z" "-korigin")
- list(APPEND haskell_flags "-optl" "-Wl,-rpath,'${CMAKE_INSTALL_RPATH_ESCAPED},-z,origin'")
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
- set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} -Wl,-z,origin")
- set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} -Wl,-z,origin")
+ #make sure $ORIGIN is respected
+ append_linker_flag("-zorigin")
+ #apply RPATH settings to pascal and haskell executables
+ list(APPEND pascal_flags "-k-rpath" "-k'${CMAKE_INSTALL_RPATH_ESCAPED}'")
+ list(APPEND haskell_flags "-optl" "-Wl,-rpath,'${CMAKE_INSTALL_RPATH_ESCAPED}'")
endif()
#add the automatically determined parts of the RPATH
--- a/cmake_modules/utils.cmake Thu Jun 13 14:44:28 2013 +0200
+++ b/cmake_modules/utils.cmake Thu Jun 13 15:37:52 2013 +0200
@@ -25,6 +25,13 @@
endif(NOT ${_VAR_NAME})
endmacro(find_package_or_disable_msg _PKG_NAME _VAR_NAME _MSG)
+macro(append_linker_flag _FLAG)
+ list(APPEND pascal_flags "-k${_FLAG}")
+ list(APPEND haskell_flags "-optl" "${_FLAG}")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,${_FLAG}")
+ set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} -Wl,${_FLAG}")
+ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} -Wl,${_FLAG}")
+endmacro(append_linker_flag _FLAG)
#TODO: find_package_or_bundle