# HG changeset patch # User koda # Date 1371483601 -7200 # Node ID 2bf3796c58551a23af3f68663d4cb35ec863e073 # Parent e653e96b0ec32a81084b3bb4ac4ce659ef807400# Parent a6ae0286787c9bb095cd72b13bd13f7074632110 This commit changes many aspect of our cmake build system - shared libraries are compiled by default: * this modifies RPATH of unix executables; * this will prevent a lot of linking issues, esp. from pascal world; * the old behaviour (static libs) is still available with -DBUILD_SHARED_LIBS=off; * of course in this case you have to provide the full list of dependencies with FPFLAGS and CMAKE_C_FLAGS; - pascal is now fully integrated with cmake, meaning you can just do add_sources and use CMAKE_Pascal_FLAGS: * some of the language features are only partially implemented, for example .inc files will not get rebuilt if you modify them; * target_link_libraries for pascal targets is just dummy as linking is determined within pascal files; * universal builds for osx are not available any more; - bundled libraries and system libraries are addressed using the target name: * this avoids depedency tracking; * this allows to name output as we wish. diff -r e653e96b0ec3 -r 2bf3796c5855 CMakeLists.txt --- a/CMakeLists.txt Mon Jun 17 10:48:50 2013 -0400 +++ b/CMakeLists.txt Mon Jun 17 17:40:01 2013 +0200 @@ -1,7 +1,7 @@ project(hedgewars) #initialise cmake environment -cmake_minimum_required(VERSION 2.6.0) +cmake_minimum_required(VERSION 2.6.4) foreach(hwpolicy CMP0003 CMP0012 CMP0017 CMP0018) if(POLICY ${hwpolicy}) cmake_policy(SET ${hwpolicy} NEW) @@ -9,16 +9,24 @@ endforeach() set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules") - +include(${CMAKE_MODULE_PATH}/utils.cmake) #possible cmake configuration option(NOSERVER "Disable gameServer build (off)]" OFF) option(NOPNG "Disable screenshoot compression (off)" OFF) option(NOVIDEOREC "Disable video recording (off)" OFF) +#libraries are built shared unless explicitly added as a static +option(BUILD_SHARED_LIBS "Build libraries as shared modules (on)" ON) #set this to ON when 2.1.0 becomes more widespread (and only for linux) option(PHYSFS_SYSTEM "Use system physfs (off)" OFF) +if(WIN32 OR APPLE) + option(LUA_SYSTEM "Use system lua (off)" OFF) +else() + option(LUA_SYSTEM "Use system lua (on)" ON) +endif() + option(BUILD_ENGINE_LIBRARY "Enable hwengine library (off)" OFF) option(ANDROID "Enable Android build (off)" OFF) @@ -45,41 +53,11 @@ message(STATUS "Building ${HEDGEWARS_VERSION}-r${HEDGEWARS_REVISION} (${HEDGEWARS_HASH})") - -#where to build libs and bins -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) -set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) - -#resource paths -if(UNIX AND NOT APPLE) - set(target_binary_install_dir "bin") - set(target_library_install_dir "lib") - - string(SUBSTRING "${DATA_INSTALL_DIR}" 0 1 sharepath_start) - if (NOT (${sharepath_start} MATCHES "/")) - set(HEDGEWARS_DATADIR "${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/") - else() - set(HEDGEWARS_DATADIR "${DATA_INSTALL_DIR}/") - endif() - set(HEDGEWARS_FULL_DATADIR "${HEDGEWARS_DATADIR}") -else() - set(target_binary_install_dir "./") - - if(APPLE) - set(target_library_install_dir "../Frameworks/") - set(CMAKE_INSTALL_PREFIX "Hedgewars.app/Contents/MacOS/") - set(HEDGEWARS_DATADIR "../Resources/") - set(HEDGEWARS_FULL_DATADIR "/Applications/${CMAKE_INSTALL_PREFIX}/${HEDGEWARS_DATADIR}") - elseif(WIN32) - set(target_library_install_dir "./") - set(HEDGEWARS_DATADIR "./") - set(HEDGEWARS_FULL_DATADIR "${CMAKE_INSTALL_PREFIX}/") - link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin") - endif() -endif() - +#general utilities +include(${CMAKE_MODULE_PATH}/utils.cmake) #platform specific init code include(${CMAKE_MODULE_PATH}/platform.cmake) +include(${CMAKE_MODULE_PATH}/paths.cmake) #when build type is not specified, assume Debug/Release according to build version information @@ -101,77 +79,73 @@ if(NOT ${MINIMAL_FLAGS}) set(CMAKE_C_FLAGS "-pipe ${CMAKE_C_FLAGS}") set(CMAKE_C_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_C_FLAGS_RELEASE}") - set(CMAKE_C_FLAGS_DEBUG "-Wall -O0 -g -DDEBUG ${CMAKE_C_FLAGS_DEBUG}") - set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS}) - set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE}) - set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) + set(CMAKE_C_FLAGS_DEBUG "-Wall -O0 -g ${CMAKE_C_FLAGS_DEBUG}") + set(CMAKE_CXX_FLAGS "-pipe ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS_RELEASE "-w -Os -fomit-frame-pointer ${CMAKE_CXX_FLAGS_RELEASE}") + set(CMAKE_CXX_FLAGS_DEBUG "-Wall -O0 -g ${CMAKE_CXX_FLAGS_DEBUG}") else() #CMake adds a lot of additional configuration flags, so let's clear them up set(CMAKE_C_FLAGS_RELEASE "") - set(CMAKE_C_FLAGS_DEBUG "-Wall -DDEBUG") + set(CMAKE_C_FLAGS_DEBUG "-Wall") set(CMAKE_CXX_FLAGS_RELEASE "") - set(CMAKE_CXX_FLAGS_DEBUG "-Wall -DDEBUG") + set(CMAKE_CXX_FLAGS_DEBUG "-Wall") endif() #parse additional parameters -if(FPFLAGS OR GHFLAGS) - if(CMAKE_VERSION VERSION_GREATER "2.6") - separate_arguments(fpflags_parsed UNIX_COMMAND ${FPFLAGS}) +if(FPFLAGS) + add_flag_prepend(CMAKE_Pascal_FLAGS ${FPFLAGS}) +endif() +if(GHFLAGS) + if(${allow_parse_args}) separate_arguments(ghflags_parsed UNIX_COMMAND ${GHFLAGS}) else() - message("*** FPFLAGS and GHFLAGS are available only when using CMake >= 2.8 ***") + message(${WARNING} "FPFLAGS and GHFLAGS are available only when using CMake >= 2.8") endif() endif() -list(APPEND pascal_flags ${fpflags_parsed} # user flags - "-B" # compile all units - "-vm4079,4080,4081" # fpc verbosity output format - "-FE${PROJECT_BINARY_DIR}/bin" # fpc binaries output directory - "-FU${PROJECT_BINARY_DIR}/hedgewars" # fpc units output directory - "-Fl${PROJECT_BINARY_DIR}/bin" # fpc linking directory (win/unix) - "-Fi${PROJECT_BINARY_DIR}/hedgewars" # fpc .inc path (for out of source builds) - "-k-L${PROJECT_BINARY_DIR}/bin" # ld linking directory (unix/osx) - "-Cs2000000" # stack size - "-vewnq" # fpc output verbosity - "-dDEBUGFILE" # macro for engine output - ) + list(APPEND haskell_flags ${ghflags_parsed} # user flags "-O2" # optimise for faster code ) +#-vm4079,4080,4081 +add_flag_append(CMAKE_Pascal_FLAGS "-Cs2000000") +add_flag_append(CMAKE_Pascal_FLAGS_DEBUG "-O- -gv") +add_flag_append(CMAKE_Pascal_FLAGS_RELEASE "-Os -Xs") #get BUILD_TYPE and enable/disable optimisation message(STATUS "Using ${CMAKE_BUILD_TYPE} configuration") if(CMAKE_BUILD_TYPE MATCHES "DEBUG") - list(APPEND pascal_flags "-O-" # disable all optimisations - "-g" # enable debug symbols - "-gl" # add line info to bt - "-gv" # allow valgrind - ) list(APPEND haskell_flags "-Wall" # all warnings "-debug" # debug mode "-dcore-lint" # internal sanity check ) else() - list(APPEND pascal_flags "-Os" # optimise for size - "-Xs" # strip binary - "-Si" # turn on inlining - ) list(APPEND haskell_flags "-w" # no warnings ) endif() -include(${CMAKE_MODULE_PATH}/utils.cmake) #lua discovery -find_package(Lua) -if(LUA_FOUND) - message(STATUS "Found LUA: ${LUA_DEFAULT}") +if (${LUA_SYSTEM}) + if (NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR) + find_package(Lua) + endif() + + if (LUA_LIBRARY AND LUA_INCLUDE_DIR) + set(LUA_FOUND TRUE) + #use an IMPORTED tharget so that we can just use 'lua' to link + add_library(lua UNKNOWN IMPORTED) + set_target_properties(lua PROPERTIES IMPORTED_LOCATION ${LUA_LIBRARY}) + else() + message(FATAL_ERROR "Missing Lua! Rerun cmake with -DLUA_SYSTEM=off to build the internal version") + endif() else() - message(STATUS "LUA will be provided by the bundled sources") + if (NOT LUA_LIBRARY OR NOT LUA_INCLUDE_DIR) + message(STATUS "LUA will be provided by the bundled sources") + endif() + set(lua_output_name "hwlua") add_subdirectory(misc/liblua) - #linking with liblua.a requires system readline - list(APPEND pascal_flags "-k${EXECUTABLE_OUTPUT_PATH}/lib${LUA_LIBRARY}.a" "-k-lreadline") endif() @@ -199,15 +173,17 @@ if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR) message(FATAL_ERROR "Missing PhysFS! Rerun cmake with -DPHYSFS_SYSTEM=off to build the internal version") + else() + #use an IMPORTED tharget so that we can just use 'physfs' to link + add_library(physfs UNKNOWN IMPORTED) + set_target_properties(physfs PROPERTIES IMPORTED_LOCATION ${PHYSFS_LIBRARY}) endif() else() - message(STATUS "PhysFS will be provided by the bundled sources") - set(physfs_output_name "hw_physfs") + if (NOT PHYSFS_LIBRARY OR NOT PHYSFS_INCLUDE_DIR) + message(STATUS "PhysFS will be provided by the bundled sources") + endif() + set(physfs_output_name "hwphysfs") add_subdirectory(misc/libphysfs) - #-XLA is a beta fpc flag that renames libraries before passing them to the linker - #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements - #(should be harmless on other platforms) - list(APPEND pascal_flags "-XLAphysfs=${physfs_output_name}" "-dPHYSFS_INTERNAL") endif() find_package_or_disable_msg(FFMPEG NOVIDEOREC "Video recording will not be built") diff -r e653e96b0ec3 -r 2bf3796c5855 QTfrontend/CMakeLists.txt --- a/QTfrontend/CMakeLists.txt Mon Jun 17 10:48:50 2013 -0400 +++ b/QTfrontend/CMakeLists.txt Mon Jun 17 17:40:01 2013 +0200 @@ -189,13 +189,8 @@ ${hwfr_rez_src} ) -if((UNIX AND NOT APPLE) AND ${BUILD_ENGINE_LIBRARY}) - set_target_properties(hedgewars PROPERTIES LINK_FLAGS "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/${target_library_install_dir}") -endif() - list(APPEND HW_LINK_LIBS - ${PHYSFS_LIBRARY} - ${PHYSLAYER_LIBRARY} + physfs physlayer ${QT_LIBRARIES} ${SDL_LIBRARY} ${SDLMIXER_LIBRARY} diff -r e653e96b0ec3 -r 2bf3796c5855 QTfrontend/campaign.cpp --- a/QTfrontend/campaign.cpp Mon Jun 17 10:48:50 2013 -0400 +++ b/QTfrontend/campaign.cpp Mon Jun 17 17:40:01 2013 +0200 @@ -53,11 +53,11 @@ QString getCampaignImage(QString campaign, unsigned int mNum) { - return getCampaignScript(campaign,mNum).replace(QString(".lua"),QString(".png")); + return getCampaignScript(campaign,mNum).replace(QString(".lua"),QString(".png")); } -QString getCampaignMissionName(QString campaign, unsigned int mNum) +QString getCampaignMissionName(QString campaign, unsigned int mNum) { - return getCampaignScript(campaign,mNum).replace(QString(".lua"),QString("")); + return getCampaignScript(campaign,mNum).replace(QString(".lua"),QString("")); } diff -r e653e96b0ec3 -r 2bf3796c5855 QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Mon Jun 17 10:48:50 2013 -0400 +++ b/QTfrontend/hwform.cpp Mon Jun 17 17:40:01 2013 +0200 @@ -194,8 +194,8 @@ //connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload())); #endif - previousCampaignName = ""; - previousTeamName = ""; + previousCampaignName = ""; + previousTeamName = ""; UpdateTeamsLists(); InitCampaignPage(); UpdateCampaignPage(0); @@ -1894,7 +1894,7 @@ void HWForm::UpdateCampaignPage(int index) { Q_UNUSED(index); - + HWTeam team(ui.pageCampaign->CBTeam->currentText()); ui.pageCampaign->CBMission->clear(); @@ -1903,61 +1903,61 @@ QString tName = team.name(); unsigned int n = missionEntries.count(); unsigned int m = getCampProgress(tName, campaignName); - + // if the campaign name changes update the campaignMissionDescriptions list // this will be used later in UpdateCampaignPageMission() to update // the mission description in the campaign page bool updateMissionList = false; QSettings * m_info; - if(previousCampaignName.compare(campaignName)!=0 || - previousTeamName.compare(tName) != 0) + if(previousCampaignName.compare(campaignName)!=0 || + previousTeamName.compare(tName) != 0) { - if (previousTeamName.compare(tName) != 0 && - previousTeamName.compare("") != 0) - index = qMin(m + 1, n); - previousCampaignName = campaignName; - previousTeamName = tName; - updateMissionList = true; - // the following code was based on pagetraining.cpp - DataManager & dataMgr = DataManager::instance(); - // get locale - QSettings settings(dataMgr.settingsFileName(), - QSettings::IniFormat); - QString loc = settings.value("misc/locale", "").toString(); - if (loc.isEmpty()) - loc = QLocale::system().name(); - QString campaignDescFile = QString("physfs://Locale/campaigns_" + loc + ".txt"); - // if file is non-existant try with language only - if (!QFile::exists(campaignDescFile)) - campaignDescFile = QString("physfs://Locale/campaigns_" + loc.remove(QRegExp("_.*$")) + ".txt"); + if (previousTeamName.compare(tName) != 0 && + previousTeamName.compare("") != 0) + index = qMin(m + 1, n); + previousCampaignName = campaignName; + previousTeamName = tName; + updateMissionList = true; + // the following code was based on pagetraining.cpp + DataManager & dataMgr = DataManager::instance(); + // get locale + QSettings settings(dataMgr.settingsFileName(), + QSettings::IniFormat); + QString loc = settings.value("misc/locale", "").toString(); + if (loc.isEmpty()) + loc = QLocale::system().name(); + QString campaignDescFile = QString("physfs://Locale/campaigns_" + loc + ".txt"); + // if file is non-existant try with language only + if (!QFile::exists(campaignDescFile)) + campaignDescFile = QString("physfs://Locale/campaigns_" + loc.remove(QRegExp("_.*$")) + ".txt"); - // fallback if file for current locale is non-existant - if (!QFile::exists(campaignDescFile)) - campaignDescFile = QString("physfs://Locale/campaigns_en.txt"); - - m_info = new QSettings(campaignDescFile, QSettings::IniFormat, this); - m_info->setIniCodec("UTF-8"); - campaignMissionDescriptions.clear(); - ui.pageCampaign->CBMission->clear(); - } - + // fallback if file for current locale is non-existant + if (!QFile::exists(campaignDescFile)) + campaignDescFile = QString("physfs://Locale/campaigns_en.txt"); + + m_info = new QSettings(campaignDescFile, QSettings::IniFormat, this); + m_info->setIniCodec("UTF-8"); + campaignMissionDescriptions.clear(); + ui.pageCampaign->CBMission->clear(); + } + for (unsigned int i = qMin(m + 1, n); i > 0; i--) { - if(updateMissionList) + if(updateMissionList) { - campaignMissionDescriptions += m_info->value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc", + campaignMissionDescriptions += m_info->value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc", tr("No description available")).toString(); - } - ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1])); + } + ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1])); } if(updateMissionList) - delete m_info; + delete m_info; UpdateCampaignPageMission(index); } -void HWForm::UpdateCampaignPageMission(int index) -{ +void HWForm::UpdateCampaignPageMission(int index) +{ // update thumbnail QString campaignName = ui.pageCampaign->CBCampaign->currentText(); unsigned int mNum = ui.pageCampaign->CBMission->count() - ui.pageCampaign->CBMission->currentIndex(); @@ -1967,9 +1967,9 @@ // when campaign changes the UpdateCampaignPageMission is triggered with wrong values // this will cause segfault. This check prevents illegal memory reads if(index > -1 && index < campaignMissionDescriptions.count()) { - ui.pageCampaign->lbltitle->setText("

"+ui.pageCampaign->CBMission->currentText()+"

"); - ui.pageCampaign->lbldescription->setText(campaignMissionDescriptions[index]); - } + ui.pageCampaign->lbltitle->setText("

"+ui.pageCampaign->CBMission->currentText()+"

