From cdbbac5b6d63a986d2da3be475197446238fb375 Mon Sep 17 00:00:00 2001 From: Desour Date: Sat, 25 Mar 2023 21:40:17 +0100 Subject: [PATCH] Move sha256.c to lib/ Precompiled headers don't work if we're not a pure C++ project. --- CMakeLists.txt | 1 + lib/sha256/CMakeLists.txt | 14 ++++++++++++++ lib/sha256/cmake_config.h.in | 5 +++++ {src/util => lib/sha256}/sha256.c | 8 ++------ {src/util => lib/sha256/sha256}/sha256.h | 0 src/CMakeLists.txt | 2 ++ src/script/lua_api/l_util.cpp | 4 ++-- src/util/CMakeLists.txt | 1 - src/util/srp.cpp | 2 +- 9 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 lib/sha256/CMakeLists.txt create mode 100644 lib/sha256/cmake_config.h.in rename {src/util => lib/sha256}/sha256.c (99%) rename {src/util => lib/sha256/sha256}/sha256.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c6c60ba9..2cd2e7336 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -277,6 +277,7 @@ find_package(Lua REQUIRED) if(NOT USE_LUAJIT) add_subdirectory(lib/bitop) endif() +add_subdirectory(lib/sha256) if(BUILD_UNITTESTS OR BUILD_BENCHMARKS) add_subdirectory(lib/catch2) diff --git a/lib/sha256/CMakeLists.txt b/lib/sha256/CMakeLists.txt new file mode 100644 index 000000000..555cb8ba9 --- /dev/null +++ b/lib/sha256/CMakeLists.txt @@ -0,0 +1,14 @@ +project(sha256 C) + +add_library(sha256 STATIC sha256.c) + +target_include_directories(sha256 INTERFACE .) + +INCLUDE(CheckIncludeFiles) +check_include_files(endian.h HAVE_ENDIAN_H) + +configure_file( + "${PROJECT_SOURCE_DIR}/cmake_config.h.in" + "${PROJECT_BINARY_DIR}/cmake_config.h" +) +target_include_directories(sha256 PRIVATE "${PROJECT_BINARY_DIR}") diff --git a/lib/sha256/cmake_config.h.in b/lib/sha256/cmake_config.h.in new file mode 100644 index 000000000..1ce07a107 --- /dev/null +++ b/lib/sha256/cmake_config.h.in @@ -0,0 +1,5 @@ +// Filled in by the build system + +#pragma once + +#cmakedefine HAVE_ENDIAN_H diff --git a/src/util/sha256.c b/lib/sha256/sha256.c similarity index 99% rename from src/util/sha256.c rename to lib/sha256/sha256.c index 2c1c6303f..56bdec098 100644 --- a/src/util/sha256.c +++ b/lib/sha256/sha256.c @@ -56,17 +56,13 @@ #include #include -#include "util/sha256.h" +#include "sha256/sha256.h" #if defined(_MSC_VER) && !defined(__clang__) && !defined(__attribute__) #define __attribute__(a) #endif -/* pull HAVE_ENDIAN_H from Minetest */ -#include "config.h" -#if !HAVE_ENDIAN_H -#undef HAVE_ENDIAN_H -#endif +#include "cmake_config.h" /* HAVE_ENDIAN_H */ /** endian.h **/ /* diff --git a/src/util/sha256.h b/lib/sha256/sha256/sha256.h similarity index 100% rename from src/util/sha256.h rename to lib/sha256/sha256/sha256.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ea544980..a37b02f87 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -565,6 +565,7 @@ if(BUILD_CLIENT) ${GMP_LIBRARY} ${JSON_LIBRARY} ${LUA_BIT_LIBRARY} + sha256 ${FREETYPE_LIBRARY} ${PLATFORM_LIBS} # on Android, Minetest depends on SDL2 directly @@ -637,6 +638,7 @@ if(BUILD_SERVER) ${JSON_LIBRARY} ${LUA_LIBRARY} ${LUA_BIT_LIBRARY} + sha256 ${GMP_LIBRARY} ${PLATFORM_LIBS} ) diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index f98eb0288..c868f949c 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -42,7 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "version.h" #include "util/hex.h" #include "util/sha1.h" -#include "util/sha256.h" +#include #include "util/png.h" #include @@ -573,7 +573,7 @@ int ModApiUtil::l_sha256(lua_State *L) auto data = readParam(L, 1); bool hex = !lua_isboolean(L, 2) || !readParam(L, 2); - + std::string data_sha256; data_sha256.resize(SHA256_DIGEST_LENGTH); SHA256(reinterpret_cast(data.data()), data.size(), diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 68e9eae5f..01b932c72 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -13,7 +13,6 @@ set(UTIL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/quicktune.cpp ${CMAKE_CURRENT_SOURCE_DIR}/serialize.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sha1.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/sha256.c ${CMAKE_CURRENT_SOURCE_DIR}/string.cpp ${CMAKE_CURRENT_SOURCE_DIR}/srp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/timetaker.cpp diff --git a/src/util/srp.cpp b/src/util/srp.cpp index a290c9995..ea64efca6 100644 --- a/src/util/srp.cpp +++ b/src/util/srp.cpp @@ -50,7 +50,7 @@ #include #endif -#include "util/sha256.h" +#include #include "srp.h" //#define CSRP_USE_SHA1