introduce find_package_or_fail/disable to group together similar cmake code
authorkoda
Thu, 07 Mar 2013 10:14:12 +0100
changeset 8686 d303da4568b7
parent 8685 c0e54583296e
child 8687 5b6ad1bd6ace
introduce find_package_or_fail/disable to group together similar cmake code
CMakeLists.txt
QTfrontend/CMakeLists.txt
cmake_modules/utils.cmake
gameServer/CMakeLists.txt
hedgewars/CMakeLists.txt
--- a/CMakeLists.txt	Thu Mar 07 10:11:07 2013 +0100
+++ b/CMakeLists.txt	Thu Mar 07 10:14:12 2013 +0100
@@ -19,8 +19,8 @@
 
 
 #possible cmake configuration
-option(NOSERVER "Disable gameServer build [default: auto]" OFF)
-option(NOPNG "Disable screenshoot compression [default: auto]" OFF)
+option(NOSERVER "Disable gameServer build [default: off]" OFF)
+option(NOPNG "Disable screenshoot compression [default: off]" OFF)
 option(NOVIDEOREC "Disable video recording [default: off]" OFF)
 
 #set this to ON when 2.1.0 becomes more widespread (and only for linux)
@@ -282,6 +282,7 @@
                               )
 endif()
 
+include(${CMAKE_MODULE_PATH}/utils.cmake)
 
 #lua discovery
 find_package(Lua)
@@ -331,11 +332,9 @@
 endif()
 
 if(NOT NOVIDEOREC)
-    find_package(FFMPEG)
-    if(NOT ${FFMPEG_FOUND})
-        message(FATAL_ERROR "Missing FFMPEG/Libav! Rerun cmake with -DNOVIDEOREC=on to disable video recording")
-    endif()
+    find_package_or_disable(FFMPEG NOVIDEOREC)
 else()
+    message(STATUS "Video recording disabled")
     set(FFMPEG_FOUND false)
 endif()
 
--- a/QTfrontend/CMakeLists.txt	Thu Mar 07 10:11:07 2013 +0100
+++ b/QTfrontend/CMakeLists.txt	Thu Mar 07 10:14:12 2013 +0100
@@ -167,15 +167,14 @@
                          util/platform/NSWorkspace_RBAdditions.m
                          )
     if(NOT NOAUTOUPDATE)
-        find_package(Sparkle)
-        if(SPARKLE_FOUND)
-            add_definitions(-DSPARKLE_ENABLED)
-            list(APPEND hwfr_src util/platform/AutoUpdater.cpp
-                                 util/platform/SparkleAutoUpdater.mm)
-            list(APPEND HW_LINK_LIBS ${SPARKLE_LIBRARY})
-        else()
-            message(FATAL_ERROR "Missing Sparkle! Rerun cmake with -DNOAUTOUPDATE=on to disable autoupdating")
-        endif()
+        include(${CMAKE_MODULE_PATH}/utils.cmake)
+        find_package_or_disable(Sparkle NOAUTOUPDATE)
+        add_definitions(-DSPARKLE_ENABLED)
+        list(APPEND hwfr_src util/platform/AutoUpdater.cpp
+                             util/platform/SparkleAutoUpdater.mm)
+        list(APPEND HW_LINK_LIBS ${SPARKLE_LIBRARY})
+    else()
+        message(STATUS "Sparkle autoupdater disabled")
     endif()
 endif()
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake_modules/utils.cmake	Thu Mar 07 10:14:12 2013 +0100
@@ -0,0 +1,19 @@
+
+macro(find_package_or_fail _PKG_NAME)
+    find_package(${_PKG_NAME})
+    string(TOUPPER ${_PKG_NAME} _PKG_NAME_UP)
+    if(NOT ${_PKG_NAME_UP}_FOUND)
+        message(SEND_ERROR "Missing ${_PKG_NAME}! Please install it and rerun cmake.")
+    endif(NOT ${_PKG_NAME_UP}_FOUND)
+endmacro(find_package_or_fail _PKG_NAME)
+
+macro(find_package_or_disable _PKG_NAME _VAR_NAME)
+    find_package(${_PKG_NAME})
+    string(TOUPPER ${_PKG_NAME} _PKG_NAME_UP)
+    if(NOT ${_PKG_NAME_UP}_FOUND)
+        message(SEND_ERROR "Missing ${_PKG_NAME}! Rerun cmake with -D${_VAR_NAME}=1 to build without it.")
+    endif(NOT ${_PKG_NAME_UP}_FOUND)
+endmacro(find_package_or_disable _PKG_NAME _VAR_NAME)
+
+#TODO: find_package_or_bundle
+
--- a/gameServer/CMakeLists.txt	Thu Mar 07 10:11:07 2013 +0100
+++ b/gameServer/CMakeLists.txt	Thu Mar 07 10:14:12 2013 +0100
@@ -1,8 +1,7 @@
 
-find_package(GHC REQUIRED)
-if(NOT ${GHC_FOUND})
-    message(FATAL_ERROR "Missing Glasgow Haskell Compiler! Rerun cmake with -DNOSERVER=on to disable hosting LAN games")
-endif()
+include(${CMAKE_MODULE_PATH}/utils.cmake)
+
+find_package_or_disable(GHC NOSERVER)
 
 set(hwserver_sources
     OfficialServer/DBInteraction.hs
--- a/hedgewars/CMakeLists.txt	Thu Mar 07 10:11:07 2013 +0100
+++ b/hedgewars/CMakeLists.txt	Thu Mar 07 10:14:12 2013 +0100
@@ -120,7 +120,10 @@
 endif(${BUILD_ENGINE_LIBRARY})
 
 
-find_package(FreePascal REQUIRED)
+include(${CMAKE_MODULE_PATH}/utils.cmake)
+
+find_package_or_fail(FreePascal)
+
 #when cmake-2.6 support is dropped, this ought to be inside FindFreePascal.cmake
 if (FREEPASCAL_VERSION VERSION_LESS required_fpc_version)
     message(FATAL_ERROR "Freepascal ${FREEPASCAL_VERSION} is too old, minimum version required is ${required_fpc_version}")
@@ -163,17 +166,10 @@
 endif(APPLE)
 
 if(NOT NOPNG)
-    find_package(PNG)
-    if(${PNG_FOUND})
-        list(APPEND pascal_flags "-dPNG_SCREENSHOTS")
-        if(APPLE)  # fpc png unit doesn't pull the library (see bug 21833)
-            list(APPEND pascal_flags "-k${PNG_LIBRARY}")
-        endif()
-    else()
-        message(${WARNING} "Screenshots will be in BMP format because libpng was not found")
-    endif()
+    find_package_or_disable(PNG NOPNG)
+    list(APPEND pascal_flags "-dPNG_SCREENSHOTS")
 else()
-    message(STATUS "Screenshots will be in BMP format per user request")
+    message(STATUS "PNG screenshots disabled, using BMP format")
 endif()