"); + ui.pageCampaign->lbldescription->setText(campaignMissionDescriptions[index]); + } } void HWForm::UpdateCampaignPageProgress(int index) diff -r e653e96b0ec3 -r 2bf3796c5855 QTfrontend/net/tcpBase.cpp --- a/QTfrontend/net/tcpBase.cpp Mon Jun 17 10:48:50 2013 -0400 +++ b/QTfrontend/net/tcpBase.cpp Mon Jun 17 17:40:01 2013 +0200 @@ -134,7 +134,7 @@ connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); QStringList arguments=getArguments(); -#ifdef DEBUG +#ifdef QT_DEBUG // redirect everything written on stdout/stderr process->setProcessChannelMode(QProcess::ForwardedChannels); #endif diff -r e653e96b0ec3 -r 2bf3796c5855 QTfrontend/ui/page/pagecampaign.cpp --- a/QTfrontend/ui/page/pagecampaign.cpp Mon Jun 17 10:48:50 2013 -0400 +++ b/QTfrontend/ui/page/pagecampaign.cpp Mon Jun 17 17:40:01 2013 +0200 @@ -31,7 +31,7 @@ pageLayout->setColumnStretch(2, 1); pageLayout->setRowStretch(0, 1); pageLayout->setRowStretch(3, 1); - + QGridLayout * infoLayout = new QGridLayout(); infoLayout->setColumnStretch(0, 1); infoLayout->setColumnStretch(1, 1); @@ -40,27 +40,27 @@ infoLayout->setColumnStretch(4, 1); infoLayout->setRowStretch(0, 1); infoLayout->setRowStretch(1, 1); - + // set this as default image first time page is created, this will change in hwform.cpp btnPreview = formattedButton(":/res/campaign/A Classic Fairytale/first_blood.png", true); - infoLayout->setAlignment(btnPreview, Qt::AlignHCenter | Qt::AlignVCenter); - + infoLayout->setAlignment(btnPreview, Qt::AlignHCenter | Qt::AlignVCenter); + lbldescription = new QLabel(); lbldescription->setAlignment(Qt::AlignHCenter| Qt::AlignTop); lbldescription->setWordWrap(true); - + lbltitle = new QLabel(); lbltitle->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); CBTeam = new QComboBox(this); CBMission = new QComboBox(this); CBCampaign = new QComboBox(this); - - infoLayout->addWidget(btnPreview,0,1,2,1); - infoLayout->addWidget(lbltitle,0,2,1,2); - infoLayout->addWidget(lbldescription,1,2,1,2); - - pageLayout->addLayout(infoLayout, 0, 0, 2, 3); + + infoLayout->addWidget(btnPreview,0,1,2,1); + infoLayout->addWidget(lbltitle,0,2,1,2); + infoLayout->addWidget(lbldescription,1,2,1,2); + + pageLayout->addLayout(infoLayout, 0, 0, 2, 3); pageLayout->addWidget(CBTeam, 2, 1); pageLayout->addWidget(CBCampaign, 3, 1); pageLayout->addWidget(CBMission, 4, 1); diff -r e653e96b0ec3 -r 2bf3796c5855 QTfrontend/ui/page/pagecampaign.h --- a/QTfrontend/ui/page/pagecampaign.h Mon Jun 17 10:48:50 2013 -0400 +++ b/QTfrontend/ui/page/pagecampaign.h Mon Jun 17 17:40:01 2013 +0200 @@ -28,7 +28,7 @@ public: PageCampaign(QWidget* parent = 0); - QPushButton *btnPreview; + QPushButton *btnPreview; QPushButton *BtnStartCampaign; QLabel *lbldescription; QLabel *lbltitle; diff -r e653e96b0ec3 -r 2bf3796c5855 QTfrontend/ui/page/pagemain.cpp --- a/QTfrontend/ui/page/pagemain.cpp Mon Jun 17 10:48:50 2013 -0400 +++ b/QTfrontend/ui/page/pagemain.cpp Mon Jun 17 17:40:01 2013 +0200 @@ -133,7 +133,7 @@ setAttribute(Qt::WA_NoSystemBackground, true); mainNote->setOpenExternalLinks(true); -#ifdef DEBUG +#ifdef QT_DEBUG setDefaultDescription(QLabel::tr("This development build is 'work in progress' and may not be compatible with other versions of the game, while some features might be broken or incomplete!")); #else setDefaultDescription(QLabel::tr("Tip: %1").arg(randomTip())); diff -r e653e96b0ec3 -r 2bf3796c5855 QTfrontend/ui_hwform.cpp --- a/QTfrontend/ui_hwform.cpp Mon Jun 17 10:48:50 2013 -0400 +++ b/QTfrontend/ui_hwform.cpp Mon Jun 17 17:40:01 2013 +0200 @@ -55,7 +55,7 @@ HWForm->resize(QSize(640, 480).expandedTo(HWForm->minimumSizeHint())); HWForm->setMinimumSize(QSize(720, 450)); QString title = QMainWindow::tr("Hedgewars %1").arg(*cVersionString); -#ifdef DEBUG +#ifdef QT_DEBUG title += QString("-r%1 (%2)").arg(*cRevisionString, *cHashString); #endif HWForm->setWindowTitle(title); diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/CMakeDeterminePascalCompiler.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake_modules/CMakeDeterminePascalCompiler.cmake Mon Jun 17 17:40:01 2013 +0200 @@ -0,0 +1,65 @@ +# Determine the compiler to use for Pascal programs +# NOTE, a generator may set CMAKE_Pascal_COMPILER before +# loading this file to force a compiler. +# use environment variable Pascal first if defined by user, next use +# the cmake variable CMAKE_GENERATOR_PASCAL which can be defined by a generator +# as a default compiler + +if(NOT CMAKE_Pascal_COMPILER) + # prefer the environment variable FPC + if($ENV{FPC} MATCHES ".+") + get_filename_component(CMAKE_Pascal_COMPILER_INIT $ENV{FPC} PROGRAM PROGRAM_ARGS CMAKE_Pascal_FLAGS_ENV_INIT) + if(CMAKE_Pascal_FLAGS_ENV_INIT) + set(CMAKE_Pascal_COMPILER_ARG1 "${CMAKE_Pascal_FLAGS_ENV_INIT}" CACHE STRING "First argument to Pascal compiler") + endif(CMAKE_Pascal_FLAGS_ENV_INIT) + if(EXISTS ${CMAKE_Pascal_COMPILER_INIT}) + else(EXISTS ${CMAKE_Pascal_COMPILER_INIT}) + message(FATAL_ERROR "Could not find compiler set in environment variable FPC:\n$ENV{FPC}.") + endif(EXISTS ${CMAKE_Pascal_COMPILER_INIT}) + endif($ENV{FPC} MATCHES ".+") + + # next try prefer the compiler specified by the generator + if(CMAKE_GENERATOR_PASCAL) + if(NOT CMAKE_Pascal_COMPILER_INIT) + set(CMAKE_Pascal_COMPILER_INIT ${CMAKE_GENERATOR_PASCAL}) + endif(NOT CMAKE_Pascal_COMPILER_INIT) + endif(CMAKE_GENERATOR_PASCAL) + + # finally list compilers to try + if(CMAKE_Pascal_COMPILER_INIT) + set(CMAKE_Pascal_COMPILER_LIST ${CMAKE_Pascal_COMPILER_INIT}) + else(CMAKE_Pascal_COMPILER_INIT) + set(CMAKE_Pascal_COMPILER_LIST fpc) + endif(CMAKE_Pascal_COMPILER_INIT) + + # Find the compiler. + find_program(CMAKE_Pascal_COMPILER NAMES ${CMAKE_Pascal_COMPILER_LIST} DOC "Pascal compiler") + if(CMAKE_Pascal_COMPILER_INIT AND NOT CMAKE_Pascal_COMPILER) + set(CMAKE_Pascal_COMPILER "${CMAKE_Pascal_COMPILER_INIT}" CACHE FILEPATH "Pascal compiler" FORCE) + endif(CMAKE_Pascal_COMPILER_INIT AND NOT CMAKE_Pascal_COMPILER) +endif(NOT CMAKE_Pascal_COMPILER) +mark_as_advanced(CMAKE_Pascal_COMPILER) + +if(NOT CMAKE_Pascal_COMPILER_VERSION) + execute_process(COMMAND ${CMAKE_Pascal_COMPILER} -iV + OUTPUT_VARIABLE CMAKE_Pascal_COMPILER_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) # we assume no error for something so simple +endif(NOT CMAKE_Pascal_COMPILER_VERSION) +mark_as_advanced(CMAKE_Pascal_COMPILER_VERSION) + +get_filename_component(COMPILER_LOCATION "${CMAKE_Pascal_COMPILER}" PATH) + +# configure variables set in this file for fast reload later on +if(${CMAKE_VERSION} VERSION_LESS 2.8.10) + configure_file(${CMAKE_MODULE_PATH}/CMakePascalCompiler.cmake.in + "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakePascalCompiler.cmake" + IMMEDIATE ) +else(${CMAKE_VERSION} VERSION_LESS 2.8.10) + configure_file(${CMAKE_MODULE_PATH}/CMakePascalCompiler.cmake.in + "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${CMAKE_VERSION}/CMakePascalCompiler.cmake" + IMMEDIATE ) +endif(${CMAKE_VERSION} VERSION_LESS 2.8.10) + +set(CMAKE_Pascal_COMPILER_ENV_VAR "FPC") + diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/CMakePascalCompiler.cmake.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake_modules/CMakePascalCompiler.cmake.in Mon Jun 17 17:40:01 2013 +0200 @@ -0,0 +1,12 @@ +set(CMAKE_Pascal_COMPILER "@CMAKE_Pascal_COMPILER@") +set(CMAKE_Pascal_COMPILER_ARG1 "@CMAKE_Pascal_COMPILER_ARG1@") +set(CMAKE_Pascal_COMPILER_LOADED 1) +set(CMAKE_Pascal_COMPILER_VERSION "@CMAKE_Pascal_COMPILER_VERSION@") + +set(CMAKE_Pascal_COMPILER_ENV_VAR "FPC") + +set(CMAKE_Pascal_SOURCE_FILE_EXTENSIONS "pas" "pp") +set(CMAKE_Pascal_IGNORE_EXTENSIONS ppu;PPU;h;H;o;O;obj;OBJ;def;DEF;rc;RC) +set(CMAKE_Pascal_LINKER_PREFERENCE Prefered) +set(CMAKE_Pascal_OUTPUT_EXTENSION_REPLACE 1) +set(CMAKE_Pascal_OUTPUT_EXTENSION ".o") diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/CMakePascalInformation.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake_modules/CMakePascalInformation.cmake Mon Jun 17 17:40:01 2013 +0200 @@ -0,0 +1,208 @@ +# This file sets the basic flags for the Pascal language in CMake. +# It also loads the available platform file for the system-compiler +# if it exists. + +get_filename_component(CMAKE_BASE_NAME ${CMAKE_Pascal_COMPILER} NAME_WE) +set(CMAKE_SYSTEM_AND_Pascal_COMPILER_INFO_FILE + ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake) +include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL) + +# This section should actually be in Platform/${CMAKE_SYSTME_NAME}-fpc.cmake +set(CMAKE_Pascal_FLAGS_INIT "-l- -v0ewn") +set(CMAKE_Pascal_FLAGS_DEBUG_INIT "-g -gl -gp -gh") +set(CMAKE_Pascal_FLAGS_MINSIZEREL_INIT "-Os -dNDEBUG") +set(CMAKE_Pascal_FLAGS_RELEASE_INIT "-O3 -dNDEBUG") +set(CMAKE_Pascal_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -gl -gp") + +# This should be included before the _INIT variables are +# used to initialize the cache. Since the rule variables +# have if blocks on them, users can still define them here. +# But, it should still be after the platform file so changes can +# be made to those values. + +if(CMAKE_USER_MAKE_RULES_OVERRIDE) + include(${CMAKE_USER_MAKE_RULES_OVERRIDE}) +endif(CMAKE_USER_MAKE_RULES_OVERRIDE) + +if(CMAKE_USER_MAKE_RULES_OVERRIDE_Pascal) + include(${CMAKE_USER_MAKE_RULES_OVERRIDE_Pascal}) +endif(CMAKE_USER_MAKE_RULES_OVERRIDE_Pascal) + +# Create a set of shared library variable specific to Pascal +# For 90% of the systems, these are the same flags as the C versions +# so if these are not set just copy the flags from the c version + +# No flags supported during linking as a shell script takes care of it +if(NOT CMAKE_SHARED_LIBRARY_CREATE_Pascal_FLAGS) +#-dynamiclib -Wl,-headerpad_max_install_names for C + set(CMAKE_SHARED_LIBRARY_CREATE_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}) +endif(NOT CMAKE_SHARED_LIBRARY_CREATE_Pascal_FLAGS) + +if(NOT CMAKE_SHARED_LIBRARY_Pascal_FLAGS) + #another similarity, fpc: -fPIC Same as -Cg + #(maybe required only for x86_64) + set(CMAKE_SHARED_LIBRARY_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS}) +endif(NOT CMAKE_SHARED_LIBRARY_Pascal_FLAGS) + +if(NOT CMAKE_SHARED_LIBRARY_LINK_Pascal_FLAGS) + set(CMAKE_SHARED_LIBRARY_LINK_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}) +endif(NOT CMAKE_SHARED_LIBRARY_LINK_Pascal_FLAGS) + +#if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG) +# set(CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}) +#endif(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG) + +#if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG_SEP) +# set(CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP}) +#endif(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Pascal_FLAG_SEP) + +if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_Pascal_FLAG) + set(CMAKE_SHARED_LIBRARY_RPATH_LINK_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG}) +endif(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_Pascal_FLAG) + +# for most systems a module is the same as a shared library +# so unless the variable CMAKE_MODULE_EXISTS is set just +# copy the values from the LIBRARY variables +if(NOT CMAKE_MODULE_EXISTS) + set(CMAKE_SHARED_MODULE_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_Pascal_FLAGS}) + set(CMAKE_SHARED_MODULE_CREATE_Pascal_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_Pascal_FLAGS}) +endif(NOT CMAKE_MODULE_EXISTS) + +# repeat for modules +if(NOT CMAKE_SHARED_MODULE_CREATE_Pascal_FLAGS) + set(CMAKE_SHARED_MODULE_CREATE_Pascal_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS}) +endif(NOT CMAKE_SHARED_MODULE_CREATE_Pascal_FLAGS) + +if(NOT CMAKE_SHARED_MODULE_Pascal_FLAGS) + set(CMAKE_SHARED_MODULE_Pascal_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS}) +endif(NOT CMAKE_SHARED_MODULE_Pascal_FLAGS) + +if(NOT CMAKE_SHARED_MODULE_RUNTIME_Pascal_FLAG) + set(CMAKE_SHARED_MODULE_RUNTIME_Pascal_FLAG ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG}) +endif(NOT CMAKE_SHARED_MODULE_RUNTIME_Pascal_FLAG) + +if(NOT CMAKE_SHARED_MODULE_RUNTIME_Pascal_FLAG_SEP) + set(CMAKE_SHARED_MODULE_RUNTIME_Pascal_FLAG_SEP ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG_SEP}) +endif(NOT CMAKE_SHARED_MODULE_RUNTIME_Pascal_FLAG_SEP) + +if(NOT CMAKE_INCLUDE_FLAG_Pascal) + #amazing, fpc: -I Add to include path + set(CMAKE_INCLUDE_FLAG_Pascal ${CMAKE_INCLUDE_FLAG_C}) +endif(NOT CMAKE_INCLUDE_FLAG_Pascal) + +if(NOT CMAKE_INCLUDE_FLAG_SEP_Pascal) + set(CMAKE_INCLUDE_FLAG_SEP_Pascal ${CMAKE_INCLUDE_FLAG_SEP_C}) +endif(NOT CMAKE_INCLUDE_FLAG_SEP_Pascal) + +# Copy C version of this flag which is normally determined in platform file. +if(NOT CMAKE_SHARED_LIBRARY_SONAME_Pascal_FLAG) + set(CMAKE_SHARED_LIBRARY_SONAME_Pascal_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG}) +endif(NOT CMAKE_SHARED_LIBRARY_SONAME_Pascal_FLAG) + +set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.") + +set(CMAKE_Pascal_FLAGS "$ENV{FPFLAGS} ${CMAKE_Pascal_FLAGS_INIT} ${CMAKE_Pascal_FLAGS}" CACHE STRING "Flags for Pascal compiler.") + +include(CMakeCommonLanguageInclude) + +# now define the following rule variables + +# CMAKE_Pascal_CREATE_SHARED_LIBRARY +# CMAKE_Pascal_CREATE_SHARED_MODULE +# CMAKE_Pascal_CREATE_STATIC_LIBRARY +# CMAKE_Pascal_COMPILE_OBJECT +# CMAKE_Pascal_LINK_EXECUTABLE + +# variables supplied by the generator at use time +# +# the target without the suffix +# +# +# +# +# + +# Pascal compiler information +# +# +# +# + +# Static library tools +# NONE! + +if(NOT EXECUTABLE_OUTPUT_PATH) + set (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) +endif(NOT EXECUTABLE_OUTPUT_PATH) + +# create a Pascal shared library +if(NOT CMAKE_Pascal_CREATE_SHARED_LIBRARY) + if(WIN32) + set(CMAKE_Pascal_CREATE_SHARED_LIBRARY "${EXECUTABLE_OUTPUT_PATH}/ppas.bat") + else(WIN32) + set(CMAKE_Pascal_CREATE_SHARED_LIBRARY "${EXECUTABLE_OUTPUT_PATH}/ppas.sh") + endif(WIN32) +# other expandable variables here are +endif(NOT CMAKE_Pascal_CREATE_SHARED_LIBRARY) + +# create an Pascal shared module just copy the shared library rule +if(NOT CMAKE_Pascal_CREATE_SHARED_MODULE) + set(CMAKE_Pascal_CREATE_SHARED_MODULE ${CMAKE_Pascal_CREATE_SHARED_LIBRARY}) +endif(NOT CMAKE_Pascal_CREATE_SHARED_MODULE) + +# create an Pascal static library (unsupported) +if(NOT CMAKE_Pascal_CREATE_STATIC_LIBRARY) + set(CMAKE_Pascal_CREATE_STATIC_LIBRARY + "echo STATIC LIBRARIES ARE NOT SUPPORTED" "exit") +endif(NOT CMAKE_Pascal_CREATE_STATIC_LIBRARY) + +# compile a Pascal file into an object file +if(NOT CMAKE_Pascal_COMPILE_OBJECT) + if(UNIX) + #when you have multiple ld installation make sure you get the one bundled with the system C compiler + include(Platform/${CMAKE_SYSTEM_NAME}-GNU-C.cmake OPTIONAL) + if(CMAKE_C_COMPILER) + get_filename_component(CMAKE_C_COMPILER_DIR ${CMAKE_C_COMPILER} PATH) + set(CMAKE_Pascal_UNIX_FLAGS "-FD${CMAKE_C_COMPILER_DIR}") + endif(CMAKE_C_COMPILER) + if(APPLE) + #add user framework directory + set(CMAKE_Pascal_UNIX_FLAGS "-Ff~/Library/Frameworks ${CMAKE_Pascal_UNIX_FLAGS}") + endif(APPLE) + endif(UNIX) + + set(CMAKE_Pascal_COMPILE_OBJECT + " -Cn -FE${EXECUTABLE_OUTPUT_PATH} -FU${CMAKE_CURRENT_BINARY_DIR}/ ${CMAKE_Pascal_UNIX_FLAGS} ") +endif(NOT CMAKE_Pascal_COMPILE_OBJECT) + +# link Pascal objects in a single executable +if(NOT CMAKE_Pascal_LINK_EXECUTABLE) + if(WIN32) + set(CMAKE_Pascal_LINK_EXECUTABLE "${EXECUTABLE_OUTPUT_PATH}/ppas.bat") + else(WIN32) + set(CMAKE_Pascal_LINK_EXECUTABLE "${EXECUTABLE_OUTPUT_PATH}/ppas.sh") + endif(WIN32) +# other expandable variables here are +endif(NOT CMAKE_Pascal_LINK_EXECUTABLE) + +if(CMAKE_Pascal_STANDARD_LIBRARIES_INIT) + set(CMAKE_Pascal_STANDARD_LIBRARIES "${CMAKE_Pascal_STANDARD_LIBRARIES_INIT}" + CACHE STRING "Libraries linked by default (usually handled internally).") + mark_as_advanced(CMAKE_Pascal_STANDARD_LIBRARIES) +endif(CMAKE_Pascal_STANDARD_LIBRARIES_INIT) + +if(NOT CMAKE_NOT_USING_CONFIG_FLAGS) + set(CMAKE_Pascal_FLAGS_DEBUG "${CMAKE_Pascal_FLAGS_DEBUG_INIT}" CACHE STRING + "Flags used by the compiler during debug builds.") + set(CMAKE_Pascal_FLAGS_MINSIZEREL "${CMAKE_Pascal_FLAGS_MINSIZEREL_INIT}" CACHE STRING + "Flags used by the compiler during release minsize builds.") + set(CMAKE_Pascal_FLAGS_RELEASE "${CMAKE_Pascal_FLAGS_RELEASE_INIT}" CACHE STRING + "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).") + set(CMAKE_Pascal_FLAGS_RELWITHDEBINFO "${CMAKE_Pascal_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING + "Flags used by the compiler during Release with Debug Info builds.") +endif(NOT CMAKE_NOT_USING_CONFIG_FLAGS) + +mark_as_advanced(CMAKE_Pascal_FLAGS CMAKE_Pascal_FLAGS_DEBUG CMAKE_Pascal_FLAGS_MINSIZEREL + CMAKE_Pascal_FLAGS_RELEASE CMAKE_Pascal_FLAGS_RELWITHDEBINFO) +set(CMAKE_Pascal_INFORMATION_LOADED 1) + diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/CMakeTestPascalCompiler.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake_modules/CMakeTestPascalCompiler.cmake Mon Jun 17 17:40:01 2013 +0200 @@ -0,0 +1,53 @@ +# This file is used by EnableLanguage in cmGlobalGenerator to determine that +# the FreePascal can actually compile and link the most basic of programs. +# If not, a fatal error is set, cmake stops processing commands and will not +# generate any makefiles or projects. + +if(NOT CMAKE_Pascal_COMPILER_WORKS) + message(STATUS "Check for working Pascal compiler: ${CMAKE_Pascal_COMPILER}") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp/testpascalcompiler.pas + "program testPascalCompiler; + begin + end. + ") + + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp/CMakeLists.txt + "set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules) + set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL \"\" FORCE) + project(test Pascal) + add_executable(testpascalcompiler testpascalcompiler.pas) + ") + +# To avoid try_compile recurse error, use any binary directory other +# than ${CMAKE_BINARY_DIR}. The choice of +# bindir = ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp is +# especially advantageous since it makes an in-source build which +# means that no special variables need to be set to find files. + try_compile(CMAKE_Pascal_COMPILER_WORKS + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp + ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp + test + OUTPUT_VARIABLE RESULT_OUTPUT + ) + set(PASCAL_TEST_WAS_RUN 1) +endif(NOT CMAKE_Pascal_COMPILER_WORKS) + +if(NOT CMAKE_Pascal_COMPILER_WORKS) + message(STATUS "Check for working Pascal compiler: ${CMAKE_Pascal_COMPILER} -- broken") + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the Pascal compiler works failed with " + "the following output:\n${RESULT_OUTPUT}\n\n") + message(FATAL_ERROR "The Pascal builder \"${CMAKE_Pascal_COMPILER}\" " + "is not able to compile and link a simple test program.\nIt fails " + "with the following output:\n ${RESULT_OUTPUT}\n\n" + "CMake will not be able to correctly generate this project.") +else(NOT CMAKE_Pascal_COMPILER_WORKS) + if(PASCAL_TEST_WAS_RUN) + message(STATUS "Check for working Pascal compiler: ${CMAKE_Pascal_COMPILER} -- works") + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the Pascal compiler works passed with " + "the following output:\n${RESULT_OUTPUT}\n\n") + endif(PASCAL_TEST_WAS_RUN) + set(CMAKE_Pascal_COMPILER_WORKS 1 CACHE INTERNAL "") +endif(NOT CMAKE_Pascal_COMPILER_WORKS) + diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/FindFreePascal.cmake --- a/cmake_modules/FindFreePascal.cmake Mon Jun 17 10:48:50 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -# - Try to find the FreePascal executable -# Once done this will define -# -# FREEPASCAL_FOUND - system has Freepascal -# FREEPASCAL_VERSION - Freepascal version -# FREEPASCAL_EXECUTABLE - Freepascal executable -# -# Copyright (c) 2012, Bryan Dunsmore -# Copyright (c) 2013, Vittorio Giovara -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - - -find_program(FREEPASCAL_EXECUTABLE - NAMES fpc - PATHS /opt/local/bin /usr/local/bin /usr/bin - ) - -if (FREEPASCAL_EXECUTABLE) - # check Freepascal version - execute_process(COMMAND ${FREEPASCAL_EXECUTABLE} -iV - OUTPUT_VARIABLE FREEPASCAL_VERSION - ERROR_VARIABLE FREEPASCAL_VERSION_ERROR - RESULT_VARIABLE FREEPASCAL_VERSION_RESULT - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - if(NOT ${FREEPASCAL_VERSION_RESULT} EQUAL 0) - message(SEND_ERROR "Command \"${FREEPASCAL_EXECUTABLE} -iV\" failed with output: ${FREEPASCAL_VERSION_ERROR}") - endif() -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(FreePascal DEFAULT_MSG FREEPASCAL_EXECUTABLE FREEPASCAL_VERSION) -mark_as_advanced(FREEPASCAL_VERSION) - diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/FindGMP.cmake --- a/cmake_modules/FindGMP.cmake Mon Jun 17 10:48:50 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -FIND_PATH(GMP_INCLUDE_DIR gmp.h) - -FIND_LIBRARY(GMP_LIBRARY NAMES GMP gmp) - -IF (GMP_INCLUDE_DIR AND GMP_LIBRARY) - SET(GMP_FOUND TRUE) - ENDIF (GMP_INCLUDE_DIR AND GMP_LIBRARY) - - IF (GMP_FOUND) - IF (NOT GMP_FIND_QUIETLY) - MESSAGE(STATUS "Found GMP: ${GMP_LIBRARY}") - ENDIF (NOT GMP_FIND_QUIETLY) - ELSE (GMP_FOUND) - IF (GMP_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find GMP") - ENDIF (GMP_FIND_REQUIRED) -ENDIF (GMP_FOUND) diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/FindLibraryWithDebug.cmake --- a/cmake_modules/FindLibraryWithDebug.cmake Mon Jun 17 10:48:50 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -# -# FIND_LIBRARY_WITH_DEBUG -# -> enhanced FIND_LIBRARY to allow the search for an -# optional debug library with a WIN32_DEBUG_POSTFIX similar -# to CMAKE_DEBUG_POSTFIX when creating a shared lib -# it has to be the second and third argument - -# Copyright (c) 2007, Christian Ehrlicher, -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - -MACRO(FIND_LIBRARY_WITH_DEBUG var_name win32_dbg_postfix_name dgb_postfix libname) - - IF(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX") - - # no WIN32_DEBUG_POSTFIX -> simply pass all arguments to FIND_LIBRARY - FIND_LIBRARY(${var_name} - ${win32_dbg_postfix_name} - ${dgb_postfix} - ${libname} - ${ARGN} - ) - - ELSE(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX") - - IF(NOT WIN32) - # on non-win32 we don't need to take care about WIN32_DEBUG_POSTFIX - - FIND_LIBRARY(${var_name} ${libname} ${ARGN}) - - ELSE(NOT WIN32) - - # 1. get all possible libnames - SET(args ${ARGN}) - SET(newargs "") - SET(libnames_release "") - SET(libnames_debug "") - - LIST(LENGTH args listCount) - - IF("${libname}" STREQUAL "NAMES") - SET(append_rest 0) - LIST(APPEND args " ") - - FOREACH(i RANGE ${listCount}) - LIST(GET args ${i} val) - - IF(append_rest) - LIST(APPEND newargs ${val}) - ELSE(append_rest) - IF("${val}" STREQUAL "PATHS") - LIST(APPEND newargs ${val}) - SET(append_rest 1) - ELSE("${val}" STREQUAL "PATHS") - LIST(APPEND libnames_release "${val}") - LIST(APPEND libnames_debug "${val}${dgb_postfix}") - ENDIF("${val}" STREQUAL "PATHS") - ENDIF(append_rest) - - ENDFOREACH(i) - - ELSE("${libname}" STREQUAL "NAMES") - - # just one name - LIST(APPEND libnames_release "${libname}") - LIST(APPEND libnames_debug "${libname}${dgb_postfix}") - - SET(newargs ${args}) - - ENDIF("${libname}" STREQUAL "NAMES") - - # search the release lib - FIND_LIBRARY(${var_name}_RELEASE - NAMES ${libnames_release} - ${newargs} - ) - - # search the debug lib - FIND_LIBRARY(${var_name}_DEBUG - NAMES ${libnames_debug} - ${newargs} - ) - - IF(${var_name}_RELEASE AND ${var_name}_DEBUG) - - # both libs found - SET(${var_name} optimized ${${var_name}_RELEASE} - debug ${${var_name}_DEBUG}) - - ELSE(${var_name}_RELEASE AND ${var_name}_DEBUG) - - IF(${var_name}_RELEASE) - - # only release found - SET(${var_name} ${${var_name}_RELEASE}) - - ELSE(${var_name}_RELEASE) - - # only debug (or nothing) found - SET(${var_name} ${${var_name}_DEBUG}) - - ENDIF(${var_name}_RELEASE) - - ENDIF(${var_name}_RELEASE AND ${var_name}_DEBUG) - - MARK_AS_ADVANCED(${var_name}_RELEASE) - MARK_AS_ADVANCED(${var_name}_DEBUG) - - ENDIF(NOT WIN32) - - ENDIF(NOT "${win32_dbg_postfix_name}" STREQUAL "WIN32_DEBUG_POSTFIX") - -ENDMACRO(FIND_LIBRARY_WITH_DEBUG) diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/FindLua.cmake --- a/cmake_modules/FindLua.cmake Mon Jun 17 10:48:50 2013 -0400 +++ b/cmake_modules/FindLua.cmake Mon Jun 17 17:40:01 2013 +0200 @@ -1,37 +1,26 @@ -# Find the Lua library -# -------------------- -# On Android/Windows/OSX this just defines the name of the library that -# will be compiled from our bundled sources -# On Linux it will try to load the system library and fallback to compiling -# the bundled one when nothing is found - -set(LUA_FOUND false) -set(LUA_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/misc/liblua) +# Find liblua +# +# Once done this will define +# LUA_FOUND - system has Lua +# LUA_INCLUDE_DIR - the Lua include directory +# LUA_LIBRARY - The library needed to use Lua +# Copyright (c) 2013, Vittorio Giovara +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. -if (ANDROID) - SET(LUA_DEFAULT "liblua5.1.so") -else (ANDROID) - IF(WIN32) - SET(LUA_DEFAULT lua.dll) - ELSE(WIN32) - IF(APPLE) - SET(LUA_DEFAULT lua) - ELSE(APPLE) - #locate the system's lua library - FIND_LIBRARY(LUA_DEFAULT NAMES lua51 lua5.1 lua-5.1 lua PATHS /lib /usr/lib /usr/local/lib /usr/pkg/lib) - IF(${LUA_DEFAULT} MATCHES "LUA_DEFAULT-NOTFOUND") - set(LUA_DEFAULT lua) - ELSE() - set(LUA_FOUND true) - message(STATUS "LibLua 5.1 found at ${LUA_DEFAULT}") - find_path(LUA_INCLUDE_DIR lua.h) - #remove the path (fpc doesn't like it - why?) - GET_FILENAME_COMPONENT(LUA_DEFAULT ${LUA_DEFAULT} NAME) - ENDIF() - ENDIF(APPLE) - ENDIF(WIN32) -ENDIF(ANDROID) +include(FindPackageHandleStandardArgs) -SET(LUA_LIBRARY ${LUA_DEFAULT} CACHE STRING "Lua library to link to; file name without path only!") +find_path(LUA_INCLUDE_DIR lua.h + PATHS /usr/include /usr/local/include /usr/pkg/include + PATH_SUFFIXES lua5.1 lua51) +find_library(LUA_LIBRARY NAMES lua51 lua5.1 lua-5.1 lua + PATHS /lib /usr/lib /usr/local/lib /usr/pkg/lib) +find_package_handle_standard_args(Lua DEFAULT_MSG LUA_LIBRARY LUA_INCLUDE_DIR) +mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY) diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/compilerchecks.cmake --- a/cmake_modules/compilerchecks.cmake Mon Jun 17 10:48:50 2013 -0400 +++ b/cmake_modules/compilerchecks.cmake Mon Jun 17 17:40:01 2013 +0200 @@ -14,18 +14,18 @@ #(see 822312 654424 on bugzilla.redhat.com) check_c_compiler_flag("-fstack-protector-all -fstack-protector" HAVE_STACKPROTECTOR) if(HAVE_STACKPROTECTOR AND (NOT WIN32)) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all -fstack-protector") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -fstack-protector") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fstack-protector-all -fstack-protector") - set(CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} -fstack-protector-all -fstack-protector") - set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} -fstack-protector-all -fstack-protector") + add_flag_append(CMAKE_C_FLAGS "-fstack-protector-all -fstack-protector") + add_flag_append(CMAKE_CXX_FLAGS "-fstack-protector-all -fstack-protector") + add_flag_append(CMAKE_EXE_LINKER_FLAGS "-fstack-protector-all -fstack-protector") + add_flag_append(CMAKE_SHARED_LIBRARY_C_FLAGS "-fstack-protector-all -fstack-protector") + add_flag_append(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-fstack-protector-all -fstack-protector") endif() -#symbol visibility, not supported on Windows (so we error out to avoid spam) -check_c_compiler_flag("-fvisibility=hidden -Werror" HAVE_VISIBILITY) -if(HAVE_VISIBILITY) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") +#symbol visibility, not supported on Windows +check_c_compiler_flag("-fvisibility=hidden" HAVE_VISIBILITY) +if(HAVE_VISIBILITY AND (NOT WIN32)) + add_flag_append(CMAKE_C_FLAGS "-fvisibility=hidden") + add_flag_append(CMAKE_CXX_FLAGS "-fvisibility=hidden") endif() @@ -33,26 +33,21 @@ set(CMAKE_REQUIRED_FLAGS "-Wl,-z,noexecstack") check_c_compiler_flag("" HAVE_NOEXECSTACK) if(HAVE_NOEXECSTACK) - list(APPEND pascal_flags "-k-z" "-knoexecstack") - list(APPEND haskell_flags "-optl" "-z" "-optl" "noexecstack") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") + add_linker_flag("-znoexecstack") endif() #check for full relro on ELF, Debian security -set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro,-z,now") +set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro,-znow") check_c_compiler_flag("" HAVE_RELROFULL) if(HAVE_RELROFULL) - list(APPEND pascal_flags "-k-z" "-krelro" "-k-z" "-know") - list(APPEND haskell_flags "-optl" "-z" "-optl" "relro" "-optl" "-z" "-optl" "now") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") + add_linker_flag("-zrelro") + add_linker_flag("-znow") else() #if full relro is not available, try partial relro - set(CMAKE_REQUIRED_FLAGS "-Wl,-z,relro") + set(CMAKE_REQUIRED_FLAGS "-Wl,-zrelro") check_c_compiler_flag("" HAVE_RELROPARTIAL) if(HAVE_RELROPARTIAL) - list(APPEND pascal_flags "-k-z" "-krelro") - list(APPEND haskell_flags "-optl" "-z" "-optl" "relro") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") + add_linker_flag("-zrelro") endif() endif() @@ -60,20 +55,22 @@ set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat") check_c_compiler_flag("" HAVE_WINASLR) if(HAVE_WINASLR) - list(APPEND pascal_flags "-k--nxcompat") - list(APPEND haskell_flags "-optl" "--nxcompat") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") + add_linker_flag("--nxcompat") endif() #check for DEP on Windows XP SP2 or later, requires binutils >= 2.20 set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") check_c_compiler_flag("" HAVE_WINDEP) if(HAVE_WINDEP) - list(APPEND pascal_flags "-k--dynamicbase") - list(APPEND haskell_flags "-optl" "--dynamicbase") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}") + add_linker_flag("--dynamicbase") endif() +#this is actually an optimisation +set(CMAKE_REQUIRED_FLAGS "-Wl,--as-needed") +check_c_compiler_flag("" HAVE_ASNEEDED) +if(HAVE_ASNEEDED) + add_linker_flag("--as-needed") +endif() #always unset or these flags will be spread everywhere unset(CMAKE_REQUIRED_FLAGS) diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/paths.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake_modules/paths.cmake Mon Jun 17 17:40:01 2013 +0200 @@ -0,0 +1,78 @@ +#where to build libs and bins +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) +#these variables are for non-makefile generators +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${EXECUTABLE_OUTPUT_PATH}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${EXECUTABLE_OUTPUT_PATH}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${LIBRARY_OUTPUT_PATH}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${LIBRARY_OUTPUT_PATH}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${LIBRARY_OUTPUT_PATH}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${LIBRARY_OUTPUT_PATH}) + +#resource paths +if(UNIX AND NOT APPLE) + set(target_binary_install_dir "bin") + set(target_library_install_dir "lib") + + string(SUBSTRING "${DATA_INSTALL_DIR}" 0 1 sharepath_start) + if (NOT (${sharepath_start} MATCHES "/")) + set(HEDGEWARS_DATADIR "${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}/") + else() + set(HEDGEWARS_DATADIR "${DATA_INSTALL_DIR}/") + endif() + set(HEDGEWARS_FULL_DATADIR "${HEDGEWARS_DATADIR}") +else() + set(target_binary_install_dir "./") + + if(APPLE) + set(target_library_install_dir "../Frameworks/") + set(CMAKE_INSTALL_PREFIX "Hedgewars.app/Contents/MacOS/") + set(HEDGEWARS_DATADIR "../Resources/") + set(HEDGEWARS_FULL_DATADIR "/Applications/${CMAKE_INSTALL_PREFIX}/${HEDGEWARS_DATADIR}") + elseif(WIN32) + set(target_library_install_dir "./") + set(HEDGEWARS_DATADIR "./") + set(HEDGEWARS_FULL_DATADIR "${CMAKE_INSTALL_PREFIX}/") + link_directories("${EXECUTABLE_OUTPUT_PATH}" "${CMAKE_SOURCE_DIR}/misc/winutils/bin") + endif() +endif() + + +#RPATH SETTINGS +#necessary for dynamic libraries on UNIX, ignored elsewhere + +#use, i.e. don't skip the full RPATH for the build tree +set(CMAKE_SKIP_BUILD_RPATH FALSE) +set(CMAKE_SKIP_INSTALL_RPATH FALSE) + +#it's safe to use our RPATH because it is relative +set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) + +#paths where to find libraries (final slash not optional): +# - the first is relative to the executable +# - the second is the same directory of the executable (so it runs in bin/) +# - the third one is the full path of the system dir +#source http://www.cmake.org/pipermail/cmake/2008-January/019290.html +set(CMAKE_INSTALL_RPATH "$ORIGIN/../${target_library_install_dir}/:$ORIGIN/:${CMAKE_INSTALL_PREFIX}/${target_library_install_dir}/") + +if(UNIX AND NOT APPLE) + #make sure $ORIGIN is respected + add_linker_flag("-zorigin") + #apply RPATH settings to pascal executables + add_flag_append(CMAKE_Pascal_FLAGS "-k-rpath -k'${CMAKE_INSTALL_RPATH}'") + #until we link with external things there is no need to set rpath on haskell + #should you need it remember to escape $ with $$ + #list(APPEND haskell_flags "-optl" "-Wl,-rpath,'${CMAKE_INSTALL_RPATH_ESCAPED}'") +endif() + +#add the automatically determined parts of the RPATH +#which point to directories outside the build tree to the install RPATH +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) + + +#install_name_tool magic for OS X +set(CMAKE_INSTALL_NAME_DIR "@executable_path/../Frameworks") + diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/platform.cmake --- a/cmake_modules/platform.cmake Mon Jun 17 10:48:50 2013 -0400 +++ b/cmake_modules/platform.cmake Mon Jun 17 17:40:01 2013 +0200 @@ -36,7 +36,8 @@ find_package(SDL_mixer REQUIRED) set(DYLIB_SMPEG "-dylib_file @loader_path/Frameworks/smpeg.framework/Versions/A/smpeg:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/smpeg.framework/Versions/A/smpeg") set(DYLIB_MIKMOD "-dylib_file @loader_path/Frameworks/mikmod.framework/Versions/A/mikmod:${SDLMIXER_LIBRARY}/Versions/A/Frameworks/mikmod.framework/Versions/A/mikmod") - set(CMAKE_C_FLAGS "${DYLIB_SMPEG} ${DYLIB_MIKMOD}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DYLIB_SMPEG} ${DYLIB_MIKMOD}") + set(CMAKE_CX_FLAGS "${CMAKE_CX_FLAGS} ${DYLIB_SMPEG} ${DYLIB_MIKMOD}") list(APPEND pascal_flags "-k${DYLIB_SMPEG}" "-k${DYLIB_MIKMOD}") endif() @@ -73,8 +74,14 @@ endif(APPLE) -if(WIN32) +if(MINGW) #this flags prevents a few dll hell problems - set(CMAKE_C_FLAGS "-static-libgcc ${CMAKE_C_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc ") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc ") +endif(MINGW) + +if(WIN32) + if(NOT ${BUILD_SHARED_LIB}) + message(FATAL_ERROR "Static linking is not supported on Windows") + endif() endif(WIN32) - diff -r e653e96b0ec3 -r 2bf3796c5855 cmake_modules/utils.cmake --- a/cmake_modules/utils.cmake Mon Jun 17 10:48:50 2013 -0400 +++ b/cmake_modules/utils.cmake Mon Jun 17 17:40:01 2013 +0200 @@ -1,4 +1,5 @@ +#find package helpers macro(find_package_or_fail _PKG_NAME) find_package(${_PKG_NAME}) string(TOUPPER ${_PKG_NAME} _PKG_NAME_UP) @@ -25,6 +26,24 @@ endif(NOT ${_VAR_NAME}) endmacro(find_package_or_disable_msg _PKG_NAME _VAR_NAME _MSG) +#variable manipulation macros +macro(add_flag_append _VAR_NAME _FLAG) + set(${_VAR_NAME} "${${_VAR_NAME}} ${_FLAG}") +endmacro(add_flag_append _VAR_NAME _FLAG) + +macro(add_flag_prepend _VAR_NAME _FLAG) + set(${_VAR_NAME} "${_FLAG} ${${_VAR_NAME}}") +endmacro(add_flag_prepend _VAR_NAME _FLAG) + +macro(add_linker_flag _FLAG) + list(APPEND haskell_flags "-optl" "${_FLAG}") + add_flag_append(CMAKE_Pascal_FLAGS "-k${_FLAG}") + add_flag_append(CMAKE_EXE_LINKER_FLAGS "-Wl,${_FLAG}") + add_flag_append(CMAKE_SHARED_LIBRARY_C_FLAGS "-Wl,${_FLAG}") + add_flag_append(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-Wl,${_FLAG}") +endmacro(add_linker_flag _FLAG) #TODO: find_package_or_bundle + + diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Mon Jun 17 10:48:50 2013 -0400 +++ b/hedgewars/CMakeLists.txt Mon Jun 17 17:40:01 2013 +0200 @@ -5,264 +5,207 @@ find_package(SDL_mixer) include (CheckLibraryExists) -#Mix_Init/Mix_Quit from SDL_mixer 1.2.10 -check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT) -if(HAVE_MIXINIT) - list(APPEND pascal_flags "-dSDL_MIXER_NEWER") -endif() -#IMG_Init/IMG_Quit from SDL_image 1.2.8 -check_library_exists(${SDLIMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT) -if(HAVE_IMGINIT) - list(APPEND pascal_flags "-dSDL_IMAGE_NEWER") -endif() + + +enable_language(Pascal) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.inc.in ${CMAKE_CURRENT_BINARY_DIR}/config.inc) - -#SOURCE AND PROGRAMS SECTION -if(${BUILD_ENGINE_LIBRARY}) - set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}") - set(hwengine_project hwLibrary.pas) -else() - set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}") - set(hwengine_project hwengine.pas) -endif() - -if (APPLE) - set(required_fpc_version 2.6) -else() - set(required_fpc_version 2.2) -endif() - set(engine_sources - ${hwengine_project} + SDLh.pas + uSinTable.pas + uFloat.pas + uConsts.pas LuaPas.pas PNGh.pas - SDLh.pas - uAI.pas - uAIActions.pas + uTypes.pas + uUtils.pas + uVariables.pas + uMisc.pas + uConsole.pas + uDebug.pas + uCommands.pas + uInputHandler.pas + uTextures.pas + uRenderUtils.pas + uRender.pas + uCaptions.pas + uLandTexture.pas + uIO.pas + uChat.pas + uPhysFSLayer.pas + uStore.pas + uSound.pas + uRandom.pas + uLocale.pas + uStats.pas + uCursor.pas + uVideoRec.pas uAILandMarks.pas - uAIAmmoTests.pas - uAIMisc.pas + adler32.pas + uLandTemplates.pas + uLandGraphics.pas + uLandPainted.pas + uLandOutline.pas + uLandGenMaze.pas + uLandObjects.pas + uLand.pas uAmmos.pas - uCaptions.pas - uChat.pas + + uAIMisc.pas + uAIActions.pas + uAI.pas + uWorld.pas + uVisualGears.pas + uTeams.pas + + uGearsList.pas uCollisions.pas - uCommands.pas + uAIAmmoTests.pas + uGears.pas + uGame.pas uCommandHandlers.pas - uConsole.pas - uConsts.pas - uCursor.pas - uDebug.pas - uFloat.pas - uGame.pas - uGears.pas uGearsHandlers.pas uGearsHandlersRope.pas uGearsHedgehog.pas - uGearsList.pas uGearsRender.pas uGearsUtils.pas - uIO.pas - uInputHandler.pas - uLand.pas - uLandGenMaze.pas - uLandGraphics.pas - uLandObjects.pas - uLandOutline.pas - uLandPainted.pas - uLandTemplates.pas - uLandTexture.pas - uLocale.pas - uMisc.pas - uPhysFSLayer.pas - uRandom.pas - uRender.pas - uRenderUtils.pas uScript.pas - uSinTable.pas - uSound.pas - uStats.pas - uStore.pas - uTeams.pas - uTextures.pas - uTouch.pas - uTypes.pas - uUtils.pas - uVariables.pas - uVideoRec.pas - uVisualGears.pas - uWorld.pas + hwengine.pas + GSHandlers.inc VGSHandlers.inc ArgParsers.inc options.inc - adler32.pas ${CMAKE_CURRENT_BINARY_DIR}/config.inc ) -if(${BUILD_ENGINE_LIBRARY}) - message("*** 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") - 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 VERSION_GREATER "10.5") - list(APPEND pascal_flags "-k-no_order_inits") - endif() - set(destination_dir ${target_library_install_dir}) -else(${BUILD_ENGINE_LIBRARY}) - set(destination_dir ${target_binary_install_dir}) -endif(${BUILD_ENGINE_LIBRARY}) - include(${CMAKE_MODULE_PATH}/utils.cmake) -find_package_or_fail(FreePascal) - -#when cmake-2.6 support is dropped, this ought to be inside FindFreePascal.cmake -if (FREEPASCAL_VERSION VERSION_LESS required_fpc_version) - message(FATAL_ERROR "Freepascal ${FREEPASCAL_VERSION} is too old, minimum version required is ${required_fpc_version}") +if (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.2 OR # older versions are just ancient + (${CMAKE_Pascal_COMPILER_VERSION} VERSION_LESS 2.6 AND APPLE)) # because of 64bit and opengl bindings + message(FATAL_ERROR "Your FreePascal installation is too old (fpc ${CMAKE_Pascal_COMPILER_VERSION})!") +elseif(CMAKE_Pascal_COMPILER_VERSION VERSION_GREATER 2.4) + #enable INLINE only with a recent version of fpc + add_flag_prepend(CMAKE_Pascal_FLAGS_RELEASE -Si) endif() #DEPENDECIES AND EXECUTABLES SECTION if(APPLE) - string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}") - string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}") - string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}") - - if(powerpc_build) - set(powerpc_build "powerpc") + if(CMAKE_OSX_ARCHITECTURES) + #parse this system variable and adjust only the powerpc syntax to be compatible with -P + string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}") + string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}") + string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}") + if(x86_64_build) + add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64) + elseif(i386_build) + add_flag_prepend(CMAKE_Pascal_FLAGS -Pi386) + elseif(powerpc_build) + add_flag_prepend(CMAKE_Pascal_FLAGS -Ppowerpc) + else() + message(FATAL_ERROR "Unknown architecture present in CMAKE_OSX_ARCHITECTURES (${CMAKE_OSX_ARCHITECTURES})") + endif() + list(LENGTH CMAKE_OSX_ARCHITECTURES num_of_archs) + if(num_of_archs GREATER 1) + message(${WARNING} "Only one architecture in CMAKE_OSX_ARCHITECTURES is currently supported, picking the first one") + endif() + elseif(CMAKE_SIZEOF_VOID_P MATCHES "8") + #if that variable is not set check if we are on x86_64 and if so force it, else use default + add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64) endif() #on OSX we need to provide the SDL_main() function when building as executable - 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_library_only "${SDL_LIBRARY}") - #find libsdmain.a - 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 - list(APPEND engine_sources SDLmain) - set(SDLMAIN_LIB "${LIBRARY_OUTPUT_PATH}/libSDLmain.a") - endif() - - list(APPEND pascal_flags "-k${SDLMAIN_LIB}") + if(NOT BUILD_ENGINE_LIBRARY) + add_subdirectory(sdlmain) + list(APPEND HW_LINK_LIBS SDLmain) + add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH}) endif() - #when you have multiple ld installation make sure you get the one bundled with the compiler - get_filename_component(compiler_dir ${CMAKE_C_COMPILER} PATH) - list(APPEND pascal_flags "-FD${compiler_dir}") + #when sysroot is set, make sure that fpc picks it + if(CMAKE_OSX_SYSROOT) + set(add_flag_append "-XD${CMAKE_OSX_SYSROOT}") + endif(CMAKE_OSX_SYSROOT) endif(APPLE) +if(FFMPEG_FOUND) + add_subdirectory(avwrapper) + list(APPEND HW_LINK_LIBS avwrapper) + add_definitions(-dUSE_VIDEO_RECORDING) + add_flag_append(CMAKE_Pascal_FLAGS -Fl${LIBRARY_OUTPUT_PATH}) +endif() + find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP") if(PNG_FOUND) list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH) - list(APPEND pascal_flags "-dPNG_SCREENSHOTS" "-Fl${PNG_LIBRARY_DIR}" "-k-L${PNG_LIBRARY_DIR}") -endif() - - -#this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6 -if(FREEPASCAL_VERSION VERSION_LESS "2.6") - #under some configurations CMAKE_BUILD_TOOL fails to pass on the jobserver, breaking parallel compilation - if(UNIX) - set(SAFE_BUILD_TOOL $(MAKE)) - else() - set(SAFE_BUILD_TOOL ${CMAKE_BUILD_TOOL}) - endif() - add_custom_target(ENGINECLEAN COMMAND ${SAFE_BUILD_TOOL} "clean" "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") + add_flag_append(CMAKE_Pascal_FLAGS -Fl${PNG_LIBRARY_DIR}) endif() - -if(${FFMPEG_FOUND}) - # TODO: this check is only for SDL < 2 - # fpc will take care of linking but we need to have this library installed - find_package(GLUT REQUIRED) - - #TODO: convert avwrapper to .pas unit so we can skip this step - include_directories(${FFMPEG_INCLUDE_DIR}) - 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_library_install_dir}) - else() - add_library(avwrapper STATIC avwrapper.c) - endif() +if(LUA_FOUND AND LUA_SYSTEM) + get_filename_component(LUA_LIBRARY_DIR ${LUA_LIBRARY} PATH) + get_filename_component(LUA_LIBRARY_NAME ${LUA_LIBRARY} NAME) + #NAME_WE would strip the .1 (or .2) next to the ".so" + string(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_PREFIX}(.*)${CMAKE_SHARED_LIBRARY_SUFFIX}" "\\1" LUA_LIBRARY_NAME "${LUA_LIBRARY_NAME}") + add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LUA_LIBRARY_DIR} -XLAlua=${LUA_LIBRARY_NAME}") +else() + add_definitions(-dLUA_INTERNAL) + list(APPEND HW_LINK_LIBS lua) + add_flag_append(CMAKE_Pascal_FLAGS "-XLAlua=${lua_output_name}") endif() -set(fpc_flags ${pascal_flags} ${hwengine_project}) +if(NOT PHYSFS_FOUND) + add_definitions(-dPHYSFS_INTERNAL) + list(APPEND HW_LINK_LIBS physfs) + #-XLA is a beta fpc flag that renames libraries before passing them to the linker + #we also have to pass PHYSFS_INTERNAL to satisfy windows runtime requirements + #(should be harmless on other platforms) + add_flag_append(CMAKE_Pascal_FLAGS "-Fl${LIBRARY_OUTPUT_PATH} -XLAphysfs=${physfs_output_name}") +endif() +list(APPEND HW_LINK_LIBS physlayer) + +#Mix_Init/Mix_Quit from SDL_mixer 1.2.10 +check_library_exists(${SDLMIXER_LIBRARY} Mix_Init "" HAVE_MIXINIT) +if(HAVE_MIXINIT) + add_definitions(-dSDL_MIXER_NEWER) +endif(HAVE_MIXINIT) -if(NOT APPLE) - #here is the command for standard executables or for shared library - add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" - COMMAND "${FREEPASCAL_EXECUTABLE}" - ARGS ${fpc_flags} -o${engine_output_name} - DEPENDS ${engine_sources} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) +#IMG_Init/IMG_Quit from SDL_image 1.2.8 +check_library_exists(${SDLIMAGE_LIBRARY} IMG_Init "" HAVE_IMGINIT) +if(HAVE_IMGINIT) + add_definitions(-dSDL_IMAGE_NEWER) +endif(HAVE_IMGINIT) + +#needs to be last +add_definitions(-dDEBUGFILE) + +#SOURCE AND PROGRAMS SECTION +if(BUILD_ENGINE_LIBRARY) + message(${WARNING} "Engine will be built as library (experimental)") + if(APPLE AND current_macosx_version VERSION_GREATER "10.5") + # due to compiler/linker issues on Max OS X 10.6 -k-no_order_inits is needed to avoid linking fail + add_flag_prepend(CMAKE_Pascal_FLAGS "-k-no_order_inits") + endif() + + #workaround for missing support during object generation + set(engine_output_name "${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(destination_dir ${target_library_install_dir}) + add_flag_prepend(CMAKE_Pascal_FLAGS "-o${LIBRARY_OUTPUT_PATH}/${engine_output_name}") + + add_definitions(-dHWLIBRARY) + add_library(hwengine SHARED ${engine_sources} hwLibrary.pas) else() - #these are the dependencies for building a universal binary on Mac OS X - foreach (build_arch ${powerpc_build} ${i386_build} ${x86_64_build}) - list(APPEND lipo_args_list "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}") - add_custom_command(OUTPUT "${EXECUTABLE_OUTPUT_PATH}/hwengine.${build_arch}" - COMMAND "${FREEPASCAL_EXECUTABLE}" - ARGS ${fpc_flags} -ohwengine.${build_arch} -P${build_arch} - DEPENDS ${engine_sources} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - ) - 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}" - COMMAND "lipo" - ARGS ${lipo_args_list} -create -output ${EXECUTABLE_OUTPUT_PATH}/${engine_output_name} - DEPENDS ${lipo_args_list} - ) + # no need to change name here because target has same name + set(engine_output_name "hwengine${CMAKE_EXECUTABLE_SUFFIX}") + set(destination_dir ${target_binary_install_dir}) + add_executable(hwengine ${engine_sources}) endif() - -add_custom_target(hwengine 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) - add_dependencies(hwengine lua) -endif() - -# same for physfs -if(NOT PHYSFS_FOUND) - add_dependencies(hwengine physfs) -endif() - -add_dependencies(hwengine physlayer) - -#when ffmpeg/libav is found we need to compile it before engine -#TODO: convert avwrapper to .pas unit so we can skip this step -if(${FFMPEG_FOUND}) - add_dependencies(hwengine avwrapper) -endif() - -#this command is a workaround to some inlining issues present in older FreePascal versions and fixed in 2.6 -if((FREEPASCAL_VERSION VERSION_LESS "2.6") AND (NOT ${FFMPEG_FOUND})) - add_dependencies(hwengine ENGINECLEAN) -endif() +#even though not actually used, this will trigger relink if any lib changes +target_link_libraries(hwengine ${HW_LINK_LIBS}) install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}" DESTINATION ${destination_dir}) diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Mon Jun 17 10:48:50 2013 -0400 +++ b/hedgewars/GSHandlers.inc Mon Jun 17 17:40:01 2013 +0200 @@ -132,17 +132,6 @@ HH^.Gear:= nil end; -procedure RestoreHog(HH: PHedgehog); -begin - HH^.Gear:=HH^.GearHidden; - HH^.GearHidden:= nil; - InsertGearToList(HH^.Gear); - HH^.Gear^.State:= (HH^.Gear^.State and (not (gstHHDriven or gstInvisible or gstAttacking))) or gstAttacked; - AddGearCI(HH^.Gear); - HH^.Gear^.Active:= true; - ScriptCall('onHogRestore', HH^.Gear^.Uid) -end; - //////////////////////////////////////////////////////////////////////////////// procedure doStepDrowningGear(Gear: PGear); diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/LuaPas.pas --- a/hedgewars/LuaPas.pas Mon Jun 17 10:48:50 2013 -0400 +++ b/hedgewars/LuaPas.pas Mon Jun 17 17:40:01 2013 +0200 @@ -14,6 +14,12 @@ uses uConsts; {.$DEFINE LUA_GETHOOK} +const LuaLibName = {$IFDEF LUA_INTERNAL}'libhwlua'{$ELSE}'liblua'{$ENDIF}; + +{$IFNDEF WIN32} + {$linklib lua} +{$ENDIF} + type size_t = Cardinal; Psize_t = ^size_t; @@ -22,9 +28,6 @@ lua_State = record end; Plua_State = ^lua_State; -{$DEFINE LuaLibName:= cLuaLibrary} - - (*****************************************************************************) (* luaconfig.h *) (*****************************************************************************) diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/SDLMain.h --- a/hedgewars/SDLMain.h Mon Jun 17 10:48:50 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -/* SDLMain.m - main entry point for our Cocoa-ized SDL app - Initial Version: Darrell Walisser - Non-NIB-Code & other changes: Max Horn - - Feel free to customize this file to suit your needs -*/ - -#ifndef _SDLMain_h_ -#define _SDLMain_h_ - -#import - -@interface SDLMain : NSObject -@end - -#endif /* _SDLMain_h_ */ diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/SDLMain.m --- a/hedgewars/SDLMain.m Mon Jun 17 10:48:50 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,385 +0,0 @@ -/* SDLMain.m - main entry point for our Cocoa-ized SDL app - Initial Version: Darrell Walisser - Non-NIB-Code & other changes: Max Horn - - Feel free to customize this file to suit your needs -*/ - -#include "SDL.h" -#include "SDLMain.h" -#include /* for MAXPATHLEN */ -#include - -/* For some reaon, Apple removed setAppleMenu from the headers in 10.4, - but the method still is there and works. To avoid warnings, we declare - it ourselves here. */ -@interface NSApplication(SDL_Missing_Methods) -- (void)setAppleMenu:(NSMenu *)menu; -@end - -/* Use this flag to determine whether we use SDLMain.nib or not */ -#define SDL_USE_NIB_FILE 0 - -/* Use this flag to determine whether we use CPS (docking) or not */ -#define SDL_USE_CPS 1 -#ifdef SDL_USE_CPS -/* Portions of CPS.h */ -typedef struct CPSProcessSerNum -{ - UInt32 lo; - UInt32 hi; -} CPSProcessSerNum; - -extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); -extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); -extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); - -#endif /* SDL_USE_CPS */ - -static int gArgc; -static char **gArgv; -static BOOL gFinderLaunch; -static BOOL gCalledAppMainline = FALSE; - -static NSString *getApplicationName(void) -{ - const NSDictionary *dict; - NSString *appName = 0; - - /* Determine the application name */ - dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); - if (dict) - appName = [dict objectForKey: @"CFBundleName"]; - - if (![appName length]) - appName = [[NSProcessInfo processInfo] processName]; - - return appName; -} - -#if SDL_USE_NIB_FILE -/* A helper category for NSString */ -@interface NSString (ReplaceSubString) -- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; -@end -#endif - -@interface SDLApplication : NSApplication -@end - -@implementation SDLApplication -/* Invoked from the Quit menu item */ -- (void)terminate:(id)sender -{ - /* Post a SDL_QUIT event */ - SDL_Event event; - event.type = SDL_QUIT; - SDL_PushEvent(&event); -} -@end - -/* The main class of the application, the application's delegate */ -@implementation SDLMain - -/* Set the working directory to the .app's parent directory */ -- (void) setupWorkingDirectory:(BOOL)shouldChdir -{ - if (shouldChdir) - { - char parentdir[MAXPATHLEN]; - CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); - CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); - if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) { - chdir(parentdir); /* chdir to the binary app's parent */ - } - CFRelease(url); - CFRelease(url2); - } -} - -#if SDL_USE_NIB_FILE - -/* Fix menu to contain the real app name instead of "SDL App" */ -- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName -{ - NSRange aRange; - NSEnumerator *enumerator; - NSMenuItem *menuItem; - - aRange = [[aMenu title] rangeOfString:@"SDL App"]; - if (aRange.length != 0) - [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]]; - - enumerator = [[aMenu itemArray] objectEnumerator]; - while ((menuItem = [enumerator nextObject])) - { - aRange = [[menuItem title] rangeOfString:@"SDL App"]; - if (aRange.length != 0) - [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]]; - if ([menuItem hasSubmenu]) - [self fixMenu:[menuItem submenu] withAppName:appName]; - } - [ aMenu sizeToFit ]; -} - -#else - -static void setApplicationMenu(void) -{ - /* warning: this code is very odd */ - NSMenu *appleMenu; - NSMenuItem *menuItem; - NSString *title; - NSString *appName; - - appName = getApplicationName(); - appleMenu = [[NSMenu alloc] initWithTitle:@""]; - - /* Add menu items */ - title = [@"About " stringByAppendingString:appName]; - [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; - - [appleMenu addItem:[NSMenuItem separatorItem]]; - - title = [@"Hide " stringByAppendingString:appName]; - [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; - - menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; - [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; - - [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; - - [appleMenu addItem:[NSMenuItem separatorItem]]; - - title = [@"Quit " stringByAppendingString:appName]; - [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; - - - /* Put menu into the menubar */ - menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; - [menuItem setSubmenu:appleMenu]; - [[NSApp mainMenu] addItem:menuItem]; - - /* Tell the application object that this is now the application menu */ - [NSApp setAppleMenu:appleMenu]; - - /* Finally give up our references to the objects */ - [appleMenu release]; - [menuItem release]; -} - -/* Create a window menu */ -static void setupWindowMenu(void) -{ - NSMenu *windowMenu; - NSMenuItem *windowMenuItem; - NSMenuItem *menuItem; - - windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; - - /* "Minimize" item */ - menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; - [windowMenu addItem:menuItem]; - [menuItem release]; - - /* Put menu into the menubar */ - windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; - [windowMenuItem setSubmenu:windowMenu]; - [[NSApp mainMenu] addItem:windowMenuItem]; - - /* Tell the application object that this is now the window menu */ - [NSApp setWindowsMenu:windowMenu]; - - /* Finally give up our references to the objects */ - [windowMenu release]; - [windowMenuItem release]; -} - -/* Replacement for NSApplicationMain */ -static void CustomApplicationMain (int argc, char **argv) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - SDLMain *sdlMain; - - /* Ensure the application object is initialised */ - [SDLApplication sharedApplication]; - -#ifdef SDL_USE_CPS - { - CPSProcessSerNum PSN; - /* Tell the dock about us */ - if (!CPSGetCurrentProcess(&PSN)) - if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103)) - if (!CPSSetFrontProcess(&PSN)) - [SDLApplication sharedApplication]; - } -#endif /* SDL_USE_CPS */ - - /* Set up the menubar */ - NSMenu *menu = [[NSMenu alloc] init]; - [NSApp setMainMenu:menu]; - setApplicationMenu(); - setupWindowMenu(); - [menu release]; - - /* Create SDLMain and make it the app delegate */ - sdlMain = [[SDLMain alloc] init]; - [NSApp setDelegate:sdlMain]; - - /* Start the main event loop */ - [NSApp run]; - - [sdlMain release]; - [pool release]; -} - -#endif - - -/* - * Catch document open requests...this lets us notice files when the app - * was launched by double-clicking a document, or when a document was - * dragged/dropped on the app's icon. You need to have a - * CFBundleDocumentsType section in your Info.plist to get this message, - * apparently. - * - * Files are added to gArgv, so to the app, they'll look like command line - * arguments. Previously, apps launched from the finder had nothing but - * an argv[0]. - * - * This message may be received multiple times to open several docs on launch. - * - * This message is ignored once the app's mainline has been called. - */ -- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename -{ - const char *temparg; - size_t arglen; - char *arg; - char **newargv; - - if (!gFinderLaunch) /* MacOS is passing command line args. */ - return FALSE; - - if (gCalledAppMainline) /* app has started, ignore this document. */ - return FALSE; - - temparg = [filename UTF8String]; - arglen = SDL_strlen(temparg) + 1; - arg = (char *) SDL_malloc(arglen); - if (arg == NULL) - return FALSE; - - newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2)); - if (newargv == NULL) - { - SDL_free(arg); - return FALSE; - } - gArgv = newargv; - - SDL_strlcpy(arg, temparg, arglen); - gArgv[gArgc++] = arg; - gArgv[gArgc] = NULL; - return TRUE; -} - - -/* Called when the internal event loop has just started running */ -- (void) applicationDidFinishLaunching: (NSNotification *) note -{ - int status; - - /* Set the working directory to the .app's parent directory */ - [self setupWorkingDirectory:gFinderLaunch]; - -#if SDL_USE_NIB_FILE - /* Set the main menu to contain the real app name instead of "SDL App" */ - [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()]; -#endif - - /* Hand off to main application code */ - gCalledAppMainline = TRUE; - status = SDL_main (gArgc, gArgv); - - /* We're done, thank you for playing */ - exit(status); -} -@end - - -@implementation NSString (ReplaceSubString) - -- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString -{ - unsigned int bufferSize; - unsigned int selfLen = [self length]; - unsigned int aStringLen = [aString length]; - unichar *buffer; - NSRange localRange; - NSString *result; - - bufferSize = selfLen + aStringLen - aRange.length; - buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar)); - - /* Get first part into buffer */ - localRange.location = 0; - localRange.length = aRange.location; - [self getCharacters:buffer range:localRange]; - - /* Get middle part into buffer */ - localRange.location = 0; - localRange.length = aStringLen; - [aString getCharacters:(buffer+aRange.location) range:localRange]; - - /* Get last part into buffer */ - localRange.location = aRange.location + aRange.length; - localRange.length = selfLen - localRange.location; - [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange]; - - /* Build output string */ - result = [NSString stringWithCharacters:buffer length:bufferSize]; - - NSDeallocateMemoryPages(buffer, bufferSize); - - return result; -} - -@end - - - -#ifdef main -# undef main -#endif - - -/* Main entry point to executable - should *not* be SDL_main! */ -int main (int argc, char **argv) -{ - /* Copy the arguments into a global variable */ - /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { - gArgv = (char **) SDL_malloc(sizeof (char *) * 2); - gArgv[0] = argv[0]; - gArgv[1] = NULL; - gArgc = 1; - gFinderLaunch = YES; - } else { - int i; - gArgc = argc; - gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1)); - for (i = 0; i <= argc; i++) - gArgv[i] = argv[i]; - gFinderLaunch = NO; - } - -#if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; - NSApplicationMain (argc, argv); -#else - CustomApplicationMain (argc, argv); -#endif - return 0; -} - diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Mon Jun 17 10:48:50 2013 -0400 +++ b/hedgewars/SDLh.pas Mon Jun 17 17:40:01 2013 +0200 @@ -54,7 +54,8 @@ {$ENDIF} {$IFDEF DARWIN} - {$IFNDEF IPHONEOS} + {$IFNDEF HWLIBRARY} + {$linklib SDLmain} {$PASCALMAINNAME SDL_main} {$linkframework Cocoa} {$linkframework SDL} @@ -76,19 +77,11 @@ SDL_ImageLibName = 'SDL_image.dll'; SDL_NetLibName = 'SDL_net.dll'; {$ELSE} - {$IFDEF DARWIN} - SDLLibName = 'SDL'; - SDL_TTFLibName = 'SDL_ttf'; - SDL_MixerLibName = 'SDL_mixer'; - SDL_ImageLibName = 'SDL_image'; - SDL_NetLibName = 'SDL_net'; - {$ELSE} - SDLLibName = 'libSDL.so'; - SDL_TTFLibName = 'libSDL_ttf.so'; - SDL_MixerLibName = 'libSDL_mixer.so'; - SDL_ImageLibName = 'libSDL_image.so'; - SDL_NetLibName = 'libSDL_net.so'; - {$ENDIF} + SDLLibName = 'libSDL'; + SDL_TTFLibName = 'libSDL_ttf'; + SDL_MixerLibName = 'libSDL_mixer'; + SDL_ImageLibName = 'libSDL_image'; + SDL_NetLibName = 'libSDL_net'; {$ENDIF} ///////////////////////////////////////////////////////////////// diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/avwrapper.c --- a/hedgewars/avwrapper.c Mon Jun 17 10:48:50 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,509 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2004-2013 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include "libavformat/avformat.h" -#include "libavutil/mathematics.h" - -#ifndef AVIO_FLAG_WRITE -#define AVIO_FLAG_WRITE AVIO_WRONLY -#endif - -static AVFormatContext* g_pContainer; -static AVOutputFormat* g_pFormat; -static AVStream* g_pAStream; -static AVStream* g_pVStream; -static AVFrame* g_pAFrame; -static AVFrame* g_pVFrame; -static AVCodec* g_pACodec; -static AVCodec* g_pVCodec; -static AVCodecContext* g_pAudio; -static AVCodecContext* g_pVideo; - -static int g_Width, g_Height; -static uint32_t g_Frequency, g_Channels; -static int g_VQuality; -static AVRational g_Framerate; - -static FILE* g_pSoundFile; -static int16_t* g_pSamples; -static int g_NumSamples; - - -#if LIBAVCODEC_VERSION_MAJOR < 54 -#define OUTBUFFER_SIZE 200000 -static uint8_t g_OutBuffer[OUTBUFFER_SIZE]; -#endif - -// pointer to function from hwengine (uUtils.pas) -static void (*AddFileLogRaw)(const char* pString); - -static void FatalError(const char* pFmt, ...) -{ - char Buffer[1024]; - va_list VaArgs; - - va_start(VaArgs, pFmt); - vsnprintf(Buffer, 1024, pFmt, VaArgs); - va_end(VaArgs); - - AddFileLogRaw("Error in av-wrapper: "); - AddFileLogRaw(Buffer); - AddFileLogRaw("\n"); - exit(1); -} - -// Function to be called from libav for logging. -// Note: libav can call LogCallback from different threads -// (there is mutex in AddFileLogRaw). -static void LogCallback(void* p, int Level, const char* pFmt, va_list VaArgs) -{ - char Buffer[1024]; - - vsnprintf(Buffer, 1024, pFmt, VaArgs); - AddFileLogRaw(Buffer); -} - -static void Log(const char* pFmt, ...) -{ - char Buffer[1024]; - va_list VaArgs; - - va_start(VaArgs, pFmt); - vsnprintf(Buffer, 1024, pFmt, VaArgs); - va_end(VaArgs); - - AddFileLogRaw(Buffer); -} - -static void AddAudioStream() -{ -#if LIBAVFORMAT_VERSION_MAJOR >= 53 - g_pAStream = avformat_new_stream(g_pContainer, g_pACodec); -#else - g_pAStream = av_new_stream(g_pContainer, 1); -#endif - if(!g_pAStream) - { - Log("Could not allocate audio stream\n"); - return; - } - g_pAStream->id = 1; - - g_pAudio = g_pAStream->codec; - - avcodec_get_context_defaults3(g_pAudio, g_pACodec); - g_pAudio->codec_id = g_pACodec->id; - - // put parameters - g_pAudio->sample_fmt = AV_SAMPLE_FMT_S16; - g_pAudio->sample_rate = g_Frequency; - g_pAudio->channels = g_Channels; - - // set quality - g_pAudio->bit_rate = 160000; - - // for codecs that support variable bitrate use it, it should be better - g_pAudio->flags |= CODEC_FLAG_QSCALE; - g_pAudio->global_quality = 1*FF_QP2LAMBDA; - - // some formats want stream headers to be separate - if (g_pFormat->flags & AVFMT_GLOBALHEADER) - g_pAudio->flags |= CODEC_FLAG_GLOBAL_HEADER; - - // open it -#if LIBAVCODEC_VERSION_MAJOR >= 53 - if (avcodec_open2(g_pAudio, g_pACodec, NULL) < 0) -#else - if (avcodec_open(g_pAudio, g_pACodec) < 0) -#endif - { - Log("Could not open audio codec %s\n", g_pACodec->long_name); - return; - } - -#if LIBAVCODEC_VERSION_MAJOR >= 54 - if (g_pACodec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE) -#else - if (g_pAudio->frame_size == 0) -#endif - g_NumSamples = 4096; - else - g_NumSamples = g_pAudio->frame_size; - g_pSamples = (int16_t*)av_malloc(g_NumSamples*g_Channels*sizeof(int16_t)); - g_pAFrame = avcodec_alloc_frame(); - if (!g_pAFrame) - { - Log("Could not allocate frame\n"); - return; - } -} - -// returns non-zero if there is more sound -static int WriteAudioFrame() -{ - if (!g_pAStream) - return 0; - - AVPacket Packet = { 0 }; - av_init_packet(&Packet); - - int NumSamples = fread(g_pSamples, 2*g_Channels, g_NumSamples, g_pSoundFile); - -#if LIBAVCODEC_VERSION_MAJOR >= 53 - AVFrame* pFrame = NULL; - if (NumSamples > 0) - { - g_pAFrame->nb_samples = NumSamples; - avcodec_fill_audio_frame(g_pAFrame, g_Channels, AV_SAMPLE_FMT_S16, - (uint8_t*)g_pSamples, NumSamples*2*g_Channels, 1); - pFrame = g_pAFrame; - } - // when NumSamples == 0 we still need to call encode_audio2 to flush - int got_packet; - if (avcodec_encode_audio2(g_pAudio, &Packet, pFrame, &got_packet) != 0) - FatalError("avcodec_encode_audio2 failed"); - if (!got_packet) - return 0; -#else - if (NumSamples == 0) - return 0; - int BufferSize = OUTBUFFER_SIZE; - if (g_pAudio->frame_size == 0) - BufferSize = NumSamples*g_Channels*2; - Packet.size = avcodec_encode_audio(g_pAudio, g_OutBuffer, BufferSize, g_pSamples); - if (Packet.size == 0) - return 1; - if (g_pAudio->coded_frame && g_pAudio->coded_frame->pts != AV_NOPTS_VALUE) - Packet.pts = av_rescale_q(g_pAudio->coded_frame->pts, g_pAudio->time_base, g_pAStream->time_base); - Packet.flags |= AV_PKT_FLAG_KEY; - Packet.data = g_OutBuffer; -#endif - - // Write the compressed frame to the media file. - Packet.stream_index = g_pAStream->index; - if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) - FatalError("Error while writing audio frame"); - return 1; -} - -// add a video output stream -static void AddVideoStream() -{ -#if LIBAVFORMAT_VERSION_MAJOR >= 53 - g_pVStream = avformat_new_stream(g_pContainer, g_pVCodec); -#else - g_pVStream = av_new_stream(g_pContainer, 0); -#endif - if (!g_pVStream) - FatalError("Could not allocate video stream"); - - g_pVideo = g_pVStream->codec; - - avcodec_get_context_defaults3(g_pVideo, g_pVCodec); - g_pVideo->codec_id = g_pVCodec->id; - - // put parameters - // resolution must be a multiple of two - g_pVideo->width = g_Width & ~1; // make even (dimensions should be even) - g_pVideo->height = g_Height & ~1; // make even - /* time base: this is the fundamental unit of time (in seconds) in terms - of which frame timestamps are represented. for fixed-fps content, - timebase should be 1/framerate and timestamp increments should be - identically 1. */ - g_pVideo->time_base.den = g_Framerate.num; - g_pVideo->time_base.num = g_Framerate.den; - //g_pVideo->gop_size = 12; /* emit one intra frame every twelve frames at most */ - g_pVideo->pix_fmt = PIX_FMT_YUV420P; - - // set quality - if (g_VQuality > 100) - g_pVideo->bit_rate = g_VQuality; - else - { - g_pVideo->flags |= CODEC_FLAG_QSCALE; - g_pVideo->global_quality = g_VQuality*FF_QP2LAMBDA; - } - - // some formats want stream headers to be separate - if (g_pFormat->flags & AVFMT_GLOBALHEADER) - g_pVideo->flags |= CODEC_FLAG_GLOBAL_HEADER; - -#if LIBAVCODEC_VERSION_MAJOR < 53 - // for some versions of ffmpeg x264 options must be set explicitly - if (strcmp(g_pVCodec->name, "libx264") == 0) - { - g_pVideo->coder_type = FF_CODER_TYPE_AC; - g_pVideo->flags |= CODEC_FLAG_LOOP_FILTER; - g_pVideo->crf = 23; - g_pVideo->thread_count = 3; - g_pVideo->me_cmp = FF_CMP_CHROMA; - g_pVideo->partitions = X264_PART_I8X8 | X264_PART_I4X4 | X264_PART_P8X8 | X264_PART_B8X8; - g_pVideo->me_method = ME_HEX; - g_pVideo->me_subpel_quality = 7; - g_pVideo->me_range = 16; - g_pVideo->gop_size = 250; - g_pVideo->keyint_min = 25; - g_pVideo->scenechange_threshold = 40; - g_pVideo->i_quant_factor = 0.71; - g_pVideo->b_frame_strategy = 1; - g_pVideo->qcompress = 0.6; - g_pVideo->qmin = 10; - g_pVideo->qmax = 51; - g_pVideo->max_qdiff = 4; - g_pVideo->max_b_frames = 3; - g_pVideo->refs = 3; - g_pVideo->directpred = 1; - g_pVideo->trellis = 1; - g_pVideo->flags2 = CODEC_FLAG2_BPYRAMID | CODEC_FLAG2_MIXED_REFS | CODEC_FLAG2_WPRED | CODEC_FLAG2_8X8DCT | CODEC_FLAG2_FASTPSKIP; - g_pVideo->weighted_p_pred = 2; - } -#endif - - // open the codec -#if LIBAVCODEC_VERSION_MAJOR >= 53 - AVDictionary* pDict = NULL; - if (strcmp(g_pVCodec->name, "libx264") == 0) - av_dict_set(&pDict, "preset", "medium", 0); - - if (avcodec_open2(g_pVideo, g_pVCodec, &pDict) < 0) -#else - if (avcodec_open(g_pVideo, g_pVCodec) < 0) -#endif - FatalError("Could not open video codec %s", g_pVCodec->long_name); - - g_pVFrame = avcodec_alloc_frame(); - if (!g_pVFrame) - FatalError("Could not allocate frame"); - - g_pVFrame->linesize[0] = g_Width; - g_pVFrame->linesize[1] = g_Width/2; - g_pVFrame->linesize[2] = g_Width/2; - g_pVFrame->linesize[3] = 0; -} - -static int WriteFrame(AVFrame* pFrame) -{ - double AudioTime, VideoTime; - - // write interleaved audio frame - if (g_pAStream) - { - VideoTime = (double)g_pVStream->pts.val*g_pVStream->time_base.num/g_pVStream->time_base.den; - do - AudioTime = (double)g_pAStream->pts.val*g_pAStream->time_base.num/g_pAStream->time_base.den; - while (AudioTime < VideoTime && WriteAudioFrame()); - } - - if (!g_pVStream) - return 0; - - AVPacket Packet; - av_init_packet(&Packet); - Packet.data = NULL; - Packet.size = 0; - - g_pVFrame->pts++; - if (g_pFormat->flags & AVFMT_RAWPICTURE) - { - /* raw video case. The API will change slightly in the near - future for that. */ - Packet.flags |= AV_PKT_FLAG_KEY; - Packet.stream_index = g_pVStream->index; - Packet.data = (uint8_t*)pFrame; - Packet.size = sizeof(AVPicture); - - if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) - FatalError("Error while writing video frame"); - return 0; - } - else - { -#if LIBAVCODEC_VERSION_MAJOR >= 54 - int got_packet; - if (avcodec_encode_video2(g_pVideo, &Packet, pFrame, &got_packet) < 0) - FatalError("avcodec_encode_video2 failed"); - if (!got_packet) - return 0; - - if (Packet.pts != AV_NOPTS_VALUE) - Packet.pts = av_rescale_q(Packet.pts, g_pVideo->time_base, g_pVStream->time_base); - if (Packet.dts != AV_NOPTS_VALUE) - Packet.dts = av_rescale_q(Packet.dts, g_pVideo->time_base, g_pVStream->time_base); -#else - Packet.size = avcodec_encode_video(g_pVideo, g_OutBuffer, OUTBUFFER_SIZE, pFrame); - if (Packet.size < 0) - FatalError("avcodec_encode_video failed"); - if (Packet.size == 0) - return 0; - - if( g_pVideo->coded_frame->pts != AV_NOPTS_VALUE) - Packet.pts = av_rescale_q(g_pVideo->coded_frame->pts, g_pVideo->time_base, g_pVStream->time_base); - if( g_pVideo->coded_frame->key_frame ) - Packet.flags |= AV_PKT_FLAG_KEY; - Packet.data = g_OutBuffer; -#endif - // write the compressed frame in the media file - Packet.stream_index = g_pVStream->index; - if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) - FatalError("Error while writing video frame"); - - return 1; - } -} - -void AVWrapper_WriteFrame(uint8_t* pY, uint8_t* pCb, uint8_t* pCr) -{ - g_pVFrame->data[0] = pY; - g_pVFrame->data[1] = pCb; - g_pVFrame->data[2] = pCr; - WriteFrame(g_pVFrame); -} - -void AVWrapper_Init( - void (*pAddFileLogRaw)(const char*), - const char* pFilename, - const char* pDesc, - const char* pSoundFile, - const char* pFormatName, - const char* pVCodecName, - const char* pACodecName, - int Width, int Height, - int FramerateNum, int FramerateDen, - int VQuality) -{ - AddFileLogRaw = pAddFileLogRaw; - av_log_set_callback( &LogCallback ); - - g_Width = Width; - g_Height = Height; - g_Framerate.num = FramerateNum; - g_Framerate.den = FramerateDen; - g_VQuality = VQuality; - - // initialize libav and register all codecs and formats - av_register_all(); - - // find format - g_pFormat = av_guess_format(pFormatName, NULL, NULL); - if (!g_pFormat) - FatalError("Format \"%s\" was not found", pFormatName); - - // allocate the output media context - g_pContainer = avformat_alloc_context(); - if (!g_pContainer) - FatalError("Could not allocate output context"); - - g_pContainer->oformat = g_pFormat; - - // store description of file - av_dict_set(&g_pContainer->metadata, "comment", pDesc, 0); - - // append extesnion to filename - char ext[16]; - strncpy(ext, g_pFormat->extensions, 16); - ext[15] = 0; - ext[strcspn(ext,",")] = 0; - snprintf(g_pContainer->filename, sizeof(g_pContainer->filename), "%s.%s", pFilename, ext); - - // find codecs - g_pVCodec = avcodec_find_encoder_by_name(pVCodecName); - g_pACodec = avcodec_find_encoder_by_name(pACodecName); - - // add audio and video stream to container - g_pVStream = NULL; - g_pAStream = NULL; - - if (g_pVCodec) - AddVideoStream(); - else - Log("Video codec \"%s\" was not found; video will be ignored.\n", pVCodecName); - - if (g_pACodec) - { - g_pSoundFile = fopen(pSoundFile, "rb"); - if (g_pSoundFile) - { - fread(&g_Frequency, 4, 1, g_pSoundFile); - fread(&g_Channels, 4, 1, g_pSoundFile); - AddAudioStream(); - } - else - Log("Could not open %s\n", pSoundFile); - } - else - Log("Audio codec \"%s\" was not found; audio will be ignored.\n", pACodecName); - - if (!g_pAStream && !g_pVStream) - FatalError("No video, no audio, aborting..."); - - // write format info to log - av_dump_format(g_pContainer, 0, g_pContainer->filename, 1); - - // open the output file, if needed - if (!(g_pFormat->flags & AVFMT_NOFILE)) - { - if (avio_open(&g_pContainer->pb, g_pContainer->filename, AVIO_FLAG_WRITE) < 0) - FatalError("Could not open output file (%s)", g_pContainer->filename); - } - - // write the stream header, if any - avformat_write_header(g_pContainer, NULL); - - g_pVFrame->pts = -1; -} - -void AVWrapper_Close() -{ - // output buffered frames - if (g_pVCodec->capabilities & CODEC_CAP_DELAY) - while( WriteFrame(NULL) ); - // output any remaining audio - while( WriteAudioFrame() ); - - // write the trailer, if any. - av_write_trailer(g_pContainer); - - // close the output file - if (!(g_pFormat->flags & AVFMT_NOFILE)) - avio_close(g_pContainer->pb); - - // free everything - if (g_pVStream) - { - avcodec_close(g_pVideo); - av_free(g_pVideo); - av_free(g_pVStream); - av_free(g_pVFrame); - } - if (g_pAStream) - { - avcodec_close(g_pAudio); - av_free(g_pAudio); - av_free(g_pAStream); - av_free(g_pAFrame); - av_free(g_pSamples); - fclose(g_pSoundFile); - } - - av_free(g_pContainer); -} diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/avwrapper/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hedgewars/avwrapper/CMakeLists.txt Mon Jun 17 17:40:01 2013 +0200 @@ -0,0 +1,15 @@ +#FFMPEG/Libav libraries have been searched already in main CMakeLists.txt + +# TODO: this check is only for SDL < 2 +# fpc will take care of linking but we need to have this library installed +find_package(GLUT REQUIRED) + +include_directories(${FFMPEG_INCLUDE_DIR}) + +add_library(avwrapper avwrapper.c) +#TODO: find good VERSION and SOVERSION values +target_link_libraries(avwrapper ${FFMPEG_LIBRARIES}) +install(TARGETS avwrapper RUNTIME DESTINATION ${target_binary_install_dir} + LIBRARY DESTINATION ${target_library_install_dir} + ARCHIVE DESTINATION ${target_library_install_dir}) + diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/avwrapper/avwrapper.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hedgewars/avwrapper/avwrapper.c Mon Jun 17 17:40:01 2013 +0200 @@ -0,0 +1,517 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2004-2013 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include "libavformat/avformat.h" +#include "libavutil/mathematics.h" + +#ifndef AVIO_FLAG_WRITE +#define AVIO_FLAG_WRITE AVIO_WRONLY +#endif + +#if (defined _MSC_VER) +#define AVWRAP_DECL __declspec(dllexport) +#elif ((__GNUC__ >= 3) && (!__EMX__) && (!sun)) +#define AVWRAP_DECL __attribute__((visibility("default"))) +#else +#define AVWRAP_DECL +#endif + +static AVFormatContext* g_pContainer; +static AVOutputFormat* g_pFormat; +static AVStream* g_pAStream; +static AVStream* g_pVStream; +static AVFrame* g_pAFrame; +static AVFrame* g_pVFrame; +static AVCodec* g_pACodec; +static AVCodec* g_pVCodec; +static AVCodecContext* g_pAudio; +static AVCodecContext* g_pVideo; + +static int g_Width, g_Height; +static uint32_t g_Frequency, g_Channels; +static int g_VQuality; +static AVRational g_Framerate; + +static FILE* g_pSoundFile; +static int16_t* g_pSamples; +static int g_NumSamples; + + +#if LIBAVCODEC_VERSION_MAJOR < 54 +#define OUTBUFFER_SIZE 200000 +static uint8_t g_OutBuffer[OUTBUFFER_SIZE]; +#endif + +// pointer to function from hwengine (uUtils.pas) +static void (*AddFileLogRaw)(const char* pString); + +static void FatalError(const char* pFmt, ...) +{ + char Buffer[1024]; + va_list VaArgs; + + va_start(VaArgs, pFmt); + vsnprintf(Buffer, 1024, pFmt, VaArgs); + va_end(VaArgs); + + AddFileLogRaw("Error in av-wrapper: "); + AddFileLogRaw(Buffer); + AddFileLogRaw("\n"); + exit(1); +} + +// Function to be called from libav for logging. +// Note: libav can call LogCallback from different threads +// (there is mutex in AddFileLogRaw). +static void LogCallback(void* p, int Level, const char* pFmt, va_list VaArgs) +{ + char Buffer[1024]; + + vsnprintf(Buffer, 1024, pFmt, VaArgs); + AddFileLogRaw(Buffer); +} + +static void Log(const char* pFmt, ...) +{ + char Buffer[1024]; + va_list VaArgs; + + va_start(VaArgs, pFmt); + vsnprintf(Buffer, 1024, pFmt, VaArgs); + va_end(VaArgs); + + AddFileLogRaw(Buffer); +} + +static void AddAudioStream() +{ +#if LIBAVFORMAT_VERSION_MAJOR >= 53 + g_pAStream = avformat_new_stream(g_pContainer, g_pACodec); +#else + g_pAStream = av_new_stream(g_pContainer, 1); +#endif + if(!g_pAStream) + { + Log("Could not allocate audio stream\n"); + return; + } + g_pAStream->id = 1; + + g_pAudio = g_pAStream->codec; + + avcodec_get_context_defaults3(g_pAudio, g_pACodec); + g_pAudio->codec_id = g_pACodec->id; + + // put parameters + g_pAudio->sample_fmt = AV_SAMPLE_FMT_S16; + g_pAudio->sample_rate = g_Frequency; + g_pAudio->channels = g_Channels; + + // set quality + g_pAudio->bit_rate = 160000; + + // for codecs that support variable bitrate use it, it should be better + g_pAudio->flags |= CODEC_FLAG_QSCALE; + g_pAudio->global_quality = 1*FF_QP2LAMBDA; + + // some formats want stream headers to be separate + if (g_pFormat->flags & AVFMT_GLOBALHEADER) + g_pAudio->flags |= CODEC_FLAG_GLOBAL_HEADER; + + // open it +#if LIBAVCODEC_VERSION_MAJOR >= 53 + if (avcodec_open2(g_pAudio, g_pACodec, NULL) < 0) +#else + if (avcodec_open(g_pAudio, g_pACodec) < 0) +#endif + { + Log("Could not open audio codec %s\n", g_pACodec->long_name); + return; + } + +#if LIBAVCODEC_VERSION_MAJOR >= 54 + if (g_pACodec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE) +#else + if (g_pAudio->frame_size == 0) +#endif + g_NumSamples = 4096; + else + g_NumSamples = g_pAudio->frame_size; + g_pSamples = (int16_t*)av_malloc(g_NumSamples*g_Channels*sizeof(int16_t)); + g_pAFrame = avcodec_alloc_frame(); + if (!g_pAFrame) + { + Log("Could not allocate frame\n"); + return; + } +} + +// returns non-zero if there is more sound +static int WriteAudioFrame() +{ + if (!g_pAStream) + return 0; + + AVPacket Packet = { 0 }; + av_init_packet(&Packet); + + int NumSamples = fread(g_pSamples, 2*g_Channels, g_NumSamples, g_pSoundFile); + +#if LIBAVCODEC_VERSION_MAJOR >= 53 + AVFrame* pFrame = NULL; + if (NumSamples > 0) + { + g_pAFrame->nb_samples = NumSamples; + avcodec_fill_audio_frame(g_pAFrame, g_Channels, AV_SAMPLE_FMT_S16, + (uint8_t*)g_pSamples, NumSamples*2*g_Channels, 1); + pFrame = g_pAFrame; + } + // when NumSamples == 0 we still need to call encode_audio2 to flush + int got_packet; + if (avcodec_encode_audio2(g_pAudio, &Packet, pFrame, &got_packet) != 0) + FatalError("avcodec_encode_audio2 failed"); + if (!got_packet) + return 0; +#else + if (NumSamples == 0) + return 0; + int BufferSize = OUTBUFFER_SIZE; + if (g_pAudio->frame_size == 0) + BufferSize = NumSamples*g_Channels*2; + Packet.size = avcodec_encode_audio(g_pAudio, g_OutBuffer, BufferSize, g_pSamples); + if (Packet.size == 0) + return 1; + if (g_pAudio->coded_frame && g_pAudio->coded_frame->pts != AV_NOPTS_VALUE) + Packet.pts = av_rescale_q(g_pAudio->coded_frame->pts, g_pAudio->time_base, g_pAStream->time_base); + Packet.flags |= AV_PKT_FLAG_KEY; + Packet.data = g_OutBuffer; +#endif + + // Write the compressed frame to the media file. + Packet.stream_index = g_pAStream->index; + if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) + FatalError("Error while writing audio frame"); + return 1; +} + +// add a video output stream +static void AddVideoStream() +{ +#if LIBAVFORMAT_VERSION_MAJOR >= 53 + g_pVStream = avformat_new_stream(g_pContainer, g_pVCodec); +#else + g_pVStream = av_new_stream(g_pContainer, 0); +#endif + if (!g_pVStream) + FatalError("Could not allocate video stream"); + + g_pVideo = g_pVStream->codec; + + avcodec_get_context_defaults3(g_pVideo, g_pVCodec); + g_pVideo->codec_id = g_pVCodec->id; + + // put parameters + // resolution must be a multiple of two + g_pVideo->width = g_Width & ~1; // make even (dimensions should be even) + g_pVideo->height = g_Height & ~1; // make even + /* time base: this is the fundamental unit of time (in seconds) in terms + of which frame timestamps are represented. for fixed-fps content, + timebase should be 1/framerate and timestamp increments should be + identically 1. */ + g_pVideo->time_base.den = g_Framerate.num; + g_pVideo->time_base.num = g_Framerate.den; + //g_pVideo->gop_size = 12; /* emit one intra frame every twelve frames at most */ + g_pVideo->pix_fmt = PIX_FMT_YUV420P; + + // set quality + if (g_VQuality > 100) + g_pVideo->bit_rate = g_VQuality; + else + { + g_pVideo->flags |= CODEC_FLAG_QSCALE; + g_pVideo->global_quality = g_VQuality*FF_QP2LAMBDA; + } + + // some formats want stream headers to be separate + if (g_pFormat->flags & AVFMT_GLOBALHEADER) + g_pVideo->flags |= CODEC_FLAG_GLOBAL_HEADER; + +#if LIBAVCODEC_VERSION_MAJOR < 53 + // for some versions of ffmpeg x264 options must be set explicitly + if (strcmp(g_pVCodec->name, "libx264") == 0) + { + g_pVideo->coder_type = FF_CODER_TYPE_AC; + g_pVideo->flags |= CODEC_FLAG_LOOP_FILTER; + g_pVideo->crf = 23; + g_pVideo->thread_count = 3; + g_pVideo->me_cmp = FF_CMP_CHROMA; + g_pVideo->partitions = X264_PART_I8X8 | X264_PART_I4X4 | X264_PART_P8X8 | X264_PART_B8X8; + g_pVideo->me_method = ME_HEX; + g_pVideo->me_subpel_quality = 7; + g_pVideo->me_range = 16; + g_pVideo->gop_size = 250; + g_pVideo->keyint_min = 25; + g_pVideo->scenechange_threshold = 40; + g_pVideo->i_quant_factor = 0.71; + g_pVideo->b_frame_strategy = 1; + g_pVideo->qcompress = 0.6; + g_pVideo->qmin = 10; + g_pVideo->qmax = 51; + g_pVideo->max_qdiff = 4; + g_pVideo->max_b_frames = 3; + g_pVideo->refs = 3; + g_pVideo->directpred = 1; + g_pVideo->trellis = 1; + g_pVideo->flags2 = CODEC_FLAG2_BPYRAMID | CODEC_FLAG2_MIXED_REFS | CODEC_FLAG2_WPRED | CODEC_FLAG2_8X8DCT | CODEC_FLAG2_FASTPSKIP; + g_pVideo->weighted_p_pred = 2; + } +#endif + + // open the codec +#if LIBAVCODEC_VERSION_MAJOR >= 53 + AVDictionary* pDict = NULL; + if (strcmp(g_pVCodec->name, "libx264") == 0) + av_dict_set(&pDict, "preset", "medium", 0); + + if (avcodec_open2(g_pVideo, g_pVCodec, &pDict) < 0) +#else + if (avcodec_open(g_pVideo, g_pVCodec) < 0) +#endif + FatalError("Could not open video codec %s", g_pVCodec->long_name); + + g_pVFrame = avcodec_alloc_frame(); + if (!g_pVFrame) + FatalError("Could not allocate frame"); + + g_pVFrame->linesize[0] = g_Width; + g_pVFrame->linesize[1] = g_Width/2; + g_pVFrame->linesize[2] = g_Width/2; + g_pVFrame->linesize[3] = 0; +} + +static int WriteFrame(AVFrame* pFrame) +{ + double AudioTime, VideoTime; + + // write interleaved audio frame + if (g_pAStream) + { + VideoTime = (double)g_pVStream->pts.val*g_pVStream->time_base.num/g_pVStream->time_base.den; + do + AudioTime = (double)g_pAStream->pts.val*g_pAStream->time_base.num/g_pAStream->time_base.den; + while (AudioTime < VideoTime && WriteAudioFrame()); + } + + if (!g_pVStream) + return 0; + + AVPacket Packet; + av_init_packet(&Packet); + Packet.data = NULL; + Packet.size = 0; + + g_pVFrame->pts++; + if (g_pFormat->flags & AVFMT_RAWPICTURE) + { + /* raw video case. The API will change slightly in the near + future for that. */ + Packet.flags |= AV_PKT_FLAG_KEY; + Packet.stream_index = g_pVStream->index; + Packet.data = (uint8_t*)pFrame; + Packet.size = sizeof(AVPicture); + + if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) + FatalError("Error while writing video frame"); + return 0; + } + else + { +#if LIBAVCODEC_VERSION_MAJOR >= 54 + int got_packet; + if (avcodec_encode_video2(g_pVideo, &Packet, pFrame, &got_packet) < 0) + FatalError("avcodec_encode_video2 failed"); + if (!got_packet) + return 0; + + if (Packet.pts != AV_NOPTS_VALUE) + Packet.pts = av_rescale_q(Packet.pts, g_pVideo->time_base, g_pVStream->time_base); + if (Packet.dts != AV_NOPTS_VALUE) + Packet.dts = av_rescale_q(Packet.dts, g_pVideo->time_base, g_pVStream->time_base); +#else + Packet.size = avcodec_encode_video(g_pVideo, g_OutBuffer, OUTBUFFER_SIZE, pFrame); + if (Packet.size < 0) + FatalError("avcodec_encode_video failed"); + if (Packet.size == 0) + return 0; + + if( g_pVideo->coded_frame->pts != AV_NOPTS_VALUE) + Packet.pts = av_rescale_q(g_pVideo->coded_frame->pts, g_pVideo->time_base, g_pVStream->time_base); + if( g_pVideo->coded_frame->key_frame ) + Packet.flags |= AV_PKT_FLAG_KEY; + Packet.data = g_OutBuffer; +#endif + // write the compressed frame in the media file + Packet.stream_index = g_pVStream->index; + if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) + FatalError("Error while writing video frame"); + + return 1; + } +} + +AVWRAP_DECL void AVWrapper_WriteFrame(uint8_t* pY, uint8_t* pCb, uint8_t* pCr) +{ + g_pVFrame->data[0] = pY; + g_pVFrame->data[1] = pCb; + g_pVFrame->data[2] = pCr; + WriteFrame(g_pVFrame); +} + +AVWRAP_DECL void AVWrapper_Init( + void (*pAddFileLogRaw)(const char*), + const char* pFilename, + const char* pDesc, + const char* pSoundFile, + const char* pFormatName, + const char* pVCodecName, + const char* pACodecName, + int Width, int Height, + int FramerateNum, int FramerateDen, + int VQuality) +{ + AddFileLogRaw = pAddFileLogRaw; + av_log_set_callback( &LogCallback ); + + g_Width = Width; + g_Height = Height; + g_Framerate.num = FramerateNum; + g_Framerate.den = FramerateDen; + g_VQuality = VQuality; + + // initialize libav and register all codecs and formats + av_register_all(); + + // find format + g_pFormat = av_guess_format(pFormatName, NULL, NULL); + if (!g_pFormat) + FatalError("Format \"%s\" was not found", pFormatName); + + // allocate the output media context + g_pContainer = avformat_alloc_context(); + if (!g_pContainer) + FatalError("Could not allocate output context"); + + g_pContainer->oformat = g_pFormat; + + // store description of file + av_dict_set(&g_pContainer->metadata, "comment", pDesc, 0); + + // append extesnion to filename + char ext[16]; + strncpy(ext, g_pFormat->extensions, 16); + ext[15] = 0; + ext[strcspn(ext,",")] = 0; + snprintf(g_pContainer->filename, sizeof(g_pContainer->filename), "%s.%s", pFilename, ext); + + // find codecs + g_pVCodec = avcodec_find_encoder_by_name(pVCodecName); + g_pACodec = avcodec_find_encoder_by_name(pACodecName); + + // add audio and video stream to container + g_pVStream = NULL; + g_pAStream = NULL; + + if (g_pVCodec) + AddVideoStream(); + else + Log("Video codec \"%s\" was not found; video will be ignored.\n", pVCodecName); + + if (g_pACodec) + { + g_pSoundFile = fopen(pSoundFile, "rb"); + if (g_pSoundFile) + { + fread(&g_Frequency, 4, 1, g_pSoundFile); + fread(&g_Channels, 4, 1, g_pSoundFile); + AddAudioStream(); + } + else + Log("Could not open %s\n", pSoundFile); + } + else + Log("Audio codec \"%s\" was not found; audio will be ignored.\n", pACodecName); + + if (!g_pAStream && !g_pVStream) + FatalError("No video, no audio, aborting..."); + + // write format info to log + av_dump_format(g_pContainer, 0, g_pContainer->filename, 1); + + // open the output file, if needed + if (!(g_pFormat->flags & AVFMT_NOFILE)) + { + if (avio_open(&g_pContainer->pb, g_pContainer->filename, AVIO_FLAG_WRITE) < 0) + FatalError("Could not open output file (%s)", g_pContainer->filename); + } + + // write the stream header, if any + avformat_write_header(g_pContainer, NULL); + + g_pVFrame->pts = -1; +} + +AVWRAP_DECL void AVWrapper_Close() +{ + // output buffered frames + if (g_pVCodec->capabilities & CODEC_CAP_DELAY) + while( WriteFrame(NULL) ); + // output any remaining audio + while( WriteAudioFrame() ); + + // write the trailer, if any. + av_write_trailer(g_pContainer); + + // close the output file + if (!(g_pFormat->flags & AVFMT_NOFILE)) + avio_close(g_pContainer->pb); + + // free everything + if (g_pVStream) + { + avcodec_close(g_pVideo); + av_free(g_pVideo); + av_free(g_pVStream); + av_free(g_pVFrame); + } + if (g_pAStream) + { + avcodec_close(g_pAudio); + av_free(g_pAudio); + av_free(g_pAStream); + av_free(g_pAFrame); + av_free(g_pSamples); + fclose(g_pSoundFile); + } + + av_free(g_pContainer); +} diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/config.inc.in --- a/hedgewars/config.inc.in Mon Jun 17 10:48:50 2013 -0400 +++ b/hedgewars/config.inc.in Mon Jun 17 17:40:01 2013 +0200 @@ -25,5 +25,4 @@ cVersionString = '${HEDGEWARS_VERSION}'; cRevisionString = '${HEDGEWARS_REVISION}'; cHashString = '${HEDGEWARS_HASH}'; - cLuaLibrary = '${LUA_LIBRARY}'; cDefaultPathPrefix = '${HEDGEWARS_FULL_DATADIR}/Data'; diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/sdlmain/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hedgewars/sdlmain/CMakeLists.txt Mon Jun 17 17:40:01 2013 +0200 @@ -0,0 +1,7 @@ +find_package(SDL REQUIRED) + +include_directories(${SDL_INCLUDE_DIR}) + +add_library (SDLmain STATIC SDLMain.m) + + diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/sdlmain/SDLMain.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hedgewars/sdlmain/SDLMain.h Mon Jun 17 17:40:01 2013 +0200 @@ -0,0 +1,16 @@ +/* SDLMain.m - main entry point for our Cocoa-ized SDL app + Initial Version: Darrell Walisser + Non-NIB-Code & other changes: Max Horn + + Feel free to customize this file to suit your needs +*/ + +#ifndef _SDLMain_h_ +#define _SDLMain_h_ + +#import + +@interface SDLMain : NSObject +@end + +#endif /* _SDLMain_h_ */ diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/sdlmain/SDLMain.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hedgewars/sdlmain/SDLMain.m Mon Jun 17 17:40:01 2013 +0200 @@ -0,0 +1,385 @@ +/* SDLMain.m - main entry point for our Cocoa-ized SDL app + Initial Version: Darrell Walisser + Non-NIB-Code & other changes: Max Horn + + Feel free to customize this file to suit your needs +*/ + +#include "SDL.h" +#include "SDLMain.h" +#include /* for MAXPATHLEN */ +#include + +/* For some reaon, Apple removed setAppleMenu from the headers in 10.4, + but the method still is there and works. To avoid warnings, we declare + it ourselves here. */ +@interface NSApplication(SDL_Missing_Methods) +- (void)setAppleMenu:(NSMenu *)menu; +@end + +/* Use this flag to determine whether we use SDLMain.nib or not */ +#define SDL_USE_NIB_FILE 0 + +/* Use this flag to determine whether we use CPS (docking) or not */ +#define SDL_USE_CPS 1 +#ifdef SDL_USE_CPS +/* Portions of CPS.h */ +typedef struct CPSProcessSerNum +{ + UInt32 lo; + UInt32 hi; +} CPSProcessSerNum; + +extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); +extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); +extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); + +#endif /* SDL_USE_CPS */ + +static int gArgc; +static char **gArgv; +static BOOL gFinderLaunch; +static BOOL gCalledAppMainline = FALSE; + +static NSString *getApplicationName(void) +{ + const NSDictionary *dict; + NSString *appName = 0; + + /* Determine the application name */ + dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); + if (dict) + appName = [dict objectForKey: @"CFBundleName"]; + + if (![appName length]) + appName = [[NSProcessInfo processInfo] processName]; + + return appName; +} + +#if SDL_USE_NIB_FILE +/* A helper category for NSString */ +@interface NSString (ReplaceSubString) +- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; +@end +#endif + +@interface SDLApplication : NSApplication +@end + +@implementation SDLApplication +/* Invoked from the Quit menu item */ +- (void)terminate:(id)sender +{ + /* Post a SDL_QUIT event */ + SDL_Event event; + event.type = SDL_QUIT; + SDL_PushEvent(&event); +} +@end + +/* The main class of the application, the application's delegate */ +@implementation SDLMain + +/* Set the working directory to the .app's parent directory */ +- (void) setupWorkingDirectory:(BOOL)shouldChdir +{ + if (shouldChdir) + { + char parentdir[MAXPATHLEN]; + CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); + if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) { + chdir(parentdir); /* chdir to the binary app's parent */ + } + CFRelease(url); + CFRelease(url2); + } +} + +#if SDL_USE_NIB_FILE + +/* Fix menu to contain the real app name instead of "SDL App" */ +- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName +{ + NSRange aRange; + NSEnumerator *enumerator; + NSMenuItem *menuItem; + + aRange = [[aMenu title] rangeOfString:@"SDL App"]; + if (aRange.length != 0) + [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]]; + + enumerator = [[aMenu itemArray] objectEnumerator]; + while ((menuItem = [enumerator nextObject])) + { + aRange = [[menuItem title] rangeOfString:@"SDL App"]; + if (aRange.length != 0) + [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]]; + if ([menuItem hasSubmenu]) + [self fixMenu:[menuItem submenu] withAppName:appName]; + } + [ aMenu sizeToFit ]; +} + +#else + +static void setApplicationMenu(void) +{ + /* warning: this code is very odd */ + NSMenu *appleMenu; + NSMenuItem *menuItem; + NSString *title; + NSString *appName; + + appName = getApplicationName(); + appleMenu = [[NSMenu alloc] initWithTitle:@""]; + + /* Add menu items */ + title = [@"About " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; + + title = [@"Hide " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; + + menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; + [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; + + [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; + + [appleMenu addItem:[NSMenuItem separatorItem]]; + + title = [@"Quit " stringByAppendingString:appName]; + [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; + + + /* Put menu into the menubar */ + menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; + [menuItem setSubmenu:appleMenu]; + [[NSApp mainMenu] addItem:menuItem]; + + /* Tell the application object that this is now the application menu */ + [NSApp setAppleMenu:appleMenu]; + + /* Finally give up our references to the objects */ + [appleMenu release]; + [menuItem release]; +} + +/* Create a window menu */ +static void setupWindowMenu(void) +{ + NSMenu *windowMenu; + NSMenuItem *windowMenuItem; + NSMenuItem *menuItem; + + windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; + + /* "Minimize" item */ + menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; + [windowMenu addItem:menuItem]; + [menuItem release]; + + /* Put menu into the menubar */ + windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; + [windowMenuItem setSubmenu:windowMenu]; + [[NSApp mainMenu] addItem:windowMenuItem]; + + /* Tell the application object that this is now the window menu */ + [NSApp setWindowsMenu:windowMenu]; + + /* Finally give up our references to the objects */ + [windowMenu release]; + [windowMenuItem release]; +} + +/* Replacement for NSApplicationMain */ +static void CustomApplicationMain (int argc, char **argv) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + SDLMain *sdlMain; + + /* Ensure the application object is initialised */ + [SDLApplication sharedApplication]; + +#ifdef SDL_USE_CPS + { + CPSProcessSerNum PSN; + /* Tell the dock about us */ + if (!CPSGetCurrentProcess(&PSN)) + if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103)) + if (!CPSSetFrontProcess(&PSN)) + [SDLApplication sharedApplication]; + } +#endif /* SDL_USE_CPS */ + + /* Set up the menubar */ + NSMenu *menu = [[NSMenu alloc] init]; + [NSApp setMainMenu:menu]; + setApplicationMenu(); + setupWindowMenu(); + [menu release]; + + /* Create SDLMain and make it the app delegate */ + sdlMain = [[SDLMain alloc] init]; + [NSApp setDelegate:sdlMain]; + + /* Start the main event loop */ + [NSApp run]; + + [sdlMain release]; + [pool release]; +} + +#endif + + +/* + * Catch document open requests...this lets us notice files when the app + * was launched by double-clicking a document, or when a document was + * dragged/dropped on the app's icon. You need to have a + * CFBundleDocumentsType section in your Info.plist to get this message, + * apparently. + * + * Files are added to gArgv, so to the app, they'll look like command line + * arguments. Previously, apps launched from the finder had nothing but + * an argv[0]. + * + * This message may be received multiple times to open several docs on launch. + * + * This message is ignored once the app's mainline has been called. + */ +- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename +{ + const char *temparg; + size_t arglen; + char *arg; + char **newargv; + + if (!gFinderLaunch) /* MacOS is passing command line args. */ + return FALSE; + + if (gCalledAppMainline) /* app has started, ignore this document. */ + return FALSE; + + temparg = [filename UTF8String]; + arglen = SDL_strlen(temparg) + 1; + arg = (char *) SDL_malloc(arglen); + if (arg == NULL) + return FALSE; + + newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2)); + if (newargv == NULL) + { + SDL_free(arg); + return FALSE; + } + gArgv = newargv; + + SDL_strlcpy(arg, temparg, arglen); + gArgv[gArgc++] = arg; + gArgv[gArgc] = NULL; + return TRUE; +} + + +/* Called when the internal event loop has just started running */ +- (void) applicationDidFinishLaunching: (NSNotification *) note +{ + int status; + + /* Set the working directory to the .app's parent directory */ + [self setupWorkingDirectory:gFinderLaunch]; + +#if SDL_USE_NIB_FILE + /* Set the main menu to contain the real app name instead of "SDL App" */ + [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()]; +#endif + + /* Hand off to main application code */ + gCalledAppMainline = TRUE; + status = SDL_main (gArgc, gArgv); + + /* We're done, thank you for playing */ + exit(status); +} +@end + + +@implementation NSString (ReplaceSubString) + +- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString +{ + unsigned int bufferSize; + unsigned int selfLen = [self length]; + unsigned int aStringLen = [aString length]; + unichar *buffer; + NSRange localRange; + NSString *result; + + bufferSize = selfLen + aStringLen - aRange.length; + buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar)); + + /* Get first part into buffer */ + localRange.location = 0; + localRange.length = aRange.location; + [self getCharacters:buffer range:localRange]; + + /* Get middle part into buffer */ + localRange.location = 0; + localRange.length = aStringLen; + [aString getCharacters:(buffer+aRange.location) range:localRange]; + + /* Get last part into buffer */ + localRange.location = aRange.location + aRange.length; + localRange.length = selfLen - localRange.location; + [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange]; + + /* Build output string */ + result = [NSString stringWithCharacters:buffer length:bufferSize]; + + NSDeallocateMemoryPages(buffer, bufferSize); + + return result; +} + +@end + + + +#ifdef main +# undef main +#endif + + +/* Main entry point to executable - should *not* be SDL_main! */ +int main (int argc, char **argv) +{ + /* Copy the arguments into a global variable */ + /* This is passed if we are launched by double-clicking */ + if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + gArgv = (char **) SDL_malloc(sizeof (char *) * 2); + gArgv[0] = argv[0]; + gArgv[1] = NULL; + gArgc = 1; + gFinderLaunch = YES; + } else { + int i; + gArgc = argc; + gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1)); + for (i = 0; i <= argc; i++) + gArgv[i] = argv[i]; + gFinderLaunch = NO; + } + +#if SDL_USE_NIB_FILE + [SDLApplication poseAsClass:[NSApplication class]]; + NSApplicationMain (argc, argv); +#else + CustomApplicationMain (argc, argv); +#endif + return 0; +} + diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/uGears.pas --- a/hedgewars/uGears.pas Mon Jun 17 10:48:50 2013 -0400 +++ b/hedgewars/uGears.pas Mon Jun 17 17:40:01 2013 +0200 @@ -42,7 +42,6 @@ function GetAmmo(Hedgehog: PHedgehog): TAmmoType; function GetUtility(Hedgehog: PHedgehog): TAmmoType; procedure HideHog(HH: PHedgehog); -procedure RestoreHog(HH: PHedgehog); procedure ProcessGears; procedure EndTurnCleanup; procedure SetAllToActive; diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/uPhysFSLayer.pas --- a/hedgewars/uPhysFSLayer.pas Mon Jun 17 10:48:50 2013 -0400 +++ b/hedgewars/uPhysFSLayer.pas Mon Jun 17 17:40:01 2013 +0200 @@ -3,17 +3,12 @@ interface uses SDLh, LuaPas; -const PhysfsLibName = {$IFDEF PHYSFS_INTERNAL}'libhw_physfs'{$ELSE}'libphysfs'{$ENDIF}; +const PhysfsLibName = {$IFDEF PHYSFS_INTERNAL}'libhwphysfs'{$ELSE}'libphysfs'{$ENDIF}; const PhyslayerLibName = 'libphyslayer'; {$IFNDEF WIN32} {$linklib physfs} {$linklib physlayer} - - {statically linking physfs brings IOKit dependency on OSX} - {$IFDEF DARWIN} - {$linkframework IOKit} - {$ENDIF} {$ENDIF} procedure initModule; diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Mon Jun 17 10:48:50 2013 -0400 +++ b/hedgewars/uScript.pas Mon Jun 17 17:40:01 2013 +0200 @@ -54,6 +54,7 @@ implementation {$IFDEF USE_LUA_SCRIPT} + uses LuaPas, uConsole, uConsts, diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Mon Jun 17 10:48:50 2013 -0400 +++ b/hedgewars/uTeams.pas Mon Jun 17 17:40:01 2013 +0200 @@ -20,8 +20,8 @@ unit uTeams; interface -uses uConsts, uInputHandler, uGears, uRandom, uFloat, uStats, uVisualGears, uCollisions, GLunit, - uSound, uStore, uTypes +uses uConsts, uInputHandler, uRandom, uFloat, uStats, uVisualGears, + uCollisions, GLunit, uSound, uStore, uTypes, uScript {$IFDEF USE_TOUCH_INTERFACE}, uWorld{$ENDIF}; @@ -34,6 +34,8 @@ procedure InitTeams; function TeamSize(p: PTeam): Longword; procedure RecountTeamHealth(team: PTeam); +procedure RestoreHog(HH: PHedgehog); + procedure RestoreTeamsFromSave; function CheckForWin: boolean; procedure TeamGoneEffect(var Team: TTeam); @@ -496,6 +498,17 @@ AddVisualGear(0, 0, vgtTeamHealthSorter) end; +procedure RestoreHog(HH: PHedgehog); +begin + HH^.Gear:=HH^.GearHidden; + HH^.GearHidden:= nil; + InsertGearToList(HH^.Gear); + HH^.Gear^.State:= (HH^.Gear^.State and (not (gstHHDriven or gstInvisible or gstAttacking))) or gstAttacked; + AddGearCI(HH^.Gear); + HH^.Gear^.Active:= true; + ScriptCall('onHogRestore', HH^.Gear^.Uid) +end; + procedure RestoreTeamsFromSave; var t: LongInt; begin diff -r e653e96b0ec3 -r 2bf3796c5855 hedgewars/uVideoRec.pas --- a/hedgewars/uVideoRec.pas Mon Jun 17 10:48:50 2013 -0400 +++ b/hedgewars/uVideoRec.pas Mon Jun 17 17:40:01 2013 +0200 @@ -28,9 +28,6 @@ {$ELSE} {$IFNDEF WIN32} - {$linklib avcodec} - {$linklib avformat} - {$linklib avutil} {$linklib avwrapper} {$ENDIF} diff -r e653e96b0ec3 -r 2bf3796c5855 misc/liblua/CMakeLists.txt --- a/misc/liblua/CMakeLists.txt Mon Jun 17 10:48:50 2013 -0400 +++ b/misc/liblua/CMakeLists.txt Mon Jun 17 17:40:01 2013 +0200 @@ -4,17 +4,23 @@ if(WIN32) add_definitions(-DLUA_BUILD_AS_DLL) - add_library(lua SHARED ${lua_src}) - - set(LUA_LIBRARY lua.dll) - - set_target_properties(lua PROPERTIES PREFIX "") - install(TARGETS lua RUNTIME DESTINATION ${target_library_install_dir}) else(WIN32) add_definitions(-DLUA_USE_LINUX) - add_library(lua STATIC ${lua_src}) - set(LUA_LIBRARY lua) + add_definitions(-fvisibility=default) #TODO: fixme endif(WIN32) +add_library(lua ${lua_src}) + +set_target_properties(lua PROPERTIES + VERSION "5.1.4" + SOVERSION 1 + OUTPUT_NAME ${lua_output_name}) +install(TARGETS lua RUNTIME DESTINATION ${target_binary_install_dir} + LIBRARY DESTINATION ${target_library_install_dir} + ARCHIVE DESTINATION ${target_library_install_dir}) +get_target_property(lua_fullpath lua LOCATION) + +set(LUA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Lua include dir" FORCE) +set(LUA_LIBRARY ${lua_fullpath} CACHE STRING "Lua library" FORCE) diff -r e653e96b0ec3 -r 2bf3796c5855 misc/libphysfs/CMakeLists.txt --- a/misc/libphysfs/CMakeLists.txt Mon Jun 17 10:48:50 2013 -0400 +++ b/misc/libphysfs/CMakeLists.txt Mon Jun 17 17:40:01 2013 +0200 @@ -35,15 +35,6 @@ include(CheckCSourceCompiles) -# 32bit platforms won't link unless this is set -# although Windows doesn't like it -if(NOT WINDOWS) - if(CMAKE_SIZEOF_VOID_P LESS 8) - add_definitions(-DPHYSFS_NO_64BIT_SUPPORT=1) - endif(CMAKE_SIZEOF_VOID_P LESS 8) -endif(NOT WINDOWS) - - if(MACOSX) # Fallback to older OS X on PowerPC to support wider range of systems... if(CMAKE_OSX_ARCHITECTURES MATCHES ppc) @@ -61,31 +52,8 @@ # Add some gcc-specific command lines. if(CMAKE_COMPILER_IS_GNUCC) - # Always build with debug symbols...you can strip it later. + # Always build with debug symbols... you can strip it later. add_definitions(-g -fsigned-char) - - # Stupid BeOS generates warnings in the system headers. - if(NOT BEOS) - add_definitions(-Wall) - endif(NOT BEOS) - - CHECK_C_SOURCE_COMPILES(" - #if ((defined(__GNUC__)) && (__GNUC__ >= 4)) - int main(int argc, char **argv) { int is_gcc4 = 1; return 0; } - #else - #error This is not gcc4. - #endif - " PHYSFS_IS_GCC4) - - if(PHYSFS_IS_GCC4) - # Not supported on several operating systems at this time. - if(NOT SOLARIS AND NOT WINDOWS) - add_definitions(-fvisibility=hidden) - endif(NOT SOLARIS AND NOT WINDOWS) - endif(PHYSFS_IS_GCC4) - - # Don't use -rpath. - set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE) endif(CMAKE_COMPILER_IS_GNUCC) if(CMAKE_C_COMPILER_ID STREQUAL "SunPro") @@ -180,6 +148,7 @@ if(WINDOWS) set(PHYSFS_HAVE_CDROM_SUPPORT TRUE) set(PHYSFS_HAVE_THREAD_SUPPORT TRUE) + list(APPEND OTHER_LDFLAGS ${SDL_LIBRARY}) endif(WINDOWS) if(NOT PHYSFS_HAVE_CDROM_SUPPORT) @@ -252,50 +221,26 @@ #endif(PHYSFS_ARCHIVE_ISO9660) -##as needed by Hedgewars configuration -if(WINDOWS) - option(PHYSFS_BUILD_STATIC "Build static library" FALSE) - option(PHYSFS_BUILD_SHARED "Build shared library" TRUE) - list(APPEND OTHER_LDFLAGS ${SDL_LIBRARY}) -else(WINDOWS) - option(PHYSFS_BUILD_STATIC "Build static library" TRUE) - option(PHYSFS_BUILD_SHARED "Build shared library" FALSE) -endif(WINDOWS) - -if(PHYSFS_BUILD_STATIC) - add_library(physfs STATIC ${PHYSFS_SRCS}) - set_target_properties(physfs PROPERTIES OUTPUT_NAME ${physfs_output_name}) ## - set(lib_prefix ${CMAKE_STATIC_LIBRARY_PREFIX}) ## - set(lib_suffix ${CMAKE_STATIC_LIBRARY_SUFFIX}) ## -endif(PHYSFS_BUILD_STATIC) - -if(PHYSFS_BUILD_SHARED) - add_library(physfs SHARED ${PHYSFS_SRCS}) - set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION}) - set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION}) - set_target_properties(physfs PROPERTIES OUTPUT_NAME ${physfs_output_name}) ## - target_link_libraries(physfs ${optional_library_libs} ${OTHER_LDFLAGS}) - install(TARGETS physfs RUNTIME DESTINATION ${target_library_install_dir}) ## - set(lib_prefix ${CMAKE_SHARED_LIBRARY_PREFIX}) ## - set(lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX}) ## -endif(PHYSFS_BUILD_SHARED) - -if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC) - message(FATAL "Both shared and static libraries are disabled!") -endif(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC) - -# CMake FAQ says I need this... -if(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC) - set_target_properties(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1) -endif(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC) +##Hedgewars modifications +add_library(physfs ${PHYSFS_SRCS}) +set_target_properties(physfs PROPERTIES + VERSION ${PHYSFS_VERSION} + SOVERSION ${PHYSFS_SOVERSION} + OUTPUT_NAME ${physfs_output_name}) +target_link_libraries(physfs ${optional_library_libs} ${OTHER_LDFLAGS}) +install(TARGETS physfs RUNTIME DESTINATION ${target_binary_install_dir} + LIBRARY DESTINATION ${target_library_install_dir} + ARCHIVE DESTINATION ${target_library_install_dir}) +get_target_property(physfs_fullpath physfs LOCATION) ## added standard variables emulating the FindPhysFS.cmake ones (FORCE or cmake won't pick 'em) -set(PHYSFS_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/misc/libphysfs/ CACHE STRING "" FORCE) -set(PHYSFS_LIBRARY ${LIBRARY_OUTPUT_PATH}/${lib_prefix}${physfs_output_name}${lib_suffix} CACHE STRING "" FORCE) +set(PHYSFS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Physfs include dir" FORCE) +set(PHYSFS_LIBRARY ${physfs_fullpath} CACHE STRING "Physfs library path" FORCE) -## removed install, language bindings and test program +## removed language bindings and test program ## simplified configuration output +## merged shared and static library building #message(STATUS "PhysFS will be built with ${PHYSFS_FEATURES} support") diff -r e653e96b0ec3 -r 2bf3796c5855 misc/libphysfs/physfs_internal.h --- a/misc/libphysfs/physfs_internal.h Mon Jun 17 10:48:50 2013 -0400 +++ b/misc/libphysfs/physfs_internal.h Mon Jun 17 17:40:01 2013 +0200 @@ -322,13 +322,8 @@ #define __PHYSFS_ARRAYLEN(x) ( (sizeof (x)) / (sizeof (x[0])) ) #ifdef PHYSFS_NO_64BIT_SUPPORT -/* if a 32bit compiler sees something with this many bits: 0xFFFFFFFFFFFFFFFF - * it doesn't know if it really means 64bit or if it's supposed to squeeze - * it into 32 bit, so without the ULL it squeezes the number to 32 bit, - * with it it forces it to be 64bits - */ -#define __PHYSFS_SI64(x) ((PHYSFS_sint64) (x##LL)) -#define __PHYSFS_UI64(x) ((PHYSFS_uint64) (x##ULL)) +#define __PHYSFS_SI64(x) ((PHYSFS_sint64) (x)) +#define __PHYSFS_UI64(x) ((PHYSFS_uint64) (x)) #elif (defined __GNUC__) #define __PHYSFS_SI64(x) x##LL #define __PHYSFS_UI64(x) x##ULL diff -r e653e96b0ec3 -r 2bf3796c5855 misc/libphyslayer/CMakeLists.txt --- a/misc/libphyslayer/CMakeLists.txt Mon Jun 17 10:48:50 2013 -0400 +++ b/misc/libphyslayer/CMakeLists.txt Mon Jun 17 17:40:01 2013 +0200 @@ -12,25 +12,17 @@ hwpacksmounter.c ) -set(build_type STATIC) -set(lib_prefix ${CMAKE_STATIC_LIBRARY_PREFIX}) -set(lib_suffix ${CMAKE_STATIC_LIBRARY_SUFFIX}) +#compiles and links actual library +add_library (physlayer ${PHYSLAYER_SRCS}) +#TODO: find good VERSION and SOVERSION values +target_link_libraries(physlayer ${SDL_LIBRARY} lua physfs) +install(TARGETS physlayer RUNTIME DESTINATION ${target_binary_install_dir} + LIBRARY DESTINATION ${target_library_install_dir} + ARCHIVE DESTINATION ${target_library_install_dir}) +get_target_property(physlayer_fullpath physlayer LOCATION) -if(WIN32) - set(build_type SHARED) - set(lib_prefix ${CMAKE_SHARED_LIBRARY_PREFIX}) - set(lib_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX}) -endif(WIN32) - -#compiles and links actual library -add_library (physlayer ${build_type} ${PHYSLAYER_SRCS}) - -if(WIN32) - target_link_libraries(physlayer ${SDL_LIBRARY} ${LUA_LIBRARY} ${PHYSFS_LIBRARY}) - install(TARGETS physlayer RUNTIME DESTINATION ${target_library_install_dir}) -endif() ## added standard variables (FORCE or cmake won't pick 'em) -set(PHYSLAYER_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/misc/libphyslayer/ CACHE STRING "" FORCE) -set(PHYSLAYER_LIBRARY ${LIBRARY_OUTPUT_PATH}/${lib_prefix}physlayer${lib_suffix} CACHE STRING "" FORCE) +set(PHYSLAYER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Physlayer include dir" FORCE) +set(PHYSLAYER_LIBRARY ${physlayer_fullpath} CACHE STRING "Physlayer library" FORCE) diff -r e653e96b0ec3 -r 2bf3796c5855 project_files/hedgewars.pro --- a/project_files/hedgewars.pro Mon Jun 17 10:48:50 2013 -0400 +++ b/project_files/hedgewars.pro Mon Jun 17 17:40:01 2013 +0200 @@ -248,7 +248,7 @@ RESOURCES += ../QTfrontend/hedgewars.qrc -LIBS += -L../bin -lhw_physfs -lphyslayer +LIBS += -L../bin -lhwphysfs -lphyslayer macx { QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6 diff -r e653e96b0ec3 -r 2bf3796c5855 tools/CMakeLists.txt --- a/tools/CMakeLists.txt Mon Jun 17 10:48:50 2013 -0400 +++ b/tools/CMakeLists.txt Mon Jun 17 17:40:01 2013 +0200 @@ -48,8 +48,6 @@ 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 diff -r e653e96b0ec3 -r 2bf3796c5855 tools/build_windows.bat