cmake_modules/FindFreepascal.cmake
author O. Michael Hartman
Sun, 02 Dec 2012 15:23:59 +0100
changeset 8185 1c3739ba4352
parent 8166 5bc0fc0bab4d
child 8188 4c166505e5c8
permissions -rw-r--r--
GCI2012: Check for Non-Standard Recorder Framerate
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 "")
8166
5bc0fc0bab4d Refactor Freepascal module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8164
diff changeset
    31
    message(STATUS "Checking whether linker needs explicit noexecstack -- no")
8164
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    32
else()
8166
5bc0fc0bab4d Refactor Freepascal module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8164
diff changeset
    33
    message(STATUS "Checking whether linker needs explicit noexecstack -- yes")
8164
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    34
endif()