diff --git a/CMakeLists.txt b/CMakeLists.txt index 64cdb05c9..5ffafb042 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 2.6) cmake_policy(SET CMP0025 OLD) @@ -6,11 +6,45 @@ cmake_policy(SET CMP0025 OLD) project(multicraft) set(PROJECT_NAME_CAPITALIZED "MultiCraft") -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED TRUE) -set(GCC_MINIMUM_VERSION "5.1") -set(CLANG_MINIMUM_VERSION "3.5") - +# check compatible compileer must be after project definition and set flags, assume if C++ is installed also CC is installed +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + endif() + if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") + elseif (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.6) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu1x") + else() + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") + endif() + message(STATUS "using gnu compiler") +elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1y") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + endif() + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") + endif() + message(STATUS "using clang compiler") +else() + if (CMAKE_VERSION VERSION_GREATER 3.0) + set(CMAKE_C_STANDARD 11) + set(CMAKE_CXX_STANDARD 11) + else() + if(APPLE) + # Fix behavior of CMAKE_CXX_STANDARD when targeting macOS. + if (POLICY CMP0025) + cmake_policy(SET CMP0025 NEW) + endif () + endif () + endif() + message(STATUS "using default installed compiler") +endif() # Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing set(VERSION_MAJOR 2) set(VERSION_MINOR 0) @@ -25,7 +59,7 @@ set(ENABLE_UPDATE_CHECKER (NOT ${DEVELOPMENT_BUILD}) CACHE BOOL set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") if(VERSION_EXTRA) - set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA}) + set(VERSION_STRING "${VERSION_STRING}-${VERSION_EXTRA}") elseif(DEVELOPMENT_BUILD) set(VERSION_STRING "${VERSION_STRING}-dev") endif() @@ -189,10 +223,11 @@ install(FILES "doc/world_format.txt" DESTINATION "${DOCDIR}" COMPONENT "Docs") install(FILES "multicraft.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}") if(UNIX AND NOT APPLE) - install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6") - install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}") - install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}") - install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps") + install(FILES "doc/minetest.6" DESTINATION "${MANDIR}/man6 RENAME "${PROJECT_NAME}.6") + install(FILES "doc/minetestserver.6" DESTINATION "${MANDIR}/man6 RENAME "${PROJECT_NAME}server.6") + install(FILES "misc/net.minetest.minetest.desktop" DESTINATION "${XDG_APPS_DIR}" RENAME "net.minetest.${PROJECT_NAME}.desktop") + install(FILES "misc/net.minetest.minetest.appdata.xml" DESTINATION "${APPDATADIR}" RENAME "net.minetest.${PROJECT_NAME}.appdata.xml") + install(FILES "misc/minetest.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps" RENAME "multicraft.svg") install(FILES "misc/multicraft-xorg-icon-128.png" DESTINATION "${ICONDIR}/hicolor/128x128/apps" RENAME "multicraft.png") diff --git a/cmake/Modules/FindJson.cmake b/cmake/Modules/FindJson.cmake index a5e9098f8..9d1c8c3b1 100644 --- a/cmake/Modules/FindJson.cmake +++ b/cmake/Modules/FindJson.cmake @@ -8,7 +8,11 @@ option(ENABLE_SYSTEM_JSONCPP "Enable using a system-wide JSONCPP. May cause seg if(ENABLE_SYSTEM_JSONCPP) find_library(JSON_LIBRARY NAMES jsoncpp) - find_path(JSON_INCLUDE_DIR json/allocator.h PATH_SUFFIXES jsoncpp) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5) + find_path(JSON_INCLUDE_DIR json/features.h PATH_SUFFIXES jsoncpp) + else() + find_path(JSON_INCLUDE_DIR json/allocator.h PATH_SUFFIXES jsoncpp) + endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Json DEFAULT_MSG JSON_LIBRARY JSON_INCLUDE_DIR) diff --git a/lib/lua/CMakeLists.txt b/lib/lua/CMakeLists.txt index 5d0dc0f70..9a3550b33 100644 --- a/lib/lua/CMakeLists.txt +++ b/lib/lua/CMakeLists.txt @@ -63,6 +63,45 @@ if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2 -g") endif(CMAKE_COMPILER_IS_GNUCC) +# check compatible compileer must be after project definition and set flags, assume if C++ is installed also CC is installed +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + endif() + if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") + elseif (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.6) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu1x") + else() + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") + endif() + message(STATUS "using gnu compiler") +elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1y") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + endif() + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") + endif() + message(STATUS "using clang compiler") +else() + if (CMAKE_VERSION VERSION_GREATER 3.0) + set(CMAKE_C_STANDARD 11) + set(CMAKE_CXX_STANDARD 11) + else() + if(APPLE) + # Fix behavior of CMAKE_CXX_STANDARD when targeting macOS. + if (POLICY CMP0025) + cmake_policy(SET CMP0025 NEW) + endif () + endif () + endif() + message(STATUS "using default installed compiler") +endif() add_subdirectory(src build) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24ff14c88..1be05a8be 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -169,7 +169,18 @@ 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}) + set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY}) + endif() + else() + find_package(PostgreSQL) + endif() if(PostgreSQL_FOUND) set(USE_POSTGRESQL TRUE) @@ -733,11 +744,13 @@ option(APPLY_LOCALE_BLACKLIST "Use a blacklist to avoid broken locales" TRUE) if (GETTEXTLIB_FOUND AND APPLY_LOCALE_BLACKLIST) set(GETTEXT_USED_LOCALES "") foreach(LOCALE ${GETTEXT_AVAILABLE_LOCALES}) - if (NOT "${LOCALE}" IN_LIST GETTEXT_BLACKLISTED_LOCALES) + if (NOT ";${GETTEXT_BLACKLISTED_LOCALES};" MATCHES ";${LOCALE};") list(APPEND GETTEXT_USED_LOCALES ${LOCALE}) endif() endforeach() message(STATUS "Locale blacklist applied; Locales used: ${GETTEXT_USED_LOCALES}") +elseif (GETTEXTLIB_FOUND) + set(GETTEXT_USED_LOCALES ${GETTEXT_AVAILABLE_LOCALES}) endif() # Set some optimizations and tweaks @@ -784,6 +797,47 @@ else() else() set(RELEASE_WARNING_FLAGS "") endif() + + # check compatible compileer must be after project definition and set flags, assume if C++ is installed also CC is installed + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + endif() + if (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") + elseif (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.6) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu1x") + else() + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") + endif() + message(STATUS "using gnu compiler") + elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1y") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + endif() + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.5) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") + endif() + message(STATUS "using clang compiler") + else() + if (CMAKE_VERSION VERSION_GREATER 3.0) + set(CMAKE_C_STANDARD 11) + set(CMAKE_CXX_STANDARD 11) + else() + if(APPLE) + # Fix behavior of CMAKE_CXX_STANDARD when targeting macOS. + if (POLICY CMP0025) + cmake_policy(SET CMP0025 NEW) + endif () + endif () + endif() + message(STATUS "using default installed compiler") + endif() + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(WARNING_FLAGS "${WARNING_FLAGS} -Wsign-compare") endif() @@ -809,6 +863,21 @@ else() # - we don't deal with Inf/NaN or signed zero set(MATH_FLAGS "-fno-math-errno -fno-trapping-math -ffinite-math-only -fno-signed-zeros") + # only related to moder x86 32bit platforms using gcc compilers + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.7) + # Enable SSE for floating point math on 32-bit x86 by default + # reasoning see minetest issue #11810 and https://gcc.gnu.org/wiki/FloatingPointMath + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + check_c_source_compiles("#ifndef __i686__\n#error\n#endif\nint main(){}" IS_I686) + if(IS_I686) + message(STATUS "Detected Intel x86: using SSE instead of x87 FPU") + set(OTHER_FLAGS "${OTHER_FLAGS} -mfpmath=sse -msse") + endif() + endif() + endif() + endif() + set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -Wall -pipe -funroll-loops") if(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os") @@ -822,8 +891,13 @@ else() set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MATH_FLAGS}") endif() endif(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)") - set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS} $ENV{CPPFLAGS}") + set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS} $ENV{CPPFLAGS}") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS}") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS} $ENV{CFLAGS} ") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS} -g") + set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} ${CMAKE_C_FLAGS} -O1 -g") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} ${CMAKE_C_FLAGS} $ENV{CFLAGS} -g") if(USE_GPROF) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") @@ -912,7 +986,7 @@ if(BUILD_CLIENT) if(USE_GETTEXT) foreach(LOCALE ${GETTEXT_USED_LOCALES}) set_mo_paths(MO_BUILD_PATH MO_DEST_PATH ${LOCALE}) - set(MO_BUILD_PATH "${MO_BUILD_PATH}/minetest.mo") + set(MO_BUILD_PATH "${MO_BUILD_PATH}/${PROJECT_NAME}.mo") install(FILES ${MO_BUILD_PATH} DESTINATION ${MO_DEST_PATH}) endforeach() endif() @@ -952,7 +1026,7 @@ if (USE_GETTEXT) foreach(LOCALE ${GETTEXT_USED_LOCALES}) set(PO_FILE_PATH "${GETTEXT_PO_PATH}/${LOCALE}/minetest.po") set_mo_paths(MO_BUILD_PATH MO_DEST_PATH ${LOCALE}) - set(MO_FILE_PATH "${MO_BUILD_PATH}/minetest.mo") + set(MO_FILE_PATH "${MO_BUILD_PATH}/${PROJECT_NAME}.mo") add_custom_command(OUTPUT ${MO_BUILD_PATH} COMMAND ${CMAKE_COMMAND} -E make_directory ${MO_BUILD_PATH}