Move code for Freepascal to separate CMake module.
authorBryan Dunsmore <dunsmoreb@gmail.com>
Fri, 30 Nov 2012 23:08:10 -0600
changeset 8162 b97a17bf89ec
parent 8159 e226be871b6e
child 8164 b12634f2e1b2
Move code for Freepascal to separate CMake module.
cmake_modules/FindFreepascal.cmake
hedgewars/CMakeLists.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/FindFreepascal.cmake	Fri Nov 30 23:08:10 2012 -0600
@@ -0,0 +1,18 @@
+# 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()
--- a/hedgewars/CMakeLists.txt	Fri Nov 30 23:36:18 2012 +0100
+++ b/hedgewars/CMakeLists.txt	Fri Nov 30 23:08:10 2012 -0600
@@ -11,6 +11,7 @@
 #SOURCE AND PROGRAMS SECTION
 set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.pas)
 set(engine_output_name "hwengine")
+SET(REQUIRED_FPC_VERSION 2.2)
 
 set(engine_sources
     ${hwengine_project}
@@ -101,37 +102,18 @@
 endif(BUILD_ENGINE_LIBRARY)
 
 
-#PASCAL DETECTION SECTION
-if(FPC)
-    set(fpc_executable ${FPC})
-else()
-    find_program(fpc_executable fpc)
-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)
+# Check Freepascal version
+FIND_PACKAGE(Freepascal)
 
-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 VERSION_GREATER REQUIRED_FPC_VERSION
+    OR FPC_VERSION VERSION_EQUAL REQUIRED_FPC_VERSION)
+    MESSAGE(STATUS "Found FPC: ${FPC_EXECUTABLE} (version ${FPC_VERSION})")
+ELSEIF (APPLE AND FPC_VERSION VERSION_LESS 2.6)
+    MESSAGE(FATAL_ERROR "Necessary FPC version not found (version >= 2.6 required)")
+ELSE()
+    MESSAGE(FATAL_ERROR "Necessary FPC version not found (version >= ${REQUIRED_FPC_VERSION} required)")
+ENDIF()
 
-    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")