diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-01-08 17:34:25 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-01-08 17:34:25 +0200 |
commit | 9fbb0889a7a73d3e879f76aa4c398dcb78c532ed (patch) | |
tree | 9169e3659112cc35166c2122aaa4ef07c5366415 /src | |
parent | 426c206d7e08ac4c5b45ec51450d02aa26b8eebd (diff) | |
download | minetest-9fbb0889a7a73d3e879f76aa4c398dcb78c532ed.tar.gz minetest-9fbb0889a7a73d3e879f76aa4c398dcb78c532ed.tar.bz2 minetest-9fbb0889a7a73d3e879f76aa4c398dcb78c532ed.zip |
CMake stuff works now on linux and windows... and should be possible to make to work on OS X.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 177 | ||||
-rw-r--r-- | src/main.cpp | 20 | ||||
-rw-r--r-- | src/porting.cpp | 17 | ||||
-rw-r--r-- | src/servermain.cpp | 21 |
4 files changed, 191 insertions, 44 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 72a159f16..083395271 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,19 +1,37 @@ project(minetest) cmake_minimum_required( VERSION 2.6 ) -set ( CMAKE_BUILD_TYPE Debug ) -add_definitions ( -Wall -DRUN_IN_PLACE -O2) -find_package(ZLIB REQUIRED) -find_package(X11 REQUIRED) -find_package(OpenGL REQUIRED) -find_package(JPEG REQUIRED) -find_package(BZip2 REQUIRED) -if( UNIX ) - #set( platform_SRCS some_necessary_linux_file.cpp ) -else( UNIX ) - #windows - #set( platform_SRCS dllmain.cpp stdafx.cpp ) -endif( UNIX ) +if(RUN_IN_PLACE) + add_definitions ( -DRUN_IN_PLACE ) +endif(RUN_IN_PLACE) + +if(UNIX) + # Unix + if(BUILD_CLIENT) + find_package(X11 REQUIRED) + find_package(OpenGL REQUIRED) + find_package(JPEG REQUIRED) + find_package(BZip2 REQUIRED) + endif(BUILD_CLIENT) + find_package(ZLIB REQUIRED) + set(SERVER_PLATFORM_LIBS -lpthread) +elseif(WIN32) + # Windows + # Surpress some warnings + add_definitions ( /D "_CRT_SECURE_NO_DEPRECATE" /W1 ) + # Zlib stuff + set(ZLIB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/../../zlib/zlib-1.2.5" + CACHE PATH "Zlib include directory") + set(ZLIB_LIBRARIES "${PROJECT_SOURCE_DIR}/../../zlib125dll/dll32/zlibwapi.lib" + CACHE PATH "Path to zlibwapi.lib") + set(ZLIB_DLL "${PROJECT_SOURCE_DIR}/../../zlib125dll/dll32/zlibwapi.dll" + CACHE PATH "Path to zlibwapi.dll (for installation)") +endif() + +configure_file( + "${PROJECT_SOURCE_DIR}/config.h.in" + "${PROJECT_BINARY_DIR}/config.h" +) set(minetest_SRCS porting.cpp @@ -48,26 +66,135 @@ set(minetest_SRCS test.cpp ) +set(minetestserver_SRCS + porting.cpp + materials.cpp + defaultsettings.cpp + mapnode.cpp + voxel.cpp + mapblockobject.cpp + inventory.cpp + debug.cpp + serialization.cpp + light.cpp + filesys.cpp + connection.cpp + environment.cpp + server.cpp + socket.cpp + mapblock.cpp + mapsector.cpp + heightmap.cpp + map.cpp + player.cpp + utility.cpp + servermain.cpp + test.cpp +) + include_directories( - ${ZLIB_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} ${IRRLICHT_INCLUDE_DIR} + ${ZLIB_INCLUDE_DIR} + ${CMAKE_BUILD_TYPE} "${PROJECT_SOURCE_DIR}/jthread" ) set(EXECUTABLE_OUTPUT_PATH ../bin) -add_executable(minetest ${minetest_SRCS}) +if(BUILD_CLIENT) + add_executable(minetest ${minetest_SRCS}) + target_link_libraries( + minetest + ${ZLIB_LIBRARIES} + ${IRRLICHT_LIBRARY} + ${OPENGL_LIBRARIES} + ${JPEG_LIBRARIES} + ${BZIP2_LIBRARIES} + jthread + ) +endif(BUILD_CLIENT) +if(BUILD_SERVER) + add_executable(minetestserver ${minetestserver_SRCS}) + target_link_libraries( + minetestserver + ${ZLIB_LIBRARIES} + jthread + ${SERVER_PLATFORM_LIBS} + ) +endif(BUILD_SERVER) -target_link_libraries( - minetest - ${ZLIB_LIBRARIES} - ${IRRLICHT_LIBRARY} - ${OPENGL_LIBRARIES} - ${JPEG_LIBRARIES} - ${BZIP2_LIBRARIES} - jthread -) +# Set some optimizations and tweaks +if( UNIX ) + # Unix + + set(UNIX_FLAGS "-Wall") + + if(BUILD_CLIENT) + set_target_properties(minetest PROPERTIES COMPILE_FLAGS + "${UNIX_FLAGS}") + endif(BUILD_CLIENT) + + if(BUILD_SERVER) + set_target_properties(minetestserver PROPERTIES COMPILE_FLAGS + "${UNIX_FLAGS} -DSERVER") + endif(BUILD_SERVER) + +else( UNIX ) + # Windows + + if(BUILD_CLIENT) + # EHa enables SEH exceptions (used for catching segfaults) + set_target_properties(minetest PROPERTIES COMPILE_FLAGS + "/O2 /Ob2 /Oi /Ot /Oy /GL /EHa") + endif(BUILD_CLIENT) + + if(BUILD_SERVER) + # EHa enables SEH exceptions (used for catching segfaults) + set_target_properties(minetestserver PROPERTIES COMPILE_FLAGS + "/O2 /Ob2 /Oi /Ot /Oy /GL /EHa /D SERVER") + endif(BUILD_SERVER) + +endif( UNIX ) + +# +# Installation +# + +if(WIN32) + set(DATADIR "data") + set(BINDIR "bin") +elseif(APPLE) + set(DATADIR "share/minetest") + set(BINDIR "bin") +elseif(UNIX) + set(DATADIR "share/minetest") + set(BINDIR "bin") +endif() + +if(BUILD_CLIENT) + install(TARGETS minetest DESTINATION ${BINDIR}) + + file(GLOB images "${CMAKE_CURRENT_SOURCE_DIR}/../data/*.png") + + install(FILES ${images} DESTINATION ${DATADIR}) + + if(WIN32) + if(DEFINED IRRLICHT_DLL) + install(FILES ${IRRLICHT_DLL} DESTINATION ${BINDIR}) + endif() + if(DEFINED ZLIB_DLL) + install(FILES ${ZLIB_DLL} DESTINATION ${BINDIR}) + endif() + endif() +endif(BUILD_CLIENT) + +if(BUILD_SERVER) + install(TARGETS minetestserver DESTINATION ${BINDIR}) +endif(BUILD_SERVER) + +# Subdirectories add_subdirectory(jthread) -#END +#end diff --git a/src/main.cpp b/src/main.cpp index 9ec49feb3..a0da103c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -212,7 +212,7 @@ Doing now: */
#define FIELD_OF_VIEW_TEST 0
-#ifdef UNITTEST_DISABLE
+#ifdef NDEBUG
#ifdef _WIN32
#pragma message ("Disabling unit tests")
#else
@@ -259,6 +259,7 @@ Doing now: #include "materials.h"
#include "guiMessageMenu.h"
#include "filesys.h"
+#include "config.h"
IrrlichtWrapper *g_irrlicht;
@@ -1110,6 +1111,12 @@ int main(int argc, char *argv[]) BEGIN_DEBUG_EXCEPTION_HANDLER
+ // Print startup message
+ dstream<<DTIME<<"minetest-c55"
+ " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
+ <<", "<<BUILD_INFO
+ <<std::endl;
+
try
{
@@ -1170,12 +1177,6 @@ int main(int argc, char *argv[]) // Initialize default settings
set_default_settings();
- // Print startup message
- dstream<<DTIME<<"minetest-c55"
- " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
- <<", ENABLE_TESTS="<<ENABLE_TESTS
- <<std::endl;
-
// Set locale. This is for forcing '.' as the decimal point.
std::locale::global(std::locale("C"));
// This enables printing all characters in bitmap font
@@ -1211,6 +1212,9 @@ int main(int argc, char *argv[]) {
core::array<std::string> filenames;
filenames.push_back(porting::path_userdata + "/minetest.conf");
+#ifdef RUN_IN_PLACE
+ filenames.push_back(porting::path_userdata + "/../minetest.conf");
+#endif
for(u32 i=0; i<filenames.size(); i++)
{
@@ -1282,6 +1286,8 @@ int main(int argc, char *argv[]) std::string map_dir = porting::path_userdata+"/map";
if(cmd_args.exists("map-dir"))
map_dir = cmd_args.get("map-dir");
+ else if(g_settings.exists("map-dir"))
+ map_dir = g_settings.get("map-dir");
if(cmd_args.getFlag("server"))
{
diff --git a/src/porting.cpp b/src/porting.cpp index bff865c53..6686a657e 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "porting.h" +#include "config.h" namespace porting { @@ -103,7 +104,9 @@ void initializePaths() path_userdata = std::string("../"); #endif -#else + +#else // RUN_IN_PLACE + /* Use platform-specific paths otherwise */ @@ -127,6 +130,7 @@ void initializePaths() // Use "./bin/../data" path_data = std::string(buf) + "/../data"; + //path_data = std::string(buf) + "/../share/" + APPNAME; // Use "C:\Documents and Settings\user\Application Data\<APPNAME>" len = GetEnvironmentVariable("APPDATA", buf, buflen); @@ -137,20 +141,23 @@ void initializePaths() Linux */ #elif defined(linux) + #include <unistd.h> - path_userdata = std::string("~/.") + APPNAME; - path_data = std::string("/usr/share/") + APPNAME; + path_userdata = std::string(getenv("HOME")) + "/." + APPNAME; + path_data = std::string(INSTALL_PREFIX) + "/share/" + APPNAME; /* OS X */ #elif defined(__APPLE__) + #include <unistd.h> - path_userdata = std::string("~/Library/Application Support/") + APPNAME; + path_userdata = std::string(getenv("HOME")) + "/Library/Application Support/" + APPNAME; path_data = std::string("minetest-mac.app/Contents/Resources/data/"); #endif -#endif + +#endif // RUN_IN_PLACE dstream<<"path_data = "<<path_data<<std::endl; dstream<<"path_userdata = "<<path_userdata<<std::endl; diff --git a/src/servermain.cpp b/src/servermain.cpp index d9b8af402..8fcefaae7 100644 --- a/src/servermain.cpp +++ b/src/servermain.cpp @@ -25,12 +25,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef SERVER #ifdef _WIN32 + #pragma error ("For a server build, SERVER must be defined globally") #else #error "For a server build, SERVER must be defined globally" #endif #endif -#ifdef UNITTEST_DISABLE +#ifdef NDEBUG #ifdef _WIN32 #pragma message ("Disabling unit tests") #else @@ -66,6 +67,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "strfnd.h" #include "porting.h" #include "materials.h" +#include "config.h" /* Settings. @@ -129,6 +131,12 @@ int main(int argc, char *argv[]) BEGIN_DEBUG_EXCEPTION_HANDLER + // Print startup message + dstream<<DTIME<<"minetest-c55" + " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST + <<", "<<BUILD_INFO + <<std::endl; + try { @@ -185,12 +193,6 @@ int main(int argc, char *argv[]) // Initialize default settings set_default_settings(); - // Print startup message - dstream<<DTIME<<"minetest-c55 server" - " with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST - <<", ENABLE_TESTS="<<ENABLE_TESTS - <<std::endl; - // Set locale. This is for forcing '.' as the decimal point. std::locale::global(std::locale("C")); // This enables printing all characters in bitmap font @@ -226,6 +228,9 @@ int main(int argc, char *argv[]) { core::array<std::string> filenames; filenames.push_back(porting::path_userdata + "/minetest.conf"); +#ifdef RUN_IN_PLACE + filenames.push_back(porting::path_userdata + "/../minetest.conf"); +#endif for(u32 i=0; i<filenames.size(); i++) { @@ -308,6 +313,8 @@ int main(int argc, char *argv[]) std::string map_dir = porting::path_userdata+"/map"; if(cmd_args.exists("map-dir")) map_dir = cmd_args.get("map-dir"); + else if(g_settings.exists("map-dir")) + map_dir = g_settings.get("map-dir"); Server server(map_dir.c_str(), hm_params, map_params); server.start(port); |