--- a/hedgewars/CMakeLists.txt Sun Dec 02 00:03:16 2012 +0100
+++ b/hedgewars/CMakeLists.txt Tue Dec 25 04:45:22 2012 +0100
@@ -6,11 +6,22 @@
include(${CMAKE_SOURCE_DIR}/cmake_modules/FindSDL_Extras.cmake)
-configure_file(${CMAKE_SOURCE_DIR}/hedgewars/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
#SOURCE AND PROGRAMS SECTION
-set(hwengine_project ${CMAKE_SOURCE_DIR}/hedgewars/hwengine.pas)
-set(engine_output_name "hwengine")
+if(${LIBENGINE})
+ set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
+ set(hwengine_project ${CMAKE_CURRENT_SOURCE_DIR}/hwLibrary.pas)
+else()
+ set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
+ set(hwengine_project ${CMAKE_CURRENT_SOURCE_DIR}/hwengine.pas)
+endif()
+
+if (APPLE)
+ set(required_fpc_version 2.6)
+else()
+ set(required_fpc_version 2.2)
+endif()
set(engine_sources
${hwengine_project}
@@ -54,7 +65,6 @@
uLocale.pas
uMatrix.pas
uMisc.pas
- uMobile.pas
uPhysFSLayer.pas
uRandom.pas
uRender.pas
@@ -81,9 +91,8 @@
${CMAKE_CURRENT_BINARY_DIR}/config.inc
)
-if(LIBENGINE)
- message(STATUS "Engine will be built as library (experimental)")
- set(hwengine_project ${CMAKE_SOURCE_DIR}/hedgewars/hwLibrary.pas)
+if(${LIBENGINE})
+ message(WARNING "Engine will be built as library (experimental)")
set(pascal_flags "-dHWLIBRARY" ${pascal_flags})
# create position independent code, only required for x68_64 builds, similar to -fPIC
@@ -92,64 +101,22 @@
endif(CMAKE_SIZEOF_VOID_P MATCHES "8")
# due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail
- if(APPLE AND current_macosx_version GREATER "10.5")
+ if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
set(pascal_flags "-k-no_order_inits" ${pascal_flags})
endif()
-
- if(APPLE)
- set(engine_output_name "libhwengine.dylib")
- endif (APPLE)
-endif(LIBENGINE)
+ set(destination_dir ${target_library_install_dir})
+else(${LIBENGINE})
+ set(destination_dir ${target_binary_install_dir})
+endif(${LIBENGINE})
-#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 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!")
+if (FPC_VERSION VERSION_LESS required_fpc_version)
+ message(FATAL_ERROR "Freepascal is too old, minimum version required is ${required_fpc_version}")
endif()
-message(STATUS "Checking whether linker supports noexecstack flag")
-set(noexecstack_flags "-k-z" "-knoexecstack")
-file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
-
-execute_process(COMMAND ${fpc_executable} ${noexecstack_flags} checkstack.pas
- WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
- RESULT_VARIABLE testnoexecstack
- OUTPUT_QUIET ERROR_QUIET
- )
-
-if(${testnoexecstack})
- set (noexecstack_flags "")
- message(STATUS "Checking whether linker supports noexecstack flag -- no")
-else(${testnoexecstack})
- message(STATUS "Checking whether linker supports noexecstack flag -- yes")
-endif(${testnoexecstack})
#DEPENDECIES AND EXECUTABLES SECTION
if(APPLE)
@@ -162,13 +129,13 @@
endif()
#on OSX we need to provide the SDL_main() function when building as executable
- if(NOT LIBENGINE)
+ if(NOT ${LIBENGINE})
#let's look for the installed sdlmain file; if it is not found, let's build our own
find_package(SDL REQUIRED)
#remove the ";-framework Cocoa" from the SDL_LIBRARY variable
- string(REGEX REPLACE "(.*);-.*" "\\1" sdl_dir "${SDL_LIBRARY}")
+ string(REGEX REPLACE "(.*);-.*" "\\1" sdl_library_only "${SDL_LIBRARY}")
#find libsdmain.a
- find_file(SDLMAIN_LIB libSDLMain.a PATHS ${sdl_dir}/Resources/)
+ find_file(SDLMAIN_LIB libSDLMain.a PATHS ${sdl_library_only}/Resources/)
if(SDLMAIN_LIB MATCHES "SDLMAIN_LIB-NOTFOUND")
include_directories(${SDL_INCLUDE_DIR})
@@ -180,7 +147,6 @@
set(pascal_flags "-k${SDLMAIN_LIB}" ${pascal_flags})
endif()
- set(pascal_flags "-k${LIBRARY_OUTPUT_PATH}/libphysfs.a" ${pascal_flags})
endif(APPLE)
if(NOT NOPNG)
@@ -199,9 +165,8 @@
#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(FPC_VERSION VERSION_LESS "2.6")
#under some configurations CMAKE_BUILD_TOOL fails to pass on the jobserver, breaking parallel compilation
- #TODO: check if this is needed on windows too
if(UNIX)
set(SAFE_BUILD_TOOL $(MAKE))
else()
@@ -226,7 +191,7 @@
# there are some problems with linking our avwrapper as static lib, so link it as shared
add_library(avwrapper SHARED videorec/avwrapper.c)
target_link_libraries(avwrapper ${FFMPEG_LIBRARIES})
- install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}avwrapper${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION ${target_dir})
+ install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}avwrapper${CMAKE_SHARED_LIBRARY_SUFFIX}" DESTINATION ${target_library_install_dir})
ELSE()
add_library(avwrapper STATIC videorec/avwrapper.c)
set(pascal_flags "-k${FFMPEG_LIBAVCODEC}" "-k${FFMPEG_LIBAVFORMAT}" "-k${FFMPEG_LIBAVUTIL}" ${pascal_flags})
@@ -238,29 +203,33 @@
message(STATUS "Video recording disabled by user")
endif()
-set(pascal_flags "-Fl${LIBRARY_OUTPUT_PATH}" ${pascal_flags})
-set(fpc_flags ${noexecstack_flags} ${pascal_flags} ${hwengine_project})
+set(fpc_flags ${NOEXECSTACK_FLAGS} ${pascal_flags} ${hwengine_project})
-IF(NOT APPLE)
+if(NOT APPLE)
#here is the command for standard executables or for shared library
- add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}"
- COMMAND "${fpc_executable}"
- ARGS ${fpc_flags}
+ add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}"
+ COMMAND "${FPC_EXECUTABLE}"
+ ARGS ${fpc_flags} -o${engine_output_name}
MAIN_DEPENDENCY ${hwengine_project}
DEPENDS ${engine_sources}
)
-ELSE()
+else()
#these are the dependencies for building a universal binary on Mac OS X
foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build})
set(lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" ${lipo_args_list})
add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
- COMMAND "${fpc_executable}"
+ COMMAND "${FPC_EXECUTABLE}"
ARGS ${fpc_flags} -ohwengine.${build_arch} -P${build_arch}
MAIN_DEPENDENCY ${hwengine_project}
DEPENDS ${engine_sources}
)
add_custom_target(hwengine.${build_arch} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
+ add_custom_command(TARGET hwengine.${build_arch} POST_BUILD
+ COMMAND "install_name_tool"
+ ARGS -id @executable_path/../Frameworks/${engine_output_name}
+ ${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}
+ )
endforeach()
add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}"
@@ -268,10 +237,10 @@
ARGS ${lipo_args_list} -create -output ${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}
DEPENDS ${lipo_args_list}
)
-ENDIF()
+endif()
-add_custom_target(${engine_output_name} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}")
+add_custom_target(${engine_output_name} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}")
#when system Lua is not found we need to compile it before engine
if(NOT LUA_FOUND)
@@ -288,8 +257,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") AND (NOVIDEOREC OR NOT ${FFMPEG_FOUND}))
+if((FPC_VERSION VERSION_LESS "2.6") 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})
+install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" DESTINATION ${destination_dir})