cmake rework, cleanup a lot of redundant sections, separate library and binary install location, unify osx and win handling of the data directory (tested on win, lin and mac)
--- a/CMakeLists.txt Wed Dec 19 19:33:49 2012 +0100
+++ b/CMakeLists.txt Thu Dec 20 23:12:18 2012 +0100
@@ -67,18 +67,35 @@
set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
-#bundle .app setup
-if(APPLE OR CROSSAPPLE)
- #paths for creating the bundle
- set(bundle_name Hedgewars.app)
- set(frameworks_dir ${bundle_name}/Contents/Frameworks/)
- set(CMAKE_INSTALL_PREFIX ${bundle_name}/Contents/MacOS/)
- set(DATA_INSTALL_DIR "../Resources/")
- set(target_dir ".")
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
+set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
+
+if(UNIX AND NOT APPLE)
+ set(target_binary_install_dir "bin")
+ set(target_library_install_dir "lib")
+ if(DEFINED DATA_INSTALL_DIR)
+ set(SHAREPATH "${DATA_INSTALL_DIR}")
+ else()
+ set(SHAREPATH "share/hedgewars/")
+ endif()
else()
- set(target_dir "bin")
+ set(target_binary_install_dir "./")
+
+ if(APPLE OR ${CROSSAPPLE})
+ set(target_library_install_dir "Hedgewars.app/Contents/Frameworks/")
+ set(CMAKE_INSTALL_PREFIX "Hedgewars.app/Contents/MacOS/")
+ set(SHAREPATH "../Resources/")
+ else()
+ if(WIN32)
+ set(target_library_install_dir "./")
+ set(SHAREPATH "./")
+ set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/misc/winutils/")
+ link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin")
+ endif(WIN32)
+ endif()
endif()
+
if(APPLE)
set(CMAKE_FIND_FRAMEWORK "FIRST")
@@ -220,20 +237,6 @@
endif()
-#finish setting paths
-if(DEFINED DATA_INSTALL_DIR)
- set(SHAREPATH ${DATA_INSTALL_DIR}/hedgewars/)
-else()
- set(SHAREPATH share/hedgewars/)
-endif()
-set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
-set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
-if(WIN32)
- set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/misc/winutils/")
- link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin")
-endif(WIN32)
-
-
#server discovery
if(NOT NOSERVER)
if(GHC)
@@ -309,6 +312,7 @@
set(CPACK_NSIS_URL_INFO_ABOUT "http://www.hedgewars.org/")
set(CPACK_NSIS_CONTACT "unC0Rr@gmail.com")
set(CPACK_NSIS_MODIFY_PATH OFF)
+ set(CPACK_NSIS_EXECUTABLES_DIRECTORY "${target_binary_install_dir}")
set(CPACK_GENERATOR "ZIP;NSIS")
set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "hedgewars")
else(WIN32 AND NOT UNIX)
--- a/QTfrontend/CMakeLists.txt Wed Dec 19 19:33:49 2012 +0100
+++ b/QTfrontend/CMakeLists.txt Thu Dec 20 23:12:18 2012 +0100
@@ -43,24 +43,21 @@
include_directories("/usr/local/include")
endif(UNIX)
-
-if(WIN32 AND NOT UNIX)
- set(HEDGEWARS_BINDIR ".")
- set(HEDGEWARS_DATADIR "../share/")
- add_definitions(-DUSE_XFIRE)
+#directory containing hw executables
+set(HEDGEWARS_BINDIR ${CMAKE_INSTALL_PREFIX}/${target_binary_install_dir})
+#directory for resources, relative to the one above on certain platforms/configurations
+if(DEFINED DATA_INSTALL_DIR OR WIN32 OR APPLE)
+ set(HEDGEWARS_DATADIR ${SHAREPATH})
else()
- set(HEDGEWARS_BINDIR ${CMAKE_INSTALL_PREFIX})
- if(DEFINED DATA_INSTALL_DIR)
- set(HEDGEWARS_DATADIR ${DATA_INSTALL_DIR})
- else()
- set(HEDGEWARS_DATADIR ${CMAKE_INSTALL_PREFIX}/share/)
- endif()
- #only the cocoa version of qt supports building 64 bit apps
- if(APPLE AND (CMAKE_OSX_ARCHITECTURES MATCHES "x86_64*") AND (NOT QT_MAC_USE_COCOA))
- message(FATAL_ERROR "Building the 64 bit version of Hedgewars *requires* the Cocoa variant of QT on Mac OS X")
- endif()
+ set(HEDGEWARS_DATADIR ${CMAKE_INSTALL_PREFIX}/${SHAREPATH}/)
endif()
+#only the cocoa version of qt supports building 64 bit apps
+if(APPLE AND (CMAKE_OSX_ARCHITECTURES MATCHES "x86_64*") AND (NOT QT_MAC_USE_COCOA))
+ message(FATAL_ERROR "Building the 64 bit version of Hedgewars *requires* the Cocoa variant of QT on Mac OS X")
+endif()
+#endif()
+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hwconsts.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/hwconsts.cpp)
file(GLOB NetCpp net/*.cpp)
@@ -136,7 +133,7 @@
set(hwfr_rez hedgewars.qrc)
-if(BUILD_ENGINE_LIBRARY)
+if(${BUILD_ENGINE_LIBRARY})
add_definitions(-DHWLIBRARY=1)
set(hwlibname "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(HW_LINK_LIBS ${hwlibname} ${HW_LINK_LIBS})
@@ -180,7 +177,7 @@
)
if((UNIX AND NOT APPLE) AND ${BUILD_ENGINE_LIBRARY})
- set_target_properties(hedgewars PROPERTIES LINK_FLAGS "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/${target_dir}")
+ set_target_properties(hedgewars PROPERTIES LINK_FLAGS "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/${target_library_install_dir}")
endif()
set(HW_LINK_LIBS
@@ -212,5 +209,5 @@
endif()
-install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hedgewars${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir})
+install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hedgewars${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_binary_install_dir})
--- a/QTfrontend/main.cpp Wed Dec 19 19:33:49 2012 +0100
+++ b/QTfrontend/main.cpp Thu Dec 20 23:12:18 2012 +0100
@@ -189,7 +189,8 @@
qRegisterMetaType<HWTeam>("HWTeam");
- bindir->cd("bin"); // workaround over NSIS installer
+ // workaround over NSIS installer which modifies the install path
+ bindir->cd("./");
if(cConfigDir->length() == 0)
cfgdir->setPath(cfgdir->homePath());
@@ -237,14 +238,14 @@
datadir->cd(bindir->absolutePath());
datadir->cd(*cDataDir);
- if(!datadir->cd("hedgewars/Data"))
+ if(!datadir->cd("Data"))
{
QMessageBox missingMsg(QApplication::activeWindow());
missingMsg.setIcon(QMessageBox::Critical);
missingMsg.setWindowTitle(QMessageBox::tr("Main - Error"));
missingMsg.setText(QMessageBox::tr("Failed to open data directory:\n%1\n\n"
"Please check your installation!").
- arg(datadir->absolutePath()+"/hedgewars/Data"));
+ arg(datadir->absolutePath()+"/Data"));
missingMsg.setWindowModality(Qt::WindowModal);
missingMsg.exec();
return 1;
--- a/bin/CMakeLists.txt Wed Dec 19 19:33:49 2012 +0100
+++ b/bin/CMakeLists.txt Thu Dec 20 23:12:18 2012 +0100
@@ -5,5 +5,5 @@
install(FILES
${DLLs}
${ICOs}
- DESTINATION bin)
+ DESTINATION ${target_library_install_dir})
endif(WIN32 AND NOT UNIX)
--- a/gameServer/CMakeLists.txt Wed Dec 19 19:33:49 2012 +0100
+++ b/gameServer/CMakeLists.txt Thu Dec 20 23:12:18 2012 +0100
@@ -42,4 +42,4 @@
add_custom_target(hedgewars-server ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/hedgewars-server${CMAKE_EXECUTABLE_SUFFIX}")
-install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hedgewars-server${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir})
+install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hedgewars-server${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_binary_install_dir})
--- a/hedgewars/CMakeLists.txt Wed Dec 19 19:33:49 2012 +0100
+++ b/hedgewars/CMakeLists.txt Thu Dec 20 23:12:18 2012 +0100
@@ -90,7 +90,7 @@
${CMAKE_CURRENT_BINARY_DIR}/config.inc
)
-if(BUILD_ENGINE_LIBRARY)
+if(${BUILD_ENGINE_LIBRARY})
message(WARNING "Engine will be built as library (experimental)")
set(pascal_flags "-dHWLIBRARY" ${pascal_flags})
@@ -103,7 +103,10 @@
if(APPLE AND current_macosx_version VERSION_GREATER "10.5")
set(pascal_flags "-k-no_order_inits" ${pascal_flags})
endif()
-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,13 +128,13 @@
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})
@@ -187,7 +190,7 @@
# 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})
@@ -252,4 +255,4 @@
add_dependencies(${engine_output_name} ENGINECLEAN)
endif()
-install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" DESTINATION ${target_dir})
+install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" DESTINATION ${destination_dir})
--- a/hedgewars/config.inc.in Wed Dec 19 19:33:49 2012 +0100
+++ b/hedgewars/config.inc.in Thu Dec 20 23:12:18 2012 +0100
@@ -24,4 +24,4 @@
const cNetProtoVersion = ${HEDGEWARS_PROTO_VER};
cVersionString = '${HEDGEWARS_VERSION}';
cLuaLibrary = '${LUA_LIBRARY}';
- cDefaultPathPrefix = '${DATA_INSTALL_DIR}';
+ cDefaultPathPrefix = '${CMAKE_INSTALL_PREFIX}/${SHAREPATH}/Data';
--- a/misc/liblua/CMakeLists.txt Wed Dec 19 19:33:49 2012 +0100
+++ b/misc/liblua/CMakeLists.txt Thu Dec 20 23:12:18 2012 +0100
@@ -9,7 +9,7 @@
set(LUA_LIBRARY lua.dll)
set_target_properties(lua PROPERTIES PREFIX "")
- install(TARGETS lua RUNTIME DESTINATION ${target_dir})
+ install(TARGETS lua RUNTIME DESTINATION ${target_library_install_dir})
else(WIN32)
add_definitions(-DLUA_USE_LINUX)
add_library(lua STATIC ${lua_src})
--- a/misc/physfs/CMakeLists.txt Wed Dec 19 19:33:49 2012 +0100
+++ b/misc/physfs/CMakeLists.txt Thu Dec 20 23:12:18 2012 +0100
@@ -287,7 +287,7 @@
SET(PHYSFS_LIB_TARGET physfs)
SET(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs")
INSTALL(TARGETS ${PHYSFS_INSTALL_TARGETS}
- RUNTIME DESTINATION ${LIBRARY_OUTPUT_PATH})
+ RUNTIME DESTINATION ${target_library_install_dir})
ENDIF(PHYSFS_BUILD_SHARED)
IF(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
--- a/share/hedgewars/Data/misc/CMakeLists.txt Wed Dec 19 19:33:49 2012 +0100
+++ b/share/hedgewars/Data/misc/CMakeLists.txt Thu Dec 20 23:12:18 2012 +0100
@@ -1,14 +1,9 @@
-if(DEFINED DATA_INSTALL_DIR)
- set(HEDGEWARS_DATADIR ${DATA_INSTALL_DIR}
-)
-else()
- set(HEDGEWARS_DATADIR ${CMAKE_INSTALL_PREFIX}/share/)
-endif()
if(UNIX AND NOT APPLE)
-configure_file(hwengine.desktop.in hwengine.desktop)
+ configure_file(hwengine.desktop.in hwengine.desktop)
+
+ file(GLOB miscfiles *.xml *.desktop)
+
+ install(FILES ${miscfiles} DESTINATION ${SHAREPATH}/Data/misc)
endif()
-file(GLOB miscfiles *.xml *.desktop)
-
-install(FILES ${miscfiles} DESTINATION ${SHAREPATH}Data/misc)
--- a/share/hedgewars/Data/misc/hwengine.desktop.in Wed Dec 19 19:33:49 2012 +0100
+++ b/share/hedgewars/Data/misc/hwengine.desktop.in Thu Dec 20 23:12:18 2012 +0100
@@ -17,7 +17,7 @@
GenericName[sv]=Hedgewarsmotorn, för att öppna demo- och sparfiler
GenericName[da]=Kæmpende Pindsvin
Icon=hedgewars.png
-Exec=${CMAKE_INSTALL_PREFIX}/bin/hwengine ${HEDGEWARS_DATADIR}/hedgewars/Data %f
+Exec=${CMAKE_INSTALL_PREFIX}/${target_binary_install_dir}/hwengine %f
Path=/tmp
Terminal=false
StartupNotify=false
--- a/tools/CMakeLists.txt Wed Dec 19 19:33:49 2012 +0100
+++ b/tools/CMakeLists.txt Thu Dec 20 23:12:18 2012 +0100
@@ -29,7 +29,7 @@
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}")
+ string(REGEX REPLACE "(.*);-.*" "\\1" sdl_library_only "${SDL_LIBRARY}")
if(NOT NOPNG)
#get the neme of the library (harmelss if it is static)
--- a/tools/CreateMacBundle.cmake.in Wed Dec 19 19:33:49 2012 +0100
+++ b/tools/CreateMacBundle.cmake.in Thu Dec 20 23:12:18 2012 +0100
@@ -1,31 +1,31 @@
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})
+execute_process(COMMAND stat ${target_library_install_dir} RESULT_VARIABLE doBundle OUTPUT_QUIET ERROR_QUIET)
+execute_process(COMMAND mkdir -p ${target_library_install_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)
+execute_process(COMMAND ${macdeployqt_executable} ${CMAKE_BINARY_DIR}/Hedgewars.app OUTPUT_QUIET ERROR_QUIET)
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)
+ execute_process(COMMAND install_name_tool -change ${FFMPEG_LIBAVCODEC} @executable_path/../Frameworks/libavcodec.dylib ${CMAKE_INSTALL_PREFIX}/hwengine)
+ execute_process(COMMAND install_name_tool -change ${FFMPEG_LIBAVFORMAT} @executable_path/../Frameworks/libavformat.dylib ${CMAKE_INSTALL_PREFIX}/hwengine)
+ execute_process(COMMAND install_name_tool -change ${FFMPEG_LIBAVUTIL} @executable_path/../Frameworks/libavutil.dylib ${CMAKE_INSTALL_PREFIX}/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)
+ execute_process(COMMAND install_name_tool -change ${PNG_LIBRARY} @executable_path/../Frameworks/${PNG_LIBNAME} ${CMAKE_INSTALL_PREFIX}/hwengine)
endif()
if(doBundle EQUAL 1)
- execute_process(COMMAND cp -pPR ${sdl_dir} ${CMAKE_BINARY_DIR}/${frameworks_dir}/SDL.framework)
- execute_process(COMMAND cp -pPR ${SDLIMAGE_LIBRARY} ${CMAKE_BINARY_DIR}/${frameworks_dir}/SDL_image.framework)
- execute_process(COMMAND cp -pPR ${SDLNET_LIBRARY} ${CMAKE_BINARY_DIR}/${frameworks_dir}/SDL_net.framework)
- execute_process(COMMAND cp -pPR ${SDLTTF_LIBRARY} ${CMAKE_BINARY_DIR}/${frameworks_dir}/SDL_ttf.framework)
- execute_process(COMMAND cp -pPR ${SDLMIXER_LIBRARY} ${CMAKE_BINARY_DIR}/${frameworks_dir}/SDL_mixer.framework)
- execute_process(COMMAND cp -pPR ${OGG_LIBRARY} ${CMAKE_BINARY_DIR}/${frameworks_dir}/Ogg.framework)
- execute_process(COMMAND cp -pPR ${VORBIS_LIBRARY} ${CMAKE_BINARY_DIR}/${frameworks_dir}/Vorbis.framework)
+ execute_process(COMMAND cp -pPR ${sdl_library_only} ${target_library_install_dir}/SDL.framework)
+ execute_process(COMMAND cp -pPR ${SDLIMAGE_LIBRARY} ${target_library_install_dir}/SDL_image.framework)
+ execute_process(COMMAND cp -pPR ${SDLNET_LIBRARY} ${target_library_install_dir}/SDL_net.framework)
+ execute_process(COMMAND cp -pPR ${SDLTTF_LIBRARY} ${target_library_install_dir}/SDL_ttf.framework)
+ execute_process(COMMAND cp -pPR ${SDLMIXER_LIBRARY} ${target_library_install_dir}/SDL_mixer.framework)
+ execute_process(COMMAND cp -pPR ${OGG_LIBRARY} ${target_library_install_dir}/Ogg.framework)
+ execute_process(COMMAND cp -pPR ${VORBIS_LIBRARY} ${target_library_install_dir}/Vorbis.framework)
if(${SPARKLE_FOUND})
execute_process(COMMAND cp -pPR ${SPARKLE_LIBRARY} ${CMAKE_BINARY_DIR}/${frameworks_dir}/Sparkle.framework)