]> git.lizzy.rs Git - minetest.git/blobdiff - src/CMakeLists.txt
Defer searching for libintl to CMake
[minetest.git] / src / CMakeLists.txt
index 2de68a8f0855308cb0e00163fc023d9f134e1425..1f1e987f79566f2416b35e699c8e3116dfec080f 100644 (file)
@@ -136,6 +136,7 @@ if(ENABLE_POSTGRESQL)
                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)
@@ -291,16 +292,15 @@ else()
                endif(HAVE_LIBRT)
        endif(APPLE)
 
-       # Prefer local iconv if installed
        find_library(ICONV_LIBRARY iconv)
        mark_as_advanced(ICONV_LIBRARY)
        if (ICONV_LIBRARY)
                set(PLATFORM_LIBS ${PLATFORM_LIBS} ${ICONV_LIBRARY})
        endif()
+
        if (HAIKU)
-               set(PLATFORM_LIBS ${PLATFORM_LIBS} intl network)
+               set(PLATFORM_LIBS ${PLATFORM_LIBS} network)
        endif()
-
 endif()
 
 check_include_files(endian.h HAVE_ENDIAN_H)
@@ -330,6 +330,7 @@ add_subdirectory(mapgen)
 add_subdirectory(network)
 add_subdirectory(script)
 add_subdirectory(unittest)
+add_subdirectory(benchmark)
 add_subdirectory(util)
 add_subdirectory(irrlicht_changes)
 add_subdirectory(server)
@@ -412,6 +413,9 @@ if(BUILD_UNITTESTS)
        set(common_SRCS ${common_SRCS} ${UNITTEST_SRCS})
 endif()
 
+if(BUILD_BENCHMARKS)
+       set(common_SRCS ${common_SRCS} ${BENCHMARK_SRCS})
+endif()
 
 # This gives us the icon and file version information
 if(WIN32)
@@ -452,6 +456,10 @@ if(BUILD_UNITTESTS)
        set(client_SRCS ${client_SRCS} ${UNITTEST_CLIENT_SRCS})
 endif()
 
+if(BUILD_BENCHMARKS)
+       set(client_SRCS ${client_SRCS} ${BENCHMARK_CLIENT_SRCS})
+endif()
+
 list(SORT client_SRCS)
 
 # Server sources
@@ -567,6 +575,9 @@ if(BUILD_CLIENT)
        if (USE_SPATIAL)
                target_link_libraries(${PROJECT_NAME} ${SPATIAL_LIBRARY})
        endif()
+       if(BUILD_BENCHMARKS)
+               target_link_libraries(${PROJECT_NAME} catch2)
+       endif()
 endif(BUILD_CLIENT)
 
 
@@ -626,6 +637,9 @@ if(BUILD_SERVER)
                        ${CURL_LIBRARY}
                )
        endif()
+       if(BUILD_BENCHMARKS)
+               target_link_libraries(${PROJECT_NAME}server catch2)
+       endif()
 endif(BUILD_SERVER)
 
 # Blacklisted locales that don't work.
@@ -657,6 +671,40 @@ endif()
 # Set some optimizations and tweaks
 
 include(CheckCSourceCompiles)
+include(CheckSymbolExists)
+
+set(CMAKE_REQUIRED_INCLUDES ${LUA_INCLUDE_DIR})
+if(USE_LUAJIT)
+       set(CMAKE_REQUIRED_LIBRARIES ${LUA_LIBRARY})
+       # LuaJIT provides exactly zero ways to determine how recent it is (the version
+       # is unchanged since 2017), however it happens that string buffers were added
+       # after the changes which we care about so that works as an indicator.
+       # (https://github.com/LuaJIT/LuaJIT/commit/4c6b669 March 2021)
+       unset(HAVE_RECENT_LJ CACHE)
+       check_symbol_exists(luaopen_string_buffer "lualib.h" HAVE_RECENT_LJ)
+       if(NOT HAVE_RECENT_LJ)
+               string(CONCAT explanation_msg
+                       "You are using a relatively old version of LuaJIT. We recommend "
+                       "running a recent version (from git) as older ones are known not "
+                       "to build/work correctly in all cases.\n"
+                       "THIS APPLIES ESPECIALLY ON macOS OR Linux/aarch64!")
+               message(WARNING ${explanation_msg})
+       endif()
+else()
+       set(CMAKE_REQUIRED_LIBRARIES "")
+       unset(HAVE_ATCCALL CACHE)
+       # Note: we need to check the function without having the library
+       #       available for linking, so check_symbol_exists won't work.
+       check_c_source_compiles("#include <lua.h>\nint main(){return sizeof(lua_atccall);}" HAVE_ATCCALL)
+       if(NOT HAVE_ATCCALL)
+               string(CONCAT explanation_msg
+                       "It looks like you're trying to build Minetest using a system-wide "
+                       "Lua installation. This is no longer supported because PUC Lua "
+                       "cannot interoperate with C++ correctly. Read src/unittest/test_lua.cpp "
+                       " for technical details.")
+               message(FATAL_ERROR ${explanation_msg})
+       endif()
+endif()
 
 if(MSVC)
        # Visual Studio
