countless small optimisation for cmake, output messages are now coherent (mostly) and the options get fully respected (eg. skipping library search if not activated)
authorkoda
Thu, 25 Oct 2012 05:06:00 +0200
changeset 7817 6cc558a69b58
parent 7816 a25e943dd4b0
child 7818 7b8b1a634a5b
countless small optimisation for cmake, output messages are now coherent (mostly) and the options get fully respected (eg. skipping library search if not activated)
CMakeLists.txt
QTfrontend/CMakeLists.txt
cmake_modules/FindSDL_Extras.cmake
hedgewars/CMakeLists.txt
tools/CMakeLists.txt
tools/CreateMacBundle.cmake.in
--- a/CMakeLists.txt	Thu Oct 25 01:16:13 2012 +0200
+++ b/CMakeLists.txt	Thu Oct 25 05:06:00 2012 +0200
@@ -227,9 +227,9 @@
 #lua discovery
 find_package(Lua)
 if(LUA_FOUND)
-    message(STATUS "LUA found: ${LUA_DEFAULT}")
+    message(STATUS "Found LUA: ${LUA_DEFAULT}")
 else()
-    message(STATUS "Cound NOT find LUA, building bundled dependency")
+    message(STATUS "LUA will be provided by the bundled sources")
     add_subdirectory(misc/liblua)
     #linking with liblua.a requires system readline -- this works everywhere, right?
     set(pascal_flags "-k${EXECUTABLE_OUTPUT_PATH}/lib${LUA_LIBRARY}.a" "-k-lreadline" ${pascal_flags})
--- a/QTfrontend/CMakeLists.txt	Thu Oct 25 01:16:13 2012 +0200
+++ b/QTfrontend/CMakeLists.txt	Thu Oct 25 05:06:00 2012 +0200
@@ -28,7 +28,9 @@
 # Configure for SDL
 find_package(SDL REQUIRED)
 find_package(SDL_mixer REQUIRED)
-find_package(FFMPEG)
+if(NOT NOVIDEOREC)
+    find_package(FFMPEG)
+endif()
 
 include_directories(.)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/model)
