cmake_modules/FindFreepascal.cmake
author Drew Gottlieb
Wed, 05 Dec 2012 18:12:07 +0100
branchflibqtfrontend
changeset 8222 d3dc08500fc0
parent 8195 37d47f09f981
child 8283 af97cdbb7713
permissions -rw-r--r--
GCI2012: Remove Quit Prompt On Mouse Click
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}")
8195
37d47f09f981 caught a few more possible glitches in engine cmakefile
koda
parents: 8188
diff changeset
    16
    message(STATUS "Found Freepascal: ${FPC_EXECUTABLE} (version ${FPC_VERSION}")
8164
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    17
else()
8195
37d47f09f981 caught a few more possible glitches in engine cmakefile
koda
parents: 8188
diff changeset
    18
    message(FATAL_ERROR "Could NOT find Freepascal")
8164
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    19
endif()
8162
b97a17bf89ec Move code for Freepascal to separate CMake module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents:
diff changeset
    20
8164
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    21
# Check for noexecstack flag support
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    22
set(NOEXECSTACK_FLAGS "-k-z" "-knoexecstack")
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    23
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
    24
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    25
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
    26
    WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    27
    RESULT_VARIABLE TEST_NOEXECSTACK
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    28
    OUTPUT_QUIET ERROR_QUIET)
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    29
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    30
if (TEST_NOEXECSTACK)
b12634f2e1b2 Move noexecstack flags to Freepascal module and refactor.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8162
diff changeset
    31
    set(NOEXECSTACK_FLAGS "")
8166
5bc0fc0bab4d Refactor Freepascal module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8164
diff changeset
    32
    message(STATUS "Checking whether linker needs explicit noexecstack -- no")
8188
4c166505e5c8 fix compiling engine (bug introduced in r33868aea694c)
koda
parents: 8166
diff changeset
    33
else(TEST_NOEXECSTACK)
8166
5bc0fc0bab4d Refactor Freepascal module.
Bryan Dunsmore <dunsmoreb@gmail.com>
parents: 8164
diff changeset
    34
    message(STATUS "Checking whether linker needs explicit noexecstack -- yes")
8188
4c166505e5c8 fix compiling engine (bug introduced in r33868aea694c)
koda
parents: 8166
diff changeset
    35
endif(TEST_NOEXECSTACK)
8195
37d47f09f981 caught a few more possible glitches in engine cmakefile
koda
parents: 8188
diff changeset
    36