@@ -693,34 +741,13 @@ if(MSVC)
        endif()
 else()
        # GCC or compatible compilers such as Clang
+       set(WARNING_FLAGS "-Wall -Wextra")
+       set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-unused-parameter -Wno-implicit-fallthrough")
        if(WARN_ALL)
-               set(RELEASE_WARNING_FLAGS "-Wall")
+               set(RELEASE_WARNING_FLAGS "${WARNING_FLAGS}")
        else()
                set(RELEASE_WARNING_FLAGS "")
        endif()
-       if(CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?Clang")
-               set(WARNING_FLAGS "${WARNING_FLAGS} -Wsign-compare")
-       endif()
-
-       if(APPLE AND USE_LUAJIT)
-               # required per http://luajit.org/install.html
-               SET(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -pagezero_size 10000 -image_base 100000000")
-       elseif(UNIX AND USE_LUAJIT)
-               check_c_source_compiles("#ifndef __aarch64__\n#error\n#endif\nint main(){}" IS_AARCH64)
-               if(IS_AARCH64)
-                       # Move text segment below LuaJIT's 47-bit limit (see issue #9367)
-                       if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
-                               # FreeBSD uses lld, and lld does not support -Ttext-segment, suggesting
-                               # --image-base instead. Not sure if it's equivalent change for the purpose 
-                               # but at least if fixes build on FreeBSD/aarch64
-                               # XXX: the condition should also be changed to check for lld regardless of
-                               # os, bit CMake doesn't have anything like CMAKE_LINKER_IS_LLD yet
-                               SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--image-base=0x200000000")
-                       else()
-                               SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Ttext-segment=0x200000000")
-                       endif()
-               endif()
-       endif()
 
        if(MINGW)
                set(OTHER_FLAGS "${OTHER_FLAGS} -mthreads -fexceptions")
@@ -729,8 +756,8 @@ else()
 
        # Use a safe subset of flags to speed up math calculations:
        # - we don't need errno or math exceptions
-       # - 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")
+       # - we don't deal with signed zero
+       set(MATH_FLAGS "-fno-math-errno -fno-trapping-math -fno-signed-zeros")
 
        # Enable SSE for floating point math on 32-bit x86 by default
        # reasoning see minetest issue #11810 and https://gcc.gnu.org/wiki/FloatingPointMath
@@ -742,7 +769,7 @@ else()
                endif()
        endif()
 
-       set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -Wall -pipe -funroll-loops")
+       set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${OTHER_FLAGS} -pipe -funroll-loops")
        if(CMAKE_SYSTEM_NAME MATCHES "(Darwin|BSD|DragonFly)")
                set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os")
        else()
@@ -755,9 +782,14 @@ else()
                        set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MATH_FLAGS}")
                endif()
        endif()
-       set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS}")
-       set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall ${WARNING_FLAGS} ${OTHER_FLAGS}")
+       set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -g")
+       set(CMAKE_CXX_FLAGS_SEMIDEBUG "-g -O1 ${WARNING_FLAGS} ${OTHER_FLAGS}")
+       set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 ${WARNING_FLAGS} ${OTHER_FLAGS}")
 
+       if(UNIX)
+               # enable assertions for libstdc++ or libc++
+               set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wp,-D_GLIBCXX_ASSERTIONS -Wp,-D_LIBCPP_ENABLE_ASSERTIONS=1")
+       endif()
        if(USE_GPROF)
                set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
        endif()
@@ -826,13 +858,14 @@ if(WIN32)
                if(LUA_DLL)
                        install(FILES ${LUA_DLL} DESTINATION ${BINDIR})
                endif()
-               if(BUILD_CLIENT AND IRRLICHT_DLL)
-                       install(FILES ${IRRLICHT_DLL} DESTINATION ${BINDIR})
-               endif()
                if(BUILD_CLIENT AND USE_GETTEXT AND GETTEXT_DLL)
                        install(FILES ${GETTEXT_DLL} DESTINATION ${BINDIR})
                endif()
        endif()
+
+       if(BUILD_CLIENT AND IRRLICHT_DLL)
+               install(FILES ${IRRLICHT_DLL} DESTINATION ${BINDIR})
+       endif()
 endif()
 
 if(BUILD_CLIENT)