--- a/hedgewars/CMakeLists.txt Tue Dec 18 20:48:37 2012 +0400
+++ b/hedgewars/CMakeLists.txt Fri Jan 04 21:44:40 2013 +0400
@@ -9,8 +9,13 @@
configure_file(${hedgewars_SOURCE_DIR}/hedgewars/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc)
#SOURCE AND PROGRAMS SECTION
-set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.pas)
-set(engine_output_name "hwengine")
+if(${BUILD_ENGINE_LIBRARY})
+ set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
+ set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwLibrary.pas)
+else()
+ set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}")
+ set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.pas)
+endif()
if (APPLE)
set(required_fpc_version 2.6)
@@ -85,25 +90,23 @@
${CMAKE_CURRENT_BINARY_DIR}/config.inc
)
-if(BUILD_ENGINE_LIBRARY)
- message(STATUS "Engine will be built as library (experimental)")
- set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwLibrary.pas)
- set(pascal_flags "-dHWLIBRARY" ${pascal_flags})
+if(${BUILD_ENGINE_LIBRARY})
+ message(WARNING "Engine will be built as library (experimental)")
+ list(APPEND pascal_flags "-dHWLIBRARY")
# create position independent code, only required for x68_64 builds, similar to -fPIC
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
- set(pascal_flags "-Cg" ${pascal_flags})
+ list(APPEND pascal_flags "-Cg")
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")
- set(pascal_flags "-k-no_order_inits" ${pascal_flags})
+ if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
+ list(APPEND pascal_flags "-k-no_order_inits")
endif()
-
- if(APPLE)
- set(engine_output_name "libhwengine.dylib")
- endif (APPLE)
-endif(BUILD_ENGINE_LIBRARY)
+ set(destination_dir ${target_library_install_dir})
+else(${BUILD_ENGINE_LIBRARY})
+ set(destination_dir ${target_binary_install_dir})
+endif(${BUILD_ENGINE_LIBRARY})
# Check Freepascal version
@@ -125,32 +128,32 @@
endif()
#on OSX we need to provide the SDL_main() function when building as executable
- if(NOT BUILD_ENGINE_LIBRARY)
+ if(NOT ${BUILD_ENGINE_LIBRARY})
#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})
add_library (SDLmain STATIC SDLMain.m)
#add a dependency to the hwengine target
- set(engine_sources ${engine_sources} SDLmain)
+ list(APPEND engine_sources SDLmain)
set(SDLMAIN_LIB "${LIBRARY_OUTPUT_PATH}/libSDLmain.a")
endif()
- set(pascal_flags "-k${SDLMAIN_LIB}" ${pascal_flags})
+ list(APPEND pascal_flags "-k${SDLMAIN_LIB}")
endif()
endif(APPLE)
if(NOT NOPNG)
find_package(PNG)
if(${PNG_FOUND})
- set(pascal_flags "-dPNG_SCREENSHOTS" ${pascal_flags})
+ list(APPEND pascal_flags "-dPNG_SCREENSHOTS")
if(APPLE) # fpc png unit doesn't pull the library (see bug 21833)
- set(pascal_flags "-k${PNG_LIBRARY}" ${pascal_flags})
+ list(APPEND pascal_flags "-k${PNG_LIBRARY}")
endif()
else()
message(WARNING "Screenshots will be in BMP format because libpng was not found")
@@ -182,15 +185,15 @@
#TODO: convert avwrapper to .pas unit so we can skip this step
include_directories(${FFMPEG_INCLUDE_DIR})
- set(pascal_flags "-dUSE_VIDEO_RECORDING" ${pascal_flags})
+ list(APPEND pascal_flags "-dUSE_VIDEO_RECORDING")
IF (WIN32)
# there are some problems with linking our avwrapper as static lib, so link it as shared
add_library(avwrapper SHARED 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 avwrapper.c)
- set(pascal_flags "-k${FFMPEG_LIBAVCODEC}" "-k${FFMPEG_LIBAVFORMAT}" "-k${FFMPEG_LIBAVUTIL}" ${pascal_flags})
+ list(APPEND pascal_flags "-k${FFMPEG_LIBAVCODEC}" "-k${FFMPEG_LIBAVFORMAT}" "-k${FFMPEG_LIBAVUTIL}")
ENDIF()
else()
message(WARNING "Could NOT find FFMPEG/LibAV, video recording will be disabled")
@@ -204,16 +207,16 @@
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}"
+ add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}"
COMMAND "${FPC_EXECUTABLE}"
- ARGS ${fpc_flags}
+ ARGS ${fpc_flags} -o${engine_output_name}
MAIN_DEPENDENCY ${hwengine_project}
DEPENDS ${engine_sources}
)
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})
+ list(APPEND lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}")
add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}"
COMMAND "${FPC_EXECUTABLE}"
ARGS ${fpc_flags} -ohwengine.${build_arch} -P${build_arch}
@@ -221,6 +224,11 @@
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}"
@@ -231,7 +239,7 @@
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)
@@ -252,4 +260,4 @@
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})