diff --git a/protobuf-plugin/CMakeLists.txt b/protobuf-plugin/CMakeLists.txt index 52694a9c14e..237789be7be 100644 --- a/protobuf-plugin/CMakeLists.txt +++ b/protobuf-plugin/CMakeLists.txt @@ -2,30 +2,25 @@ # # Copyright © 2017 Trust Wallet. -cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) project(TrustWalletCoreProtobufPlugin) set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version" FORCE) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -if ("$ENV{PREFIX}" STREQUAL "") +if("$ENV{PREFIX}" STREQUAL "") set(PREFIX "${CMAKE_SOURCE_DIR}/../build/local") else() set(PREFIX "$ENV{PREFIX}") endif() -include_directories(${PREFIX}/include) -link_directories(${PREFIX}/lib) +find_package(Protobuf CONFIG REQUIRED PATH ${PREFIX}/lib/pkgconfig) -find_package(Protobuf REQUIRED PATH ${PREFIX}/lib/pkgconfig) -include_directories(${Protobuf_INCLUDE_DIRS}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) +add_executable(protoc-gen-c-typedef c_typedef.cc) +target_link_libraries(protoc-gen-c-typedef protobuf::libprotobuf protobuf::libprotoc) -add_executable(protoc-gen-c-typedef c_typedef.cc ${PROTO_SRCS} ${PROTO_HDRS}) -target_link_libraries(protoc-gen-c-typedef protobuf -lprotoc -pthread) - -add_executable(protoc-gen-swift-typealias swift_typealias.cc ${PROTO_SRCS} ${PROTO_HDRS}) -target_link_libraries(protoc-gen-swift-typealias protobuf -lprotoc -pthread) +add_executable(protoc-gen-swift-typealias swift_typealias.cc) +target_link_libraries(protoc-gen-swift-typealias protobuf::libprotobuf protobuf::libprotoc) install(TARGETS protoc-gen-c-typedef protoc-gen-swift-typealias DESTINATION bin) diff --git a/protobuf-plugin/c_typedef.cc b/protobuf-plugin/c_typedef.cc index 5197185f9ac..1352898cb73 100644 --- a/protobuf-plugin/c_typedef.cc +++ b/protobuf-plugin/c_typedef.cc @@ -14,7 +14,7 @@ class Generator : public compiler::CodeGenerator { return "TW" + proto_file.substr(0, index) + "Proto.h"; } - bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, string* error) const { + bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, std::string* error) const { std::unique_ptr output(generator_context->Open(GetOutputFilename(file->name()))); io::Printer printer(output.get(), '$'); diff --git a/protobuf-plugin/swift_typealias.cc b/protobuf-plugin/swift_typealias.cc index 40e84df0ee9..3d0983c2ca3 100644 --- a/protobuf-plugin/swift_typealias.cc +++ b/protobuf-plugin/swift_typealias.cc @@ -16,7 +16,7 @@ class Generator : public compiler::CodeGenerator { return proto_file.substr(0, index) + "+Proto.swift"; } - bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, string* error) const { + bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, std::string* error) const { std::unique_ptr output(generator_context->Open(GetOutputFilename(file->name()))); io::Printer printer(output.get(), '$'); diff --git a/tools/install-dependencies b/tools/install-dependencies index 3a04f8434bd..3ad3d77a54d 100755 --- a/tools/install-dependencies +++ b/tools/install-dependencies @@ -10,7 +10,10 @@ CMAKE=cmake MAKE=make # Load dependencies version -BASE_DIR=$(cd `dirname $0`; pwd) +BASE_DIR=$( + cd $(dirname $0) + pwd +) source ${BASE_DIR}/dependencies-version # Setup up folders @@ -50,28 +53,28 @@ function build_protobuf() { PROTOBUF_DIR="$ROOT/build/local/src/protobuf" cd ${PROTOBUF_DIR}/protobuf-$PROTOBUF_VERSION - ./configure --prefix="$PREFIX" - $MAKE -j4 - $MAKE install + $CMAKE -Scmake -B . -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MODULE_COMPATIBLE=ON + $CMAKE --build . -j + $CMAKE --install . --prefix $PREFIX # after install, cleanup to save space (docker) - make clean + $CMAKE --build . --target clean "$PREFIX/bin/protoc" --version # Protobuf plugins cd "$ROOT/protobuf-plugin" - $CMAKE -H. -Bbuild -DCMAKE_INSTALL_PREFIX=$PREFIX - $MAKE -Cbuild -j12 - $MAKE -Cbuild install - rm -rf build + $CMAKE . -Bbuild -DProtobuf_DIR=$PREFIX/lib/cmake/protobuf + $CMAKE --build build -j + $CMAKE --install build --prefix $PREFIX + $CMAKE --build build --target clean - if [[ -x "$(command -v swift)" && `uname` == "Darwin" ]]; then + if [[ -x "$(command -v swift)" && $(uname) == "Darwin" ]]; then build_swift_plugin fi } function build_swift_plugin() { - # Download Swift Protobuf sources + # Download Swift Protobuf sources SWIFT_PROTOBUF_DIR="$ROOT/build/local/src/swift-protobuf" mkdir -p "$SWIFT_PROTOBUF_DIR" cd "$SWIFT_PROTOBUF_DIR"