Skip to content

Commit

Permalink
improve: remove protobuf generated files
Browse files Browse the repository at this point in the history
Added files to be included directly from the "build" folder, instead of needing to be included in the project.

Improves protobuf dependencies and eliminates the need to have files generated by compilation in the repository.
  • Loading branch information
dudantas committed Oct 28, 2024
1 parent 9136550 commit 90c303e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 21,546 deletions.
10 changes: 6 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ endif()
if (TOGGLE_FRAMEWORK_NET)
set(FRAMEWORK_DEFINITIONS ${FRAMEWORK_DEFINITIONS} -DFRAMEWORK_NET)
endif()

if (TOGGLE_FRAMEWORK_EDITOR)
set(FRAMEWORK_DEFINITIONS ${FRAMEWORK_DEFINITIONS} -DFRAMEWORK_EDITOR)
endif()
Expand Down Expand Up @@ -347,7 +348,6 @@ set(SOURCE_FILES
client/uiprogressrect.cpp
client/uisprite.cpp

protobuf/appearances.pb.cc
main.cpp
androidmain.cpp
)
Expand Down Expand Up @@ -448,9 +448,11 @@ if(MSVC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
find_package(Vorbis REQUIRED)
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "")
else()
log_option_disabled("STATIC_LIBRARY")
target_compile_options(${PROJECT_NAME} PUBLIC /MP /FS /Zf /EHsc )
set(VCPKG_TARGET_TRIPLET "x64-windows" CACHE STRING "")
endif()

target_include_directories(${PROJECT_NAME}
Expand Down Expand Up @@ -484,7 +486,7 @@ if(MSVC)
${DBGHELP_LIBRARY}
${STDUUID}

protobuf::libprotobuf
protobuf::libprotobuf protobuf
absl::log_internal_check_op
Threads::Threads
GLEW::GLEW
Expand Down Expand Up @@ -527,7 +529,7 @@ elseif(ANDROID)
${STDUUID}
${MINIZIP_LIBRARY}

protobuf::libprotobuf
protobuf::libprotobuf protobuf
absl::log_internal_check_op
Threads::Threads
asio::asio
Expand Down Expand Up @@ -575,7 +577,7 @@ else() # Linux
${OPENSSL_CRYPTO_LIBRARY}
${HTTPLIB_LIBRARY}

protobuf::libprotobuf
protobuf::libprotobuf protobuf
absl::log_internal_check_op
Threads::Threads
X11::X11
Expand Down
2 changes: 1 addition & 1 deletion src/client/animator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <framework/core/declarations.h>
#include <framework/core/timer.h>

#include <protobuf/appearances.pb.h>
#include <appearances.pb.h>

using namespace otclient::protobuf;

Expand Down
2 changes: 1 addition & 1 deletion src/client/thingtypemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <client/spriteappearances.h>
#include <client/spritemanager.h>

#include "protobuf/appearances.pb.h"
#include <appearances.pb.h>

#include <nlohmann/json.hpp>

Expand Down
35 changes: 19 additions & 16 deletions src/protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if(APPLE)
endif(APPLE)

find_package(Protobuf REQUIRED)
find_package(Threads)

if(EXISTS ${PROTOBUF_PROTOC_EXECUTABLE})
message(STATUS "Found Protobuf Compiler: ${PROTOBUF_PROTOC_EXECUTABLE}")
Expand All @@ -16,27 +17,29 @@ else()
endif()

if(PROTOBUF_FOUND)

include_directories(${PROTOBUF_INCLUDE_DIRS})

protobuf_generate_cpp(ProtoSources ProtoHeaders appearances.proto)
file(GLOB ProtoFiles
"${CMAKE_CURRENT_SOURCE_DIR}/**/*.proto"
"${CMAKE_CURRENT_SOURCE_DIR}/*.proto"
)

if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/appearances.pb.cc OR NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/appearances.pb.h)
message(FATAL_ERROR, "Failed to generate protobuf files")
if (MSVC AND BUILD_STATIC_LIBRARY)
add_library(${PROJECT_NAME} STATIC ${ProtoFiles})
else()
add_library(${PROJECT_NAME} ${ProtoFiles})
endif()

add_library(${PROJECT_NAME} STATIC ${ProtoSources} ${ProtoHeaders})
target_link_libraries(${PROJECT_NAME} ${PROTOBUF_LIBRARY})

add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
target_link_libraries(${PROJECT_NAME}
PUBLIC
protobuf::libprotobuf
)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

# Copy files "appearances.pb.cc" to the "src/protobuf" folder
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/appearances.pb.cc
${CMAKE_CURRENT_SOURCE_DIR}/appearances.pb.cc
if (MSVC AND BUILD_STATIC_LIBRARY)
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

# Copy files "appearances.pb.h" to the "src/protobuf" folder
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/appearances.pb.h
${CMAKE_CURRENT_SOURCE_DIR}/appearances.pb.h
)
protobuf_generate(TARGET ${PROJECT_NAME} LANGUAGE cpp)
endif(PROTOBUF_FOUND)
Loading

0 comments on commit 90c303e

Please sign in to comment.