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.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8162
b97a17bf89ec Move code for Freepascal to separate CMake module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents:
diff changeset
     1
# Load Freepascal
8164
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
     2
if (FPC)
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
     3
    set(FPC_EXECUTABLE ${FPC})
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
     4
else()
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
     5
    find_program(FPC_EXECUTABLE
8162
b97a17bf89ec Move code for Freepascal to separate CMake module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents:
diff changeset
     6
        NAMES fpc
b97a17bf89ec Move code for Freepascal to separate CMake module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents:
diff changeset
     7
        PATHS /opt/local/bin /usr/local/bin /usr/bin)
8164
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
     8
endif()
8162
b97a17bf89ec Move code for Freepascal to separate CMake module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents:
diff changeset
     9
b97a17bf89ec Move code for Freepascal to separate CMake module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents:
diff changeset
    10
# Check Freepascal version
8164
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    11
if (FPC_EXECUTABLE)
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    12
    exec_program(${FPC_EXECUTABLE} ARGS "-v" OUTPUT_VARIABLE FPC_VERSION_FULL)
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    13
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    14
    string(REGEX MATCH "[0-9]+\\.[0-9]+" FPC_VERSION_LONG "${FPC_VERSION_FULL}")
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    15
    string(REGEX REPLACE "([0-9]+\\.[0-9]+)" "\\1" FPC_VERSION "${FPC_VERSION_LONG}")
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    16
else()
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    17
    message(FATAL_ERROR "Freepascal not found (required for hedgewars)")
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    18
endif()
8162
b97a17bf89ec Move code for Freepascal to separate CMake module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents:
diff changeset
    19
8164
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    20
# Check for noexecstack flag support
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    21
set(NOEXECSTACK_FLAGS "-k-z" "-knoexecstack")
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    22
file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    23
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    24
execute_process(COMMAND ${FPC_EXECUTABLE} ${NOEXECSTACK_FLAGS} checkstack.pas
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    25
    WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    26
    RESULT_VARIABLE TEST_NOEXECSTACK
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    27
    OUTPUT_QUIET ERROR_QUIET)
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    28
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    29
if (TEST_NOEXECSTACK)
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    30
    set(NOEXECSTACK_FLAGS "")
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    31
    message(STATUS "Checking whether linker supports noexecstack flag -- no")
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    32
else()
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    33
    message(STATUS "Checking whether linker supports noexecstack flag -- yes")
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    34
endif()