Patch by Matt McCutchen to fix active waiting in main loop. (Bug 480)
[supertux.git] / CMakeLists.txt
index e83c442..ee73e77 100644 (file)
@@ -39,8 +39,12 @@ PROJECT(SUPERTUX)
 
 ### CMake configuration
 
-# allow building with old CMake. Use some bundled modules as a fallback
+# allow building with old CMake. Set compatibility options. Use some bundled modules as a fallback
 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
+IF(COMMAND cmake_policy)
+       CMAKE_POLICY(SET CMP0003 NEW)
+ENDIF(COMMAND cmake_policy)
+
 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${SUPERTUX_SOURCE_DIR}/mk/cmake)
 
 # move some config clutter to the advanced section
@@ -60,7 +64,7 @@ MARK_AS_ADVANCED(
        APPDATADIR
 )
 OPTION(ENABLE_BINRELOC "Enable autopackage's BINRELOC features" OFF)
-SET(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/games/supertux2" CACHE STRING "APPDATADIR where data files reside")
+SET(APPDATADIR "${CMAKE_INSTALL_PREFIX}/share/games/supertux2")
 
 ## Check endianess
 
@@ -76,7 +80,6 @@ MARK_AS_ADVANCED(
        SDL_LIBRARY
 )
 INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
-LINK_LIBRARIES(${SDL_LIBRARY})
 
 FIND_PACKAGE(SDL_image REQUIRED)
 MARK_AS_ADVANCED(
@@ -84,14 +87,12 @@ MARK_AS_ADVANCED(
        SDLIMAGE_LIBRARY
 )
 INCLUDE_DIRECTORIES(${SDLIMAGE_INCLUDE_DIR})
-LINK_LIBRARIES(${SDLIMAGE_LIBRARY})
 
 OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
 IF(ENABLE_OPENGL)
   FIND_PACKAGE(OpenGL)
   IF(${OPENGL_FOUND} STREQUAL "YES")
     INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
-    LINK_LIBRARIES(${OPENGL_LIBRARY})
     SET(HAVE_OPENGL TRUE)
   ENDIF(${OPENGL_FOUND} STREQUAL "YES")
 ENDIF(ENABLE_OPENGL)
@@ -102,7 +103,6 @@ MARK_AS_ADVANCED(
        OPENAL_LIBRARY
 )
 INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR})
