From 8b563f409e08645a3ec3644122acc870b536e0d8 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 27 Aug 2021 17:24:24 +0200 Subject: [PATCH] Modernize CMake build script also includes this fix: https://github.com/minetest/minetest/commit/a24899bf2dcd58916922d671ee8761448b6876e5 --- .gitignore | 10 +++++--- CMakeLists.txt | 70 ++++++++++++++++++++++++++------------------------ README.rst | 17 ++++++------ 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index da6ea97..4c8c9f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,14 @@ -colors.txt +*~ + minetestmapper minetestmapper.exe +colors.txt + CMakeCache.txt CMakeFiles/ -CPack* +CPack*.cmake +_CPack_Packages/ +install_manifest.txt Makefile cmake_install.cmake cmake_config.h -*~ diff --git a/CMakeLists.txt b/CMakeLists.txt index e21031b..67b0667 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,9 @@ cmake_minimum_required(VERSION 3.5) -project(minetestmapper CXX) - -set(VERSION_MAJOR 1) -set(VERSION_MINOR 0) -set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}") +project(minetestmapper + VERSION 1.0 + LANGUAGES CXX +) # Stuff & Paths @@ -13,18 +12,17 @@ if(NOT CMAKE_BUILD_TYPE) endif() set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -DNDEBUG") -set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g2 -Wall") +set(CMAKE_CXX_STANDARD_REQUIRED ON) if(WIN32) set(SHAREDIR ".") set(BINDIR ".") set(DOCDIR ".") else() - set(SHAREDIR "${CMAKE_INSTALL_PREFIX}/share/minetest") # reuse Minetest share dir - set(BINDIR "${CMAKE_INSTALL_PREFIX}/bin") - set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}") - set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man") + set(SHAREDIR "share/minetest") # reuse Minetest share dir + set(BINDIR "bin") + set(DOCDIR "share/doc/${PROJECT_NAME}") + set(MANDIR "share/man") endif() set(CUSTOM_SHAREDIR "" CACHE STRING "Directory to install data files into") @@ -77,7 +75,17 @@ option(ENABLE_POSTGRESQL "Enable PostgreSQL backend" TRUE) set(USE_POSTGRESQL FALSE) if(ENABLE_POSTGRESQL) - find_package("PostgreSQL") + if(CMAKE_VERSION VERSION_LESS "3.20") + find_package(PostgreSQL QUIET) + # Before CMake 3.20 FindPostgreSQL.cmake always looked for server includes + # but we don't need them, so continue anyway if only those are missing. + if(PostgreSQL_INCLUDE_DIR AND PostgreSQL_LIBRARY) + set(PostgreSQL_FOUND TRUE) + set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR}) + endif() + else() + find_package(PostgreSQL) + endif() if(PostgreSQL_FOUND) set(USE_POSTGRESQL TRUE) @@ -146,9 +154,18 @@ configure_file( "${PROJECT_SOURCE_DIR}/include/cmake_config.h.in" "${PROJECT_BINARY_DIR}/cmake_config.h" ) -add_definitions ( -DUSE_CMAKE_CONFIG_H ) +add_definitions(-DUSE_CMAKE_CONFIG_H) -set(mapper_SRCS +if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") + set(CMAKE_CXX_FLAGS_RELEASE "-O2") + set(CMAKE_CXX_FLAGS_DEBUG "-Og -g2") + add_compile_options(-Wall -pipe) +endif() +if(CMAKE_BUILD_TYPE STREQUAL "Release") + add_definitions(-DNDEBUG) +endif() + +add_executable(minetestmapper BlockDecoder.cpp PixelAttributes.cpp PlayerAttributes.cpp @@ -158,22 +175,9 @@ set(mapper_SRCS mapper.cpp util.cpp db-sqlite3.cpp -) - -if(USE_POSTGRESQL) - set(mapper_SRCS ${mapper_SRCS} db-postgresql.cpp) -endif(USE_POSTGRESQL) - -if(USE_LEVELDB) - set(mapper_SRCS ${mapper_SRCS} db-leveldb.cpp) -endif(USE_LEVELDB) - -if(USE_REDIS) - set(mapper_SRCS ${mapper_SRCS} db-redis.cpp) -endif(USE_REDIS) - -add_executable(minetestmapper - ${mapper_SRCS} + $<$:db-postgresql.cpp> + $<$:db-leveldb.cpp> + $<$:db-redis.cpp> ) target_link_libraries( @@ -198,16 +202,14 @@ if(UNIX) endif() set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Overview mapper for Minetest") -set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) -set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) set(CPACK_PACKAGE_VENDOR "celeron55") set(CPACK_PACKAGE_CONTACT "Perttu Ahola ") if(WIN32) - set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32") + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win32") set(CPACK_GENERATOR ZIP) else() - set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-linux") + set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-linux") set(CPACK_GENERATOR TGZ) set(CPACK_SOURCE_GENERATOR TGZ) endif() diff --git a/README.rst b/README.rst index 08d7d30..608d096 100644 --- a/README.rst +++ b/README.rst @@ -18,21 +18,22 @@ Requirements * hiredis (optional) * Postgres libraries (optional) -on Debian: -^^^^^^^^^^ +on Debian/Ubuntu: +^^^^^^^^^^^^^^^^^ - sudo apt install libgd-dev libsqlite3-dev libleveldb-dev libhiredis-dev libpq-dev +``sudo apt install libgd-dev libsqlite3-dev libleveldb-dev libhiredis-dev libpq-dev`` on openSUSE: ^^^^^^^^^^^^ - sudo zypper install gd-devel sqlite3-devel leveldb-devel hiredis-devel postgresql-devel postgresql-server-devel +``sudo zypper install gd-devel sqlite3-devel leveldb-devel hiredis-devel postgresql-devel`` -Windows -^^^^^^^ -Minetestmapper for Windows can be downloaded here: https://github.com/minetest/minetestmapper/releases +for Windows: +^^^^^^^^^^^^ +Minetestmapper for Windows can be downloaded `from the Releases section +`_. -After extracting the archive, minetestmapper can be invoked from cmd.exe: +After extracting the archive, it can be invoked from cmd.exe: :: cd C:\Users\yourname\Desktop\example\path