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 authored Oct 29, 2024
1 parent bdf9ab8 commit 75f0240
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 21,559 deletions.
18 changes: 11 additions & 7 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 @@ -122,10 +123,12 @@ if(ASAN_ENABLED)
log_option_enabled("asan")

if(MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC /fsanitize=address)
string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
target_compile_options(${PROJECT_NAME} PUBLIC /fsanitize=address)
target_link_options(${PROJECT_NAME} PUBLIC /fsanitize=address)
else()
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
endif()
else()
log_option_disabled("asan")
Expand Down Expand Up @@ -347,7 +350,6 @@ set(SOURCE_FILES
client/uiprogressrect.cpp
client/uisprite.cpp

protobuf/appearances.pb.cc
main.cpp
androidmain.cpp
)
Expand Down Expand Up @@ -448,9 +450,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 +488,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 +531,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 +579,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
40 changes: 23 additions & 17 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,32 @@ 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)
if (BUILD_STATIC_LIBRARY)
add_library(${PROJECT_NAME} STATIC ${ProtoFiles})
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
add_library(${PROJECT_NAME} ${ProtoFiles})
set_property(TARGET ${PROJECT_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
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

# 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

# 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
target_link_libraries(${PROJECT_NAME}
PUBLIC
protobuf::libprotobuf
)
target_compile_definitions(${PROJECT_NAME} PUBLIC _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

protobuf_generate(TARGET ${PROJECT_NAME} LANGUAGE cpp)
endif(PROTOBUF_FOUND)
Loading

0 comments on commit 75f0240

Please sign in to comment.