-LINK_LIBRARIES(${OPENAL_LIBRARY})
 
 FIND_PACKAGE(OggVorbis REQUIRED)
 MARK_AS_ADVANCED(
@@ -113,7 +113,6 @@ MARK_AS_ADVANCED(
        VORBIS_LIBRARY
 )
 INCLUDE_DIRECTORIES(${OGGVORBIS_INCLUDE_DIR})
-LINK_LIBRARIES(${OGGVORBIS_LIBRARIES})
 
 FIND_PACKAGE(PhysFS REQUIRED)
 MARK_AS_ADVANCED(
@@ -121,12 +120,10 @@ MARK_AS_ADVANCED(
        PHYSFS_LIBRARY
 )
 INCLUDE_DIRECTORIES(${PHYSFS_INCLUDE_DIR})
-LINK_LIBRARIES(${PHYSFS_LIBRARY})
 
 FIND_PACKAGE(CURL)
 IF(CURL_FOUND)
   INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
-  LINK_LIBRARIES(${CURL_LIBRARY})
   SET(HAVE_LIBCURL TRUE)
 ENDIF(CURL_FOUND)
 
@@ -134,13 +131,23 @@ ENDIF(CURL_FOUND)
 #INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR})
 #LINK_LIBRARIES(${ICONV_LIBRARY})
 
+## Find revision of WC
+MARK_AS_ADVANCED(SVNVERSION_EXECUTABLE)
+FIND_PROGRAM(SVNVERSION_EXECUTABLE svnversion)
+IF(SVNVERSION_EXECUTABLE)
+  EXECUTE_PROCESS(COMMAND svnversion -n ${SUPERTUX_SOURCE_DIR}
+                  OUTPUT_VARIABLE SUPERTUX_WC_REVISION)
+  SET(REVISION " r${SUPERTUX_WC_REVISION}")
+ENDIF(SVNVERSION_EXECUTABLE)
+
 ## Check platform-dependent build options
 
 INCLUDE(ConfigureChecks)
 
-## Create config.h
+## Create config.h and version.h
 
 configure_file(config.h.cmake ${CMAKE_BINARY_DIR}/config.h )
+configure_file(version.h.cmake ${CMAKE_BINARY_DIR}/version.h )
 include_directories (${CMAKE_BINARY_DIR}/)
 
 ## Also execute instructions in src/squirrel/CMakeLists.txt
@@ -158,14 +165,46 @@ include_directories (${SUPERTUX_SOURCE_DIR}/src/squirrel/include/)
 
 ## Build list of sources for supertux binary
 
-FILE(GLOB SUPERTUX_SOURCES RELATIVE ${SUPERTUX_SOURCE_DIR} src/*.cpp src/audio/*.cpp src/badguy/*.cpp src/binreloc/*.cpp src/control/*.cpp src/gui/*.cpp src/lisp/*.cpp src/math/*.cpp src/object/*.cpp src/physfs/*.cpp src/sprite/*.cpp src/tinygettext/*.cpp src/trigger/*.cpp src/video/*.cpp src/worldmap/*.cpp src/scripting/*.cpp src/obstack/*.c)
+FILE(GLOB SUPERTUX_SOURCES RELATIVE ${SUPERTUX_SOURCE_DIR} src/*.cpp src/*/*.cpp src/obstack/*.c)
+
+## Precompile "a few" headers in GCC
+OPTION(PRECOMPILE_HEADERS "Precompile headers (experimental)" OFF)
+IF(PRECOMPILE_HEADERS)
+  FILE(GLOB PRECOMPILED_HEADERS RELATIVE ${SUPERTUX_SOURCE_DIR} src/badguy/badguy.hpp
+           src/scripting/wrapper.hpp src/video/*.hpp src/math/*.hpp)
+  FILE(WRITE ${SUPERTUX_BINARY_DIR}/precompile.hh "// Precompiled headers\n")
+  FILE(APPEND ${SUPERTUX_BINARY_DIR}/precompile.hh "#ifndef __SUPERTUX_PRECOMPILED_HEADER\n")
+  FILE(APPEND ${SUPERTUX_BINARY_DIR}/precompile.hh "#define __SUPERTUX_PRECOMPILED_HEADER\n")
+  FOREACH(PRECOMPILED_HEADER ${PRECOMPILED_HEADERS})
+    FILE(RELATIVE_PATH PRECOMPILED_HEADER ${SUPERTUX_SOURCE_DIR}/src "${SUPERTUX_SOURCE_DIR}/${PRECOMPILED_HEADER}")
+    FILE(APPEND ${SUPERTUX_BINARY_DIR}/precompile.hh "#include \"${PRECOMPILED_HEADER}\"\n")
+  ENDFOREACH(PRECOMPILED_HEADER)
+  FILE(APPEND ${SUPERTUX_BINARY_DIR}/precompile.hh "#endif /*__SUPERTUX_PRECOMPILED_HEADER*/\n")
+  ADD_CUSTOM_COMMAND(
+    OUTPUT ${SUPERTUX_BINARY_DIR}/precompile.hh.gch
+    COMMAND ${CMAKE_CXX_COMPILER} -x "c++-header" $(CXX_FLAGS) ${SUPERTUX_BINARY_DIR}/precompile.hh
+    DEPENDS ${PRECOMPILED_HEADERS}
+    COMMENT "Building precompiled header..."
+  )
+  ## Make certain it is built
+  SET(SUPERTUX_SOURCES ${SUPERTUX_BINARY_DIR}/precompile.hh.gch ${SUPERTUX_SOURCES})
+  SET(CMAKE_CXX_FLAGS "-include ${SUPERTUX_BINARY_DIR}/precompile.hh" ${CMAKE_CXX_FLAGS})
+ELSE(PRECOMPILE_HEADERS)
+  IF(EXISTS ${SUPERTUX_BINARY_DIR}/precompile.hh)
+    FILE(REMOVE ${SUPERTUX_BINARY_DIR}/precompile.hh)
+  ENDIF(EXISTS ${SUPERTUX_BINARY_DIR}/precompile.hh)
+  IF(EXISTS ${SUPERTUX_BINARY_DIR}/precompile.hh.gch)
+    FILE(REMOVE ${SUPERTUX_BINARY_DIR}/precompile.hh.gch)
+  ENDIF(EXISTS ${SUPERTUX_BINARY_DIR}/precompile.hh.gch)
+ENDIF(PRECOMPILE_HEADERS)
+
 
 ## Debug options
 
-OPTION(DEBUG "Build with debugging options" OFF)
-OPTION(PROFILE "Build with profiling information" OFF)
-OPTION(WERROR "Build stops on first compiler warning" OFF)
+OPTION(DEBUG "Build with debugging options" ON)
+OPTION(WERROR "Stop on first compiler warning" ON)
 IF(CMAKE_COMPILER_IS_GNUCC)
+  ADD_DEFINITIONS(-Wall -Wextra -W)
   IF (DEBUG)
     REMOVE_DEFINITIONS(-O2)
     ADD_DEFINITIONS(-O0 -g)
@@ -173,16 +212,14 @@ IF(CMAKE_COMPILER_IS_GNUCC)
     ADD_DEFINITIONS(-O2)
     REMOVE_DEFINITIONS(-O0 -g)
   ENDIF (DEBUG)
-  IF (PROFILE)
-    ADD_DEFINITIONS(-pg)
-  ELSE (PROFILE)
-    REMOVE_DEFINITIONS(-pg)
-  ENDIF (PROFILE)
-  IF (WERROR)
-    ADD_DEFINITIONS(-Wall -Werror)
-  ELSE (WERROR)
-    REMOVE_DEFINITIONS(-Wall -Werror)
-  ENDIF (WERROR)
+  SET(CMAKE_CXX_FLAGS_PROFILE "-pg")
+  SET(CMAKE_C_FLAGS_PROFILE "-pg")
+  SET(CMAKE_LD_FLAGS_PROFILE "-pg")
+  IF(WERROR)
+    ADD_DEFINITIONS(-Werror)
+  ELSE(WERROR)
+    REMOVE_DEFINITIONS(-Werror)
+  ENDIF(WERROR)
 ENDIF(CMAKE_COMPILER_IS_GNUCC)
 
 ## Add in squirrel debug stuff
@@ -250,7 +287,7 @@ IF(GENERATE_MESSAGESPOT)
       ADD_CUSTOM_COMMAND(
         OUTPUT ${MESSAGES_POT_FILE}
         COMMAND ${XGETTEXT_EXECUTABLE}
-        ARGS --keyword="_:1" --language=Lisp --sort-by-file --output=${MESSAGES_POT_FILE} ${SUPERTUX_LEVELS}
+        ARGS --keyword="_:1" --language=Lisp --force-po --sort-by-file "--output=${MESSAGES_POT_FILE}" ${SUPERTUX_LEVELS}
         DEPENDS ${SUPERTUX_LEVELS}
         WORKING_DIRECTORY ${SUPERTUX_SOURCE_DIR}
         COMMENT "Generating POT file ${MESSAGES_POT_FILE}"
@@ -292,6 +329,11 @@ IF(WIN32)
   ENDIF(MINGW)
 ENDIF(WIN32)
 
+## Add binreloc.c if enabled
+IF(ENABLE_BINRELOC)
+  SET(SUPERTUX_SOURCES ${SUPERTUX_SOURCES} ${SUPERTUX_SOURCE_DIR}/src/binreloc/binreloc.c)
+ENDIF(ENABLE_BINRELOC)
+
 
 ## Generate supertux executable in the right place
 
@@ -301,10 +343,20 @@ SET(EXECUTABLE_OUTPUT_PATH ${SUPERTUX_SOURCE_DIR})
 
 ADD_EXECUTABLE(supertux2 ${SUPERTUX_SOURCES})
 
-## Link supertux binary with squirrel
+## Link supertux binary with squirrel and other libraries
 
 TARGET_LINK_LIBRARIES(supertux2 squirrel)
-
+TARGET_LINK_LIBRARIES(supertux2 ${SDL_LIBRARY})
+TARGET_LINK_LIBRARIES(supertux2 ${SDLIMAGE_LIBRARY})
+TARGET_LINK_LIBRARIES(supertux2 ${OPENAL_LIBRARY})
+TARGET_LINK_LIBRARIES(supertux2 ${OGGVORBIS_LIBRARIES})
+TARGET_LINK_LIBRARIES(supertux2 ${PHYSFS_LIBRARY})
+IF(HAVE_OPENGL)
+    TARGET_LINK_LIBRARIES(supertux2 ${OPENGL_LIBRARY})
+ENDIF(HAVE_OPENGL)
+IF(HAVE_LIBCURL)
+  TARGET_LINK_LIBRARIES(supertux2 ${CURL_LIBRARY})
+ENDIF(HAVE_LIBCURL)
 
 ## Install stuff
 
@@ -353,8 +405,9 @@ INSTALL(TARGETS supertux2 DESTINATION ${INSTALL_SUBDIR_BIN})
 
 INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/INSTALL ${SUPERTUX_SOURCE_DIR}/README ${SUPERTUX_SOURCE_DIR}/COPYING ${SUPERTUX_SOURCE_DIR}/WHATSNEW.txt DESTINATION ${INSTALL_SUBDIR_DOC})
 
-INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/data/credits.txt ${SUPERTUX_SOURCE_DIR}/data/camera.cfg DESTINATION ${INSTALL_SUBDIR_SHARE})
+INSTALL(FILES ${SUPERTUX_SOURCE_DIR}/data/credits.txt DESTINATION ${INSTALL_SUBDIR_SHARE})
 INSTALL(DIRECTORY data/images DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
+INSTALL(DIRECTORY data/fonts DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
 INSTALL(DIRECTORY data/levels DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
 INSTALL(DIRECTORY data/music DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
 INSTALL(DIRECTORY data/scripts DESTINATION ${INSTALL_SUBDIR_SHARE} PATTERN ".svn" EXCLUDE)
@@ -371,10 +424,10 @@ SET(CPACK_PACKAGE_VENDOR "SuperTux Devel Team")
 SET(CPACK_PACKAGE_CONTACT "SuperTux Devel Team <supertux-devel@lists.lethargik.org>")
 SET(CPACK_DEBIAN_PACKAGE_NAME "supertux2")
 SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.5), libgcc1 (>= 1:4.1), libgl1-mesa-glx | libgl1, libogg0 (>= 1.1.3), libopenal0a, libphysfs-1.0-0, libsdl-image1.2 (>= 1.2.5), libsdl1.2debian (>= 1.2.10-1), libstdc++6 (>= 4.1.2), libvorbis0a (>= 1.1.2), libvorbisfile3 (>= 1.1.2), libcurl3 (>= 7.16)")
-SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Classic 2D jump 'n run sidescroller with Tux\n SuperTux is a classic 2D jump 'n run sidescroller game in a similar\n style like the original SuperMario games. This release of SuperTux\n features 9 enemies, 26 playable levels, software and OpenGL rendering\n modes, configurable joystick and keyboard input, new music and\n completly redone graphics.\n .\n This is a development snapshot of SuperTux. It may suffer from\n critical bugs and has not been fully tested. \n .\n Homepage: http://supertux.lethargik.org/")
+SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Classic 2D jump 'n run sidescroller with Tux\n SuperTux is a classic 2D jump 'n run sidescroller game in a similar\n style like the original SuperMario games. This release of SuperTux\n features 9 enemies, 26 playable levels, software and OpenGL rendering\n modes, configurable joystick and keyboard input, new music and\n completely redone graphics.\n .\n This is a development snapshot of SuperTux. It may suffer from\n critical bugs and has not been fully tested. \n .\n Homepage: http://supertux.lethargik.org/")
 SET(CPACK_DEBIAN_PACKAGE_SECTION "games")
 SET(CPACK_RPM_PACKAGE_NAME "supertux2")
-SET(CPACK_RPM_PACKAGE_DESCRIPTION "Classic 2D jump 'n run sidescroller with Tux\n SuperTux is a classic 2D jump 'n run sidescroller game in a similar\n style like the original SuperMario games. This release of SuperTux\n features 9 enemies, 26 playable levels, software and OpenGL rendering\n modes, configurable joystick and keyboard input, new music and\n completly redone graphics.\n .\n This is a development snapshot of SuperTux. It may suffer from\n critical bugs and has not been fully tested. \n .\n Homepage: http://supertux.lethargik.org/")
+SET(CPACK_RPM_PACKAGE_DESCRIPTION "Classic 2D jump 'n run sidescroller with Tux\n SuperTux is a classic 2D jump 'n run sidescroller game in a similar\n style like the original SuperMario games. This release of SuperTux\n features 9 enemies, 26 playable levels, software and OpenGL rendering\n modes, configurable joystick and keyboard input, new music and\n completely redone graphics.\n .\n This is a development snapshot of SuperTux. It may suffer from\n critical bugs and has not been fully tested. \n .\n Homepage: http://supertux.lethargik.org/")
 SET(CPACK_RPM_PACKAGE_LICENSE "GNU General Public License (GPL)")
 SET(CPACK_RPM_PACKAGE_GROUP "Amusements/Games/Action/Arcade")
 IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")