@@ -73,7 +75,7 @@
 file(GLOB_RECURSE UIcpp ui/*.cpp)
 file(GLOB UtilCpp util/*.cpp)
 
-if((NOT NOVIDEOREC) AND "${FFMPEG_FOUND}")
+if(${FFMPEG_FOUND})
     add_definitions(-DVIDEOREC -D__STDC_CONSTANT_MACROS)
 endif()
 
--- a/cmake_modules/FindSDL_Extras.cmake	Thu Oct 25 01:16:13 2012 +0200
+++ b/cmake_modules/FindSDL_Extras.cmake	Thu Oct 25 05:06:00 2012 +0200
@@ -12,7 +12,7 @@
     math(EXPR sdlmixer_version "${sdlmixer_majorversion}*10000 + ${sdlmixer_minorversion}*100 + ${sdlmixer_patchversion}")
 
     if(sdlmixer_version GREATER "10209")
-        message(STATUS "SDL_mixer - Mix_Init() found")
+        message(STATUS "Mix_Init() is present")
         set(pascal_flags "-dSDL_MIXER_NEWER" ${pascal_flags})
     endif()
 endif()
@@ -29,7 +29,7 @@
     math(EXPR sdlimage_version "${sdlimage_majorversion}*10000 + ${sdlimage_minorversion}*100 + ${sdlimage_patchversion}")
 
     if(sdlimage_version GREATER "010207")
-        message(STATUS "SDL_image - IMG_Init() found")
+        message(STATUS "IMG_Init() is present")
         set(pascal_flags "-dSDL_IMAGE_NEWER" ${pascal_flags})
     endif()
 endif()
--- a/hedgewars/CMakeLists.txt	Thu Oct 25 01:16:13 2012 +0200
+++ b/hedgewars/CMakeLists.txt	Thu Oct 25 05:06:00 2012 +0200
@@ -3,8 +3,6 @@
 find_package(SDL_net)
 find_package(SDL_ttf)
 find_package(SDL_mixer)
-set(FFMPEG_FIND_QUIETLY true)
-find_package(FFMPEG)
 
 include(${CMAKE_MODULE_PATH}/FindSDL_Extras.cmake)
 
@@ -163,7 +161,7 @@
     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 "Freepascal version installed: ${fpc_vers_major}.${fpc_vers_minor}")
+    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 LESS "020200")
@@ -181,9 +179,8 @@
     find_package(PNG)
     if(${PNG_FOUND})
         set(pascal_flags "-dPNG_SCREENSHOTS" ${pascal_flags})
-        if(APPLE)  # easier to explictly link with the static lib
-            string(REGEX REPLACE "(.*)libpng.*" "\\1" PNG_LIBDIR "${PNG_LIBRARY}")
-            set(pascal_flags "-k${PNG_LIBDIR}/libpng.a" ${pascal_flags})
+        if(APPLE)  # fpc png unit doesn't pull the library (see bug 21833)
+            set(pascal_flags "-k${PNG_LIBRARY}" ${pascal_flags})
         endif()
     else()
         message(STATUS "Screenshots will be in BMP format because libpng was not found")
@@ -201,6 +198,8 @@
 
 
 if(NOT NOVIDEOREC)
+    set(FFMPEG_FIND_QUIETLY true)
+    find_package(FFMPEG)
     if(${FFMPEG_FOUND})
         include_directories(${FFMPEG_INCLUDE_DIR})
         set(pascal_flags "-dUSE_VIDEO_RECORDING" ${pascal_flags})
@@ -262,10 +261,8 @@
 endif()
 
 #this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6
-if(fpc_version LESS "020600")
-    if(NO_VIDEOREC OR NOT ${FFMPEG_FOUND})
-        add_dependencies(${engine_output_name} ENGINECLEAN)
-    endif()
+if((fpc_version LESS "020600") AND (NOVIDEOREC OR NOT ${FFMPEG_FOUND}))
+    add_dependencies(${engine_output_name} ENGINECLEAN)
 endif()
 
 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir})
--- a/tools/CMakeLists.txt	Thu Oct 25 01:16:13 2012 +0200
+++ b/tools/CMakeLists.txt	Thu Oct 25 05:06:00 2012 +0200
@@ -1,48 +1,54 @@
 if (NOT APPLE)
-	configure_file(	"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
-			"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
-			IMMEDIATE @ONLY)
+    configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
+                   "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+                    IMMEDIATE @ONLY)
 
-	add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
+    add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
 endif()
 
 if (APPLE)
-	find_package(Qt4 REQUIRED)
-	find_package(SDL REQUIRED)
-	find_package(SDL_image REQUIRED)
-	find_package(SDL_net REQUIRED)
-	find_package(SDL_ttf REQUIRED)
-	find_package(SDL_mixer REQUIRED)
-	find_package(OGGVORBIS REQUIRED)
-        if(NOT NOAUTOUPDATE)
-		#needed for SPARKLE_FOUND variable
-		find_package(Sparkle QUIET)
-		#needed because the 'if' clause in the script prints silly policy warnings
-		if(${SPARKLE_FOUND})
-			set(SPARKLE_FOUND 1)
-		else()
-			set(SPARKLE_FOUND 0)
-		endif()
-	endif()
+    find_package(Qt4 REQUIRED QUIET)
+    find_package(SDL REQUIRED)
+    find_package(SDL_image REQUIRED)
+    find_package(SDL_net REQUIRED)
+    find_package(SDL_ttf REQUIRED)
+    find_package(SDL_mixer REQUIRED)
+    find_package(OGGVORBIS REQUIRED)
+    if(NOT NOAUTOUPDATE)
+        #needed for SPARKLE_FOUND variable
+        find_package(Sparkle QUIET)
+        #needed because the 'if' clause in the script prints silly policy warnings
+        if(${SPARKLE_FOUND})
+            set(SPARKLE_FOUND 1)
+        else()
+            set(SPARKLE_FOUND 0)
+        endif()
+    endif()
+
+    #use the associated tool from the libraries we've selected
+    string(REGEX REPLACE "(.*)/include.*" "\\1" qt_base_dir "${QT_INCLUDE_DIR}")
 
-	#use the associated tool from the libraries we've selected
-	string(REGEX REPLACE "(.*)/include.*" "\\1" qt_base_dir "${QT_INCLUDE_DIR}")
+    #remove the ";-framework Cocoa" from the SDL_LIBRARY variable
+    string(REGEX REPLACE "(.*);-.*" "\\1" sdl_dir "${SDL_LIBRARY}")
 
-	#remove the ";-framework Cocoa" from the SDL_LIBRARY variable
-	string(REGEX REPLACE "(.*);-.*" "\\1" sdl_dir "${SDL_LIBRARY}")
+    if(NOT NOPNG)
+        #get the neme of the library (harmelss if it is static)
+        string(REGEX REPLACE ".*/(.*)$" "\\1" PNG_LIBNAME "${PNG_LIBRARY}")
+    endif()
 
-	#this tool is present in qt 4.5 but only if you compile from sources; from qt 4.6 is present also in the binary version
-	find_program(macdeployqt_executable NAMES macdeployqt macdeployqt-mac PATHS ${qt_base_dir}/bin)
-	if(NOT macdeployqt_executable)
-		message(FATAL_ERROR "The utility macdeployqt is required to create the bundle (seached: ${qt_base_dir})")
-	else()
-		message(STATUS "macdeployqt found in ${macdeployqt_executable}")
-	endif()
+    #this tool is present in qt 4.5 but only if you compile from sources
+    #from qt 4.6 is present also in the binary version
+    find_program(macdeployqt_executable NAMES macdeployqt macdeployqt-mac PATHS ${qt_base_dir}/bin)
+    if(NOT macdeployqt_executable)
+        message(FATAL_ERROR "The utility macdeployqt is required to create the bundle (seached: ${qt_base_dir})")
+    else()
+        message(STATUS "Found macdeployqt: ${macdeployqt_executable}")
+    endif()
 
-	#dummy target, we're interested in the postscript file
-	add_custom_target(bundle)
-	set_target_properties(bundle PROPERTIES POST_INSTALL_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/CreateMacBundle.cmake)
+    #dummy target, we're interested in the postscript file
+    add_custom_target(bundle)
+    set_target_properties(bundle PROPERTIES POST_INSTALL_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/CreateMacBundle.cmake)
 
-	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CreateMacBundle.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CreateMacBundle.cmake)
+    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CreateMacBundle.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CreateMacBundle.cmake)
 endif()
 
