cmake_modules/FindFreepascal.cmake
author Bryan Dunsmore <dunsmoreb@gmail.com>
Sat, 01 Dec 2012 15:40:10 -0600
changeset 8164 b12634f2e1b2
parent 8162 b97a17bf89ec
child 8166 5bc0fc0bab4d
permissions -rw-r--r--
Move noexecstack flags to Freepascal module and refactor.

# 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 supports noexecstack flag -- no")
else()
    message(STATUS "Checking whether linker supports noexecstack flag -- yes")
endif()