Move noexecstack flags to Freepascal module and refactor.
--- a/cmake_modules/FindFreepascal.cmake Fri Nov 30 23:08:10 2012 -0600
+++ b/cmake_modules/FindFreepascal.cmake Sat Dec 01 15:40:10 2012 -0600
@@ -1,18 +1,34 @@
# Load Freepascal
-IF (FPC)
- SET(FPC_EXECUTABLE ${FPC})
-ELSE()
- FIND_PROGRAM(FPC_EXECUTABLE
+if (FPC)
+ set(FPC_EXECUTABLE ${FPC})
+else()
+ find_program(FPC_EXECUTABLE
NAMES fpc
PATHS /opt/local/bin /usr/local/bin /usr/bin)
-ENDIF()
+endif()
# Check Freepascal version
-IF (FPC_EXECUTABLE)
- EXEC_PROGRAM(${FPC_EXECUTABLE} ARGS "-v" OUTPUT_VARIABLE FPC_VERSION_FULL)
+if (FPC_EXECUTABLE)
+ exec_program(${FPC_EXECUTABLE} ARGS "-v" OUTPUT_VARIABLE FPC_VERSION_FULL)
+
+ string(REGEX MATCH "[0-9]+\\.[0-9]+" FPC_VERSION_LONG "${FPC_VERSION_FULL}")
+ string(REGEX REPLACE "([0-9]+\\.[0-9]+)" "\\1" FPC_VERSION "${FPC_VERSION_LONG}")
+else()
+ message(FATAL_ERROR "Freepascal not found (required for hedgewars)")
+endif()
- STRING(REGEX MATCH "[0-9]+\\.[0-9]+" FPC_VERSION_LONG "${FPC_VERSION_FULL}")
- STRING(REGEX REPLACE "([0-9]+\\.[0-9]+)" "\\1" FPC_VERSION "${FPC_VERSION_LONG}")
-ELSE()
- MESSAGE(FATAL_ERROR "Freepascal not found (required for hedgewars)")
-ENDIF()
+# Check for noexecstack flag support
+set(NOEXECSTACK_FLAGS "-k-z" "-knoexecstack")
+file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
+
+execute_process(COMMAND ${FPC_EXECUTABLE} ${NOEXECSTACK_FLAGS} checkstack.pas
+ WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
+ RESULT_VARIABLE TEST_NOEXECSTACK
+ OUTPUT_QUIET ERROR_QUIET)
+
+if (TEST_NOEXECSTACK)
+ set(NOEXECSTACK_FLAGS "")
+ message(STATUS "Checking whether linker supports noexecstack flag -- no")
+else()
+ message(STATUS "Checking whether linker supports noexecstack flag -- yes")
+endif()
--- a/hedgewars/CMakeLists.txt Fri Nov 30 23:08:10 2012 -0600
+++ b/hedgewars/CMakeLists.txt Sat Dec 01 15:40:10 2012 -0600
@@ -11,7 +11,7 @@
#SOURCE AND PROGRAMS SECTION
set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.pas)
set(engine_output_name "hwengine")
-SET(REQUIRED_FPC_VERSION 2.2)
+set(required_fpc_version 2.2)
set(engine_sources
${hwengine_project}
@@ -103,34 +103,20 @@
# Check Freepascal version
-FIND_PACKAGE(Freepascal)
-
-IF (FPC_VERSION VERSION_GREATER REQUIRED_FPC_VERSION
- OR FPC_VERSION VERSION_EQUAL REQUIRED_FPC_VERSION)
- MESSAGE(STATUS "Found FPC: ${FPC_EXECUTABLE} (version ${FPC_VERSION})")
-ELSEIF (APPLE AND FPC_VERSION VERSION_LESS 2.6)
- MESSAGE(FATAL_ERROR "Necessary FPC version not found (version >= 2.6 required)")
-ELSE()
- MESSAGE(FATAL_ERROR "Necessary FPC version not found (version >= ${REQUIRED_FPC_VERSION} required)")
-ENDIF()
-
+find_package(Freepascal)
-message(STATUS "Checking whether linker supports noexecstack flag")
-set(noexecstack_flags "-k-z" "-knoexecstack")
-file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
+if (NOT APPLE)
+ if (FPC_VERSION VERSION_LESS required_fpc_version)
+ message(FATAL_ERROR "Necessary FPC version not found (version >= ${required_fpc_version} required)")
+ endif()
+elseif (APPLE)
+ if (FPC_VERSION VERSION_LESS 2.6)
+ message(FATAL_ERROR "Necessary FPC version not found (version >= 2.6 required)")
+ endif()
+endif()
-execute_process(COMMAND ${fpc_executable} ${noexecstack_flags} checkstack.pas
- WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
- RESULT_VARIABLE testnoexecstack
- OUTPUT_QUIET ERROR_QUIET
- )
+message(STATUS "Found FPC: ${FPC_EXECUTABLE} (version ${FPC_VERSION})")
-if(${testnoexecstack})
- set (noexecstack_flags "")
- message(STATUS "Checking whether linker supports noexecstack flag -- no")
-else(${testnoexecstack})
- message(STATUS "Checking whether linker supports noexecstack flag -- yes")
-endif(${testnoexecstack})
#DEPENDECIES AND EXECUTABLES SECTION
if(APPLE)