--- a/tools/CreateMacBundle.cmake.in	Thu Oct 25 01:16:13 2012 +0200
+++ b/tools/CreateMacBundle.cmake.in	Thu Oct 25 05:06:00 2012 +0200
@@ -1,14 +1,22 @@
 message(STATUS "Performing standalone bundle creation...")
 
 execute_process(COMMAND ls ${frameworks_dir} RESULT_VARIABLE doBundle OUTPUT_QUIET ERROR_QUIET)
-
 execute_process(COMMAND mkdir -p ${frameworks_dir})
 # macdeployqt will convert safely any absolute path library for 'hedgewars'
 execute_process(COMMAND ${macdeployqt_executable} ${CMAKE_BINARY_DIR}/${bundle_name} OUTPUT_QUIET ERROR_QUIET)
-# but macdeployqt will not work for 'hwengine'; luckily the dylibs were already updated before
-execute_process(COMMAND install_name_tool -change ${FFMPEG_LIBAVCODEC} @executable_path/../Frameworks/libavcodec.dylib ${CMAKE_BINARY_DIR}/${bundle_name}/Contents/MacOS/hwengine)
-execute_process(COMMAND install_name_tool -change ${FFMPEG_LIBAVFORMAT} @executable_path/../Frameworks/libavformat.dylib ${CMAKE_BINARY_DIR}/${bundle_name}/Contents/MacOS/hwengine)
-execute_process(COMMAND install_name_tool -change ${FFMPEG_LIBAVUTIL} @executable_path/../Frameworks/libavutil.dylib ${CMAKE_BINARY_DIR}/${bundle_name}/Contents/MacOS/hwengine)
+
+if(NOT ${NOVIDEOREC})
+    # but macdeployqt will not work for 'hwengine'; luckily the dylibs were already updated before
+    execute_process(COMMAND install_name_tool -change ${FFMPEG_LIBAVCODEC} @executable_path/../Frameworks/libavcodec.dylib ${CMAKE_BINARY_DIR}/${bundle_name}/Contents/MacOS/hwengine)
+    execute_process(COMMAND install_name_tool -change ${FFMPEG_LIBAVFORMAT} @executable_path/../Frameworks/libavformat.dylib ${CMAKE_BINARY_DIR}/${bundle_name}/Contents/MacOS/hwengine)
+    execute_process(COMMAND install_name_tool -change ${FFMPEG_LIBAVUTIL} @executable_path/../Frameworks/libavutil.dylib ${CMAKE_BINARY_DIR}/${bundle_name}/Contents/MacOS/hwengine)
+endif()
+
+if(NOT ${NOPNG})
+    #same here, for libpng and hwengine, let's assume the version pulled by macdeployqt is the same
+    #(yes libpng is pulled by macdeployqt even when NOVIDEOREC is active)
+    execute_process(COMMAND install_name_tool -change ${PNG_LIBRARY} @executable_path/../Frameworks/${PNG_LIBNAME} ${CMAKE_BINARY_DIR}/${bundle_name}/Contents/MacOS/hwengine)
+endif()
 
 if(doBundle EQUAL 1)
     execute_process(COMMAND cp -pPR ${sdl_dir}          ${CMAKE_BINARY_DIR}/${frameworks_dir}/SDL.framework)