# HG changeset patch # User koda # Date 1354402960 -3600 # Node ID 33868aea694ca0c1e8fc9d7ff6b6549fec8041d3 # Parent a1ffcb559f99d5b3e3b9e9d5da26fee50bf04f95# Parent 5bc0fc0bab4d763e596d0508d673c397b3de8f5a GCI2012: Move Freepascal discovery code into a CMake module diff -r a1ffcb559f99 -r 33868aea694c cmake_modules/FindFreepascal.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake_modules/FindFreepascal.cmake Sun Dec 02 00:02:40 2012 +0100 @@ -0,0 +1,34 @@ +# Load Freepascal +if (FPC) + set(FPC_EXECUTABLE ${FPC}) +else() + find_program(FPC_EXECUTABLE + NAMES fpc + PATHS /opt/local/bin /usr/local/bin /usr/bin) +endif() + +# Check Freepascal version +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() + +# 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 needs explicit noexecstack -- no") +else() + message(STATUS "Checking whether linker needs explicit noexecstack -- yes") +endif() diff -r a1ffcb559f99 -r 33868aea694c hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Sun Dec 02 01:26:00 2012 +0400 +++ b/hedgewars/CMakeLists.txt Sun Dec 02 00:02:40 2012 +0100 @@ -12,6 +12,12 @@ set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.pas) set(engine_output_name "hwengine") +if (APPLE) + set(required_fpc_version 2.6) +else() + set(required_fpc_version 2.2) +endif() + set(engine_sources ${hwengine_project} LuaPas.pas @@ -101,54 +107,15 @@ endif(BUILD_ENGINE_LIBRARY) -#PASCAL DETECTION SECTION -if(FPC) - set(fpc_executable ${FPC}) +# Check Freepascal version +find_package(Freepascal) + +if (FPC_VERSION VERSION_LESS required_fpc_version) + message(FATAL_ERROR "Necessary FPC version not found (version >= ${required_fpc_version} required)") else() - find_program(fpc_executable fpc) + message(STATUS "Found FPC: ${FPC_EXECUTABLE} (version ${FPC_VERSION})") endif() -message(STATUS "Check for working FPC compiler: ${fpc_executable}") -execute_process(COMMAND ${fpc_executable} -iV OUTPUT_VARIABLE fpc_output ERROR_VARIABLE fpc_error) -if(fpc_error) - message(STATUS "Check for working FPC compiler: ${fpc_executable} -- broken") -else(fpc_error) - message(STATUS "Check for working FPC compiler: ${fpc_executable} -- works") -endif(fpc_error) - -string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}") -if(fpc_version) - string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}") - string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}") - string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}") - message(STATUS "Found Freepascal: ${fpc_executable} (version ${fpc_vers_major}.${fpc_vers_minor})") - math(EXPR fpc_version "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}") - - if(fpc_version LESS "020200") - message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0") - elseif(APPLE AND (fpc_version LESS "020600")) - message(FATAL_ERROR "Minimum required version of FreePascal is 2.6.0 on Mac OS X") - endif() -else() - message(FATAL_ERROR "No FreePascal compiler found!") -endif() - -message(STATUS "Checking whether linker supports noexecstack flag") -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 testnoexecstack - OUTPUT_QUIET ERROR_QUIET - ) - -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)