From 8e2cdf6c8bf4deca7bbc208a90b8a3c0165ec384 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 7 Oct 2019 15:51:30 -0700 Subject: [PATCH 1/2] chore: move packages out of source --- .appveyor | 9 +- .appveyor.yml | 9 +- .github/workflows/test.yml | 66 +++++---- .github/workflows/test/clang_format.sh | 2 +- .github/workflows/test/install_platform_io.sh | 7 - .github/workflows/test/script_desktop.sh | 15 -- .github/workflows/test/script_platform_io.sh | 7 - .gitignore | 20 +-- .gitmodules | 6 - CHANGELOG.md | 3 + CMakeLists.txt | 88 ++++++----- build.cmd | 3 + build.sh | 1 + cmake/External.cmake | 48 ++++++ cmake/GTest.cmake | 33 +++++ cmake/extern/CURL.txt.in | 21 +++ cmake/extern/GTest.txt.in | 21 +++ docs/INSTALL_PLATFORMIO.md | 2 +- docs/cpp.md | 8 +- examples/cmake_example/CMakeLists.txt | 12 +- platformio.ini | 5 +- run_tests.cmd | 13 +- run_tests.sh | 12 +- src/CMakeLists.txt | 140 ++++++++++-------- src/lib/curl | 1 - test/CMakeLists.txt | 125 ++++++++++------ test/lib/googletest | 1 - test/platformio.ini | 10 +- 28 files changed, 428 insertions(+), 260 deletions(-) delete mode 100644 .github/workflows/test/install_platform_io.sh delete mode 100644 .github/workflows/test/script_desktop.sh delete mode 100644 .github/workflows/test/script_platform_io.sh delete mode 100644 .gitmodules create mode 100644 cmake/External.cmake create mode 100644 cmake/GTest.cmake create mode 100644 cmake/extern/CURL.txt.in create mode 100644 cmake/extern/GTest.txt.in delete mode 160000 src/lib/curl delete mode 160000 test/lib/googletest diff --git a/.appveyor b/.appveyor index d92e4739..7c88bb0c 100644 --- a/.appveyor +++ b/.appveyor @@ -6,15 +6,12 @@ environment: matrix: - CONFIGURATION: Debug - CONFIGURATION: Release - -install: - - git submodule update --init --recursive before_build: - - cmake -G "Visual Studio 15 2017 Win64" . + - cmake -D UNIT_TEST=ON -G "Visual Studio 15 2017 Win64" . build: - project: $(APPVEYOR_BUILD_FOLDER)\Ark-Cpp-Client.sln + project: $(APPVEYOR_BUILD_FOLDER)\ark_cpp_client.sln test_script: -- cmd: '%APPVEYOR_BUILD_FOLDER%\Bin\%CONFIGURATION%\Ark-Cpp-Client-tests.exe' +- cmd: '%APPVEYOR_BUILD_FOLDER%\Bin\%CONFIGURATION%\ark_cpp_client.exe' diff --git a/.appveyor.yml b/.appveyor.yml index 8fe3ab76..966eca37 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -6,15 +6,12 @@ environment: matrix: - CONFIGURATION: Debug - CONFIGURATION: Release - -install: - - git submodule update --init --recursive before_build: - - cmake -G "Visual Studio 15 2017 Win64" . + - cmake -D UNIT_TEST=ON -G "Visual Studio 15 2017 Win64" . build: - project: $(APPVEYOR_BUILD_FOLDER)\Ark-Cpp-Client.sln + project: $(APPVEYOR_BUILD_FOLDER)\ark_cpp_client.sln test_script: -- cmd: '%APPVEYOR_BUILD_FOLDER%\test\%CONFIGURATION%\Ark-Cpp-Client-tests.exe' +- cmd: '%APPVEYOR_BUILD_FOLDER%\test\%CONFIGURATION%\ark_cpp_client_tests.exe' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d01fd6cf..865127e3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,46 +9,49 @@ on: types: [ready_for_review, synchronize, opened] jobs: - arduino-default: + arduino: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: Make scripts executable run: sudo chmod -R +x ./.github/workflows/test/*.sh - - name: Install + - name: Install Dependencies run: ./.github/workflows/test/install_arduino.sh - - name: Build + - name: Build Arduino Sketch run: ./.github/workflows/test/script_arduino.sh - linux-default: + platformio: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Make scripts executable - run: sudo chmod -R +x ./.github/workflows/test/*.sh - - name: Install - run: ./.github/workflows/test/install_platform_io.sh + - name: Install Dependencies + run: | + sudo pip install -U platformio + platformio update - name: Build - run: ./.github/workflows/test/script_platform_io.sh + run: | + platformio run + platformio run -d ./test + linux-gcc7: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Install dependencies + - name: Install Dependencies run: | sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get -y install g++-7 lcov cmake openssl - - name: Make scripts executable - run: sudo chmod -R +x ./.github/workflows/test/*.sh - name: Build - run: ./.github/workflows/test/script_desktop.sh - env: - CC: gcc-7 - CXX: g++-7 + run: | + mkdir build && cd build + cmake -DCMAKE_BUILD_TYPE=Coverage -DUNIT_TEST=ON .. + cmake --build . + - name: Run Tests + run: ./build/test/ark_cpp_client_tests - name: Codecov upload run: bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} @@ -57,27 +60,23 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Install dependencies + - name: Install Dependencies run: | sudo apt-get update sudo apt-get -y install clang-5.0 clang-format-5.0 clang-tidy-5.0 lcov cmake openssl - name: Make scripts executable run: sudo chmod -R +x ./.github/workflows/test/*.sh - name: Build - run: ./.github/workflows/test/script_desktop.sh - env: - CC: clang-5.0 - CXX: clang++-5.0 + run: | + mkdir build && cd build + cmake -DUNIT_TEST=ON .. + cmake --build . + - name: Run Tests + run: ./build/test/ark_cpp_client_tests - name: Clang Tidy run: ./.github/workflows/test/clang_tidy.sh - env: - CC: clang-5.0 - CXX: clang++-5.0 - name: Clang Format run: ./.github/workflows/test/clang_format.sh - env: - CC: clang-5.0 - CXX: clang++-5.0 macos: runs-on: macOS-latest @@ -85,9 +84,12 @@ jobs: steps: - uses: actions/checkout@v1 - run: COMPILER=clang++ - - name: Install dependencies - run: brew install cmake lcov - - name: Make scripts executable - run: sudo chmod -R +x ./.github/workflows/test/*.sh + - name: Install Dependencies + run: brew install cmake - name: Build - run: ./.github/workflows/test/script_desktop.sh + run: | + mkdir build && cd build + cmake -DUNIT_TEST=ON .. + cmake --build . + - name: Run Tests + run: ./build/test/ark_cpp_client_tests diff --git a/.github/workflows/test/clang_format.sh b/.github/workflows/test/clang_format.sh index 19c7f38c..d75cab85 100644 --- a/.github/workflows/test/clang_format.sh +++ b/.github/workflows/test/clang_format.sh @@ -1,6 +1,6 @@ #!/bin/bash -ex -grep -nr '\s$' src test examples .gitignore .gitmodules 2>&1 > /dev/null +grep -nr '\s$' src test .gitignore 2>&1 > /dev/null if $?; then echo Trailing whitespace found, aborting exit 1 diff --git a/.github/workflows/test/install_platform_io.sh b/.github/workflows/test/install_platform_io.sh deleted file mode 100644 index 3aee5870..00000000 --- a/.github/workflows/test/install_platform_io.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -# install PlatformIO -sudo pip install -U platformio - -# update PlatformIO -platformio update diff --git a/.github/workflows/test/script_desktop.sh b/.github/workflows/test/script_desktop.sh deleted file mode 100644 index a30cfed8..00000000 --- a/.github/workflows/test/script_desktop.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# run desktop builds -mkdir build -cd build -cmake .. -DCMAKE_BUILD_TYPE=Coverage -DBUILD_TESTING=OFF -cmake --build . - -# build examples -cd ../examples/cmake_example -./build.sh - -# run Gtest -cd ../../build -./test/Ark-Cpp-Client-tests diff --git a/.github/workflows/test/script_platform_io.sh b/.github/workflows/test/script_platform_io.sh deleted file mode 100644 index 80e5f3e0..00000000 --- a/.github/workflows/test/script_platform_io.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -# run PlatformIO builds -platformio run - -# run PlatformIO unit tests -platformio run -d ./test diff --git a/.gitignore b/.gitignore index 800d0673..ea7068b2 100644 --- a/.gitignore +++ b/.gitignore @@ -23,9 +23,9 @@ build /test/.vscode /test/lib/readme.txt .DS_Store -/src/Ark-Cpp-Client-lib.vcxproj.filters -/src/Ark-Cpp-Client-lib.vcxproj -/src/Ark-Cpp-Client-lib.sln +/src/ark_cpp_client.vcxproj.filters +/src/ark_cpp_client.vcxproj +/src/ark_cpp_client.sln /src/ALL_BUILD.vcxproj.filters /src/ALL_BUILD.vcxproj /Win32 @@ -37,15 +37,15 @@ build /test/Experimental.vcxproj /test/Continuous.vcxproj.filters /test/Continuous.vcxproj -/test/Ark-Cpp-Client-tests.vcxproj.filters -/test/Ark-Cpp-Client-tests.vcxproj -/test/Ark-Cpp-Client-tests.sln +/test/ark_cpp_client_tests.vcxproj.filters +/test/ark_cpp_client_tests.vcxproj +/test/Aark_cpp_client_tests.sln /test/ALL_BUILD.vcxproj.filters /test/ALL_BUILD.vcxproj /_3rdParty /ZERO_CHECK.vcxproj.filters /ZERO_CHECK.vcxproj -/Ark-Cpp-Client.sln +/ark_cpp_client.sln /ALL_BUILD.vcxproj.filters /ALL_BUILD.vcxproj /src/Win32 @@ -53,9 +53,9 @@ build /examples/cmake_example/bin /examples/cmake_example/ZERO_CHECK.vcxproj.filters /examples/cmake_example/ZERO_CHECK.vcxproj -/examples/cmake_example/Cpp-Client-Example.vcxproj.filters -/examples/cmake_example/Cpp-Client-Example.vcxproj -/examples/cmake_example/Cpp-Client-Example.sln +/examples/cmake_example/ark_cpp_client_example.vcxproj.filters +/examples/cmake_example/ark_cpp_client_example.vcxproj +/examples/cmake_example/ark_cpp_client_example.sln /examples/cmake_example/ALL_BUILD.vcxproj.filters /examples/cmake_example/ALL_BUILD.vcxproj /examples/cmake_example/Win32 diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 84dab8ab..00000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "test/lib/googletest"] - path = test/lib/googletest - url = https://github.com/google/googletest.git -[submodule "src/lib/curl"] - path = src/lib/curl - url = https://github.com/curl/curl diff --git a/CHANGELOG.md b/CHANGELOG.md index 158c1951..6bd0279d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] + ### Added - added Blockchain API endpoint ([#104]) @@ -15,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - improved formatting and maintainability ([#92]) - dropped Hunter Package Manager in favor of git submodules in OS builds ([#90]) - updated ArduinoJson 5.13.2 >> 6.10.1, usage patterns, and documentation/examples ([#87]) +- moved external libraries out of source tree ([#140]) ### Fixed - fixed typos in Arduino examples ([#86]) @@ -68,4 +70,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. [#93]: https://github.com/ArkEcosystem/cpp-client/pull/93 [#104]: https://github.com/ArkEcosystem/cpp-client/pull/104 [#114]: https://github.com/ArkEcosystem/cpp-client/pull/114 +[#140]: https://github.com/ArkEcosystem/cpp-client/pull/140 [unreleased]: https://github.com/ArkEcosystem/cpp-client/compare/1.2.0...develop diff --git a/CMakeLists.txt b/CMakeLists.txt index d8f70caa..cdd7d5ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,34 +1,33 @@ -cmake_minimum_required(VERSION 3.2.2) -set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain.cmake") +cmake_minimum_required(VERSION 3.2) -project(Ark-Cpp-Client) +project(ark_cpp_client) + +# ------------------------------------------------------------------------------ +# Set the Environment Variables +# ------------------------------------------------------------------------------ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) +set(EXTERNAL_LIBRARY_DIR ${PROJECT_SOURCE_DIR}/extern) set(BUILD_SHARED_LIBS OFF) if (MSVC) - add_definitions( - -D_CRT_SECURE_NO_WARNINGS - -D_SCL_SECURE_NO_WARNINGS - -DNOMINMAX - ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") + add_definitions(-D_CRT_SECURE_NO_WARNINGS + -D_SCL_SECURE_NO_WARNINGS + -DNOMINMAX) + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") else() - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g") endif() -# clone submodules -execute_process( - COMMAND git submodule update --init --recursive - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -) +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ # Clang Tidy @@ -36,33 +35,50 @@ execute_process( if(ENABLE_CLANG_TIDY) - find_program(CLANG_TIDY_BIN clang-tidy-6.0) - find_program(RUN_CLANG_TIDY_BIN run-clang-tidy-6.0.py) + find_program(CLANG_TIDY_BIN clang-tidy-6.0) + find_program(RUN_CLANG_TIDY_BIN run-clang-tidy-6.0.py) - if(CLANG_TIDY_BIN STREQUAL "CLANG_TIDY_BIN-NOTFOUND") - message(FATAL_ERROR "unable to locate clang-tidy-5.0") - endif() + if(CLANG_TIDY_BIN STREQUAL "CLANG_TIDY_BIN-NOTFOUND") + message(FATAL_ERROR "unable to locate clang-tidy-5.0") + endif() - if(RUN_CLANG_TIDY_BIN STREQUAL "RUN_CLANG_TIDY_BIN-NOTFOUND") - message(FATAL_ERROR "unable to locate run-clang-tidy-5.0.py") - endif() + if(RUN_CLANG_TIDY_BIN STREQUAL "RUN_CLANG_TIDY_BIN-NOTFOUND") + message(FATAL_ERROR "unable to locate run-clang-tidy-5.0.py") + endif() - list(APPEND RUN_CLANG_TIDY_BIN_ARGS - -clang-tidy-binary ${CLANG_TIDY_BIN} - "\"-header-filter=.*\\b(src|test|examples)\\b\\/(?!lib).*\"" #Only run clang tidy on src, test, examples and skip 3rd party libraries - -checks=clan*,cert*,misc*,perf*,cppc*,read*,mode*,-cert-err58-cpp,-misc-noexcept-move-constructor,-cppcoreguidelines-* - ) + list(APPEND RUN_CLANG_TIDY_BIN_ARGS + -clang-tidy-binary ${CLANG_TIDY_BIN} + "\"-header-filter=.*\\b(src|test|examples)\\b\\/(?!lib).*\"" #Only run clang tidy on src, test, examples and skip 3rd party libraries + -checks=clan*,cert*,misc*,perf*,cppc*,read*,mode*,-cert-err58-cpp,-misc-noexcept-move-constructor,-cppcoreguidelines-*) - add_custom_target( - tidy - COMMAND ${RUN_CLANG_TIDY_BIN} ${RUN_CLANG_TIDY_BIN_ARGS} - COMMENT "running clang tidy" - ) + add_custom_target(tidy + COMMAND ${RUN_CLANG_TIDY_BIN} ${RUN_CLANG_TIDY_BIN_ARGS} + COMMENT "running clang tidy") endif() # ------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ +# Add the ARK C++ Client Library Subdirectory +# ------------------------------------------------------------------------------ + add_subdirectory(src) -add_subdirectory(test) +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# Add the ARK C++ Client Test Subdirectory +# +# Disabled by default. +# +# Use `cmake -DUNIT_TEST=ON ..` to enable Test building. +# ------------------------------------------------------------------------------ + +option(UNIT_TEST "Tests disabled by default" OFF) + +if(UNIT_TEST) + add_subdirectory(test) +endif() + +# ------------------------------------------------------------------------------ diff --git a/build.cmd b/build.cmd index c11f29f2..d71edd00 100644 --- a/build.cmd +++ b/build.cmd @@ -1,6 +1,9 @@ + rmdir /S /Q build mkdir build cd build + cmake .. cmake --build . + cd .. diff --git a/build.sh b/build.sh index a29521ca..69c55a93 100755 --- a/build.sh +++ b/build.sh @@ -3,5 +3,6 @@ rm -dfr build mkdir build cd build + cmake .. cmake --build . diff --git a/cmake/External.cmake b/cmake/External.cmake new file mode 100644 index 00000000..d513efc2 --- /dev/null +++ b/cmake/External.cmake @@ -0,0 +1,48 @@ + +# ------------------------------------------------------------------------------ +# CURL +# ------------------------------------------------------------------------------ + +set(BUILD_TESTING OFF) +set(HTTP_ONLY ON) +set(CURL_STATICLIB YES) +set(CURL_STATIC_CRT ON) +option(CMAKE_USE_LIBSSH2 OFF) +option(BUILD_CURL_EXE OFF) + +if (APPLE) + set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl/lib") + set(OPENSSL_INCLUDE_DIR "/usr/local/opt/openssl/include") +endif() + +# Set the configuration +configure_file(${CMAKE_SOURCE_DIR}/cmake/extern/CURL.txt.in + ${EXTERNAL_LIBRARY_DIR}/curl/CMakeLists.txt) + +# Execute Git Clone and run Cmake +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${EXTERNAL_LIBRARY_DIR}/curl) + +if(result) + message(FATAL_ERROR "cURL: CMake Failed: ${result}") +endif() + +# Build the Cloned Repo +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${EXTERNAL_LIBRARY_DIR}/curl) + +if(result) + message(FATAL_ERROR "cURL: Build Failed: ${result}") +endif() + +add_subdirectory("${EXTERNAL_LIBRARY_DIR}/curl/src" + "${EXTERNAL_LIBRARY_DIR}/curl/build" + EXCLUDE_FROM_ALL) + +set(CURL_INCLUDE_DIR + ${EXTERNAL_LIBRARY_DIR}/curl/src/include + CACHE INTERNAL "cURL: Include Folder Path") + +# ------------------------------------------------------------------------------ diff --git a/cmake/GTest.cmake b/cmake/GTest.cmake new file mode 100644 index 00000000..b30c64e4 --- /dev/null +++ b/cmake/GTest.cmake @@ -0,0 +1,33 @@ + +# ------------------------------------------------------------------------------ +# Google Test +# ------------------------------------------------------------------------------ + +configure_file(${CMAKE_SOURCE_DIR}/cmake/extern/GTest.txt.in + ${EXTERNAL_LIBRARY_DIR}/googletest/CMakeLists.txt) + +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${EXTERNAL_LIBRARY_DIR}/googletest) + +if(result) + message(FATAL_ERROR "CMake step for GTest failed: ${result}") +endif() + +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${EXTERNAL_LIBRARY_DIR}/googletest) + +if(result) + message(FATAL_ERROR "Build step for GTest failed: ${result}") +endif() + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +add_subdirectory("${EXTERNAL_LIBRARY_DIR}/googletest/src" + "${EXTERNAL_LIBRARY_DIR}/googletest/build" + EXCLUDE_FROM_ALL) + +include_directories(${EXTERNAL_LIBRARY_DIR}/googletest/src/googlemock/include) + +# ------------------------------------------------------------------------------ diff --git a/cmake/extern/CURL.txt.in b/cmake/extern/CURL.txt.in new file mode 100644 index 00000000..b03d6f9a --- /dev/null +++ b/cmake/extern/CURL.txt.in @@ -0,0 +1,21 @@ + +cmake_minimum_required(VERSION 3.2) + +include(ExternalProject) + +# ------------------------------------------------------------------------------ +# CURL +# ------------------------------------------------------------------------------ + +ExternalProject_Add(CURL + GIT_REPOSITORY https://github.com/curl/curl + GIT_TAG curl-7_66_0 + SOURCE_DIR "${EXTERNAL_LIBRARY_DIR}/curl/src" + BINARY_DIR "${EXTERNAL_LIBRARY_DIR}/curl/build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) + +# ------------------------------------------------------------------------------ diff --git a/cmake/extern/GTest.txt.in b/cmake/extern/GTest.txt.in new file mode 100644 index 00000000..4d4372eb --- /dev/null +++ b/cmake/extern/GTest.txt.in @@ -0,0 +1,21 @@ + +cmake_minimum_required(VERSION 3.2) + +include(ExternalProject) + +# ------------------------------------------------------------------------------ +# Google Test +# ------------------------------------------------------------------------------ + +ExternalProject_Add(GoogleTest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.10.x + SOURCE_DIR "${EXTERNAL_LIBRARY_DIR}/googletest/src" + BINARY_DIR "${EXTERNAL_LIBRARY_DIR}/googletest/build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) + +# ------------------------------------------------------------------------------ diff --git a/docs/INSTALL_PLATFORMIO.md b/docs/INSTALL_PLATFORMIO.md index b0428b24..0231f558 100644 --- a/docs/INSTALL_PLATFORMIO.md +++ b/docs/INSTALL_PLATFORMIO.md @@ -18,7 +18,7 @@ or also install platformio dependencies: -> install AUnit (2778) +> install AUnit (2778) ```platformio lib -g install 2778``` # diff --git a/docs/cpp.md b/docs/cpp.md index d149fe42..c94b4a18 100644 --- a/docs/cpp.md +++ b/docs/cpp.md @@ -213,8 +213,10 @@ using ### make and build - cd cpp-client/ - cmake . && cmake --build . + mkdir build && cd build + cmake -DUNIT_TEST .. + cmake --build . ### run tests - ./test/Ark-Cpp-Client-tests + + ./test/ark_cpp_client_tests diff --git a/examples/cmake_example/CMakeLists.txt b/examples/cmake_example/CMakeLists.txt index d9fafffd..a7a8c529 100644 --- a/examples/cmake_example/CMakeLists.txt +++ b/examples/cmake_example/CMakeLists.txt @@ -1,12 +1,7 @@ -cmake_minimum_required(VERSION 3.2) -# clone submodules - Uncomment when used outside of the Ark cpp-crypto source tree -#execute_process( -# COMMAND git submodule update --init --recursive -# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} -#) +cmake_minimum_required(VERSION 3.2) -project(Cpp-Client-Example) +project(ark_cpp_client_example) set(CMAKE_CXX_STANDARD 11) @@ -28,5 +23,4 @@ add_subdirectory(lib/cpp-client/src) set(SOURCE_FILES main.cpp) add_executable(${PROJECT_NAME} ${SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME} Ark-Cpp-Client-lib) - +target_link_libraries(${PROJECT_NAME} ark_cpp_client) diff --git a/platformio.ini b/platformio.ini index 6a02319b..7eeed0d9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,10 +10,13 @@ [platformio] description = "A simple API client implementation in C++ for the ARK Blockchain." +src_dir = ./src +build_dir = build/.pioenvs +libdeps_dir = extern/.piolibdeps [common] build_flags = -I./src/ -I./src/include/cpp-client -src_filter = +<*> -<.git/> - - -<_3rdParty> - +src_filter = +<*> - upload_speed = 921600 [env:esp8266] diff --git a/run_tests.cmd b/run_tests.cmd index 3d388d7c..9e77eeb7 100644 --- a/run_tests.cmd +++ b/run_tests.cmd @@ -1,2 +1,11 @@ -call build.cmd -.\build\test\Debug\Ark-Cpp-Client-tests + +rmdir /S /Q build +mkdir build +cd build + +cmake -DUNIT_TEST=ON .. +cmake --build . + +cd .. + +.\build\test\Debug\ark_cpp_client_tests diff --git a/run_tests.sh b/run_tests.sh index 3a07c1c9..f428bf51 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,5 +1,11 @@ #!/bin/bash -./build.sh -chmod +x ./build/test/Ark-Cpp-Client-tests -./build/test/Ark-Cpp-Client-tests +rm -dfr build +mkdir build +cd build + +cmake -DUNIT_TEST=ON .. +cmake --build . + +chmod +x ./build/test/ark_cpp_client_tests +./build/test/ark_cpp_client_tests diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7c3433a0..791de74f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,78 +1,92 @@ -cmake_minimum_required(VERSION 3.2.2) -project(Ark-Cpp-Client-lib) +cmake_minimum_required(VERSION 3.2) -set(PLATFORM_SRC - http/os/http.cpp -) +project(ark_cpp_client C CXX) -set(HOST_SRC - host/host.cpp -) +# ------------------------------------------------------------------------------ +# External Libraries +# ------------------------------------------------------------------------------ + +include(${CMAKE_SOURCE_DIR}/cmake/External.cmake) -set(API_PATHS_SRC - api/paths.cpp -) +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# ARK C++ Cliient Source +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# Platform + +set(PLATFORM_SRC http/os/http.cpp) + +# ------------------------------------------------------------------------------ +# Host + +set(HOST_SRC host/host.cpp) + +# ------------------------------------------------------------------------------ +# Paths + +set(PATHS_SRC api/paths.cpp) + +# ------------------------------------------------------------------------------ +# API set(API_SRC - api/blockchain/blockchain.cpp - api/blocks/blocks.cpp - api/delegates/delegates.cpp - api/node/node.cpp - api/peers/peers.cpp - api/rounds/rounds.cpp - api/transactions/transactions.cpp - api/votes/votes.cpp - api/wallets/wallets.cpp -) - -add_library(Ark-Cpp-Client-lib STATIC - ${PLATFORM_SRC} - ${HOST_SRC} - ${API_PATHS_SRC} - ${API_SRC} -) - -set(cpp_client_build_include_dirs - ${PROJECT_SOURCE_DIR} - ${PROJECT_SOURCE_DIR}/include/cpp-client -) - -include_directories(${cpp_client_build_include_dirs}) -include_directories(${PROJECT_SOURCE_DIR}) - -# ------------------------------------------------------------------------------ -# curl -# ------------------------------------------------------------------------------ - -set(BUILD_TESTING OFF) -set(HTTP_ONLY ON) -set(CMAKE_USE_LIBSSH2 OFF) -set(CURL_STATICLIB true) -set(CURL_STATIC_CRT ON) -set(BUILD_CURL_EXE false) - -if (APPLE) - set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl/lib") - set(OPENSSL_INCLUDE_DIR "/usr/local/opt/openssl/include") -endif() + api/blockchain/blockchain.cpp + api/blocks/blocks.cpp + api/delegates/delegates.cpp + api/node/node.cpp + api/peers/peers.cpp + api/rounds/rounds.cpp + api/transactions/transactions.cpp + api/votes/votes.cpp + api/wallets/wallets.cpp) -add_subdirectory(${PROJECT_SOURCE_DIR}/lib/curl) +# ------------------------------------------------------------------------------ +# ARK C++ Client Library Source -include_directories(${PROJECT_SOURCE_DIR}/lib/curl/include) +set(ARK_SOURCE + ${PLATFORM_SRC} + ${HOST_SRC} + ${PATHS_SRC} + ${API_SRC}) -if (APPLE) - target_link_libraries(${PROJECT_NAME} PUBLIC CURL) -else() - target_link_libraries(${PROJECT_NAME} PUBLIC libcurl) -endif() +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# Add the Source Files to the Library +# ------------------------------------------------------------------------------ + +add_library(${PROJECT_NAME} STATIC ${ARK_SOURCE}) + +# ------------------------------------------------------------------------------ + +set(ARK_CPP_CLIENT_INCLUDE_DIRS + ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/include/cpp-client) + +include_directories(${ARK_CPP_CLIENT_INCLUDE_DIRS}) + +target_include_directories(${PROJECT_NAME} PUBLIC ${ARK_CPP_CLIENT_INCLUDE_DIRS}) # ------------------------------------------------------------------------------ -target_include_directories(${PROJECT_NAME} PUBLIC - ${cpp_client_build_include_dirs} -) +# ------------------------------------------------------------------------------ +# Link against CURL +# ------------------------------------------------------------------------------ + +target_link_libraries(${PROJECT_NAME} PUBLIC libcurl) + +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# Windows: Link to `crypt32` +# ------------------------------------------------------------------------------ if (MSVC) - target_link_libraries(${PROJECT_NAME} PUBLIC crypt32) + target_link_libraries(${PROJECT_NAME} PUBLIC crypt32) endif() + +# ------------------------------------------------------------------------------ diff --git a/src/lib/curl b/src/lib/curl deleted file mode 160000 index fe20826b..00000000 --- a/src/lib/curl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fe20826b580aa221f8f796cba236d08dc0fd80fd diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2cd9a291..dcc7c935 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,67 +1,104 @@ -cmake_minimum_required(VERSION 3.2.2) -project(Ark-Cpp-Client-tests) +cmake_minimum_required(VERSION 3.2) -add_subdirectory(lib/googletest) - -include(CTest) -enable_testing() +project(${PROJECT_NAME}_tests C CXX) set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../lib") +# ------------------------------------------------------------------------------ +# External Libraries +# ------------------------------------------------------------------------------ + +include(${CMAKE_SOURCE_DIR}/cmake/GTest.cmake) + +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# Link the directories to be included +# ------------------------------------------------------------------------------ + +include_directories(${PROJECT_SOURCE_DIR}) include_directories(${PROJECT_SOURCE_DIR}/../src) -include_directories(${PROJECT_SOURCE_DIR}/../test) include_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) -set(TEST_CONNECTION_SRC - ${PROJECT_SOURCE_DIR}/connection/connection.cpp -) +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# ARK Test Source +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# Connection + +set(CONNECTION_TEST_SOURCE ${PROJECT_SOURCE_DIR}/connection/connection.cpp) + +# ------------------------------------------------------------------------------ +# Host + +set(HOST_TEST_SOURCE ${PROJECT_SOURCE_DIR}/host/host.cpp) + +# ------------------------------------------------------------------------------ +# HTTP + +set(HTTP_TEST_SOURCE ${PROJECT_SOURCE_DIR}/http/http.cpp) + +# ------------------------------------------------------------------------------ +# Paths + +set(PATH_TEST_SOURCE ${PROJECT_SOURCE_DIR}/api/paths.cpp) + +# ------------------------------------------------------------------------------ +# API + +set(API_TEST_SOURCE + ${PROJECT_SOURCE_DIR}/api/blockchain.cpp + ${PROJECT_SOURCE_DIR}/api/blocks.cpp + ${PROJECT_SOURCE_DIR}/api/delegates.cpp + ${PROJECT_SOURCE_DIR}/api/node.cpp + ${PROJECT_SOURCE_DIR}/api/peers.cpp + ${PROJECT_SOURCE_DIR}/api/rounds.cpp + ${PROJECT_SOURCE_DIR}/api/transactions.cpp + ${PROJECT_SOURCE_DIR}/api/votes.cpp + ${PROJECT_SOURCE_DIR}/api/wallets.cpp) + +# ------------------------------------------------------------------------------ +# ARK C++ Client Library Source + +set(ARK_TEST_SOURCE + ${CONNECTION_TEST_SOURCE} + ${HOST_TEST_SOURCE} + ${HTTP_TEST_SOURCE} + ${PATH_TEST_SOURCE} + ${API_TEST_SOURCE}) -set(TEST_HOST_SRC - ${PROJECT_SOURCE_DIR}/host/host.cpp -) +# ------------------------------------------------------------------------------ -set(TEST_HTTP_SRC - ${PROJECT_SOURCE_DIR}/http/http.cpp -) +# ------------------------------------------------------------------------------ +# Link ARK C++ Client to the Test Libraries +# ------------------------------------------------------------------------------ -set(TEST_API_PATHS_SRC - ${PROJECT_SOURCE_DIR}/api/paths.cpp -) +find_library(${PROJECT_NAME} PUBLIC) -set(TEST_API_SRC - ${PROJECT_SOURCE_DIR}/api/blockchain.cpp - ${PROJECT_SOURCE_DIR}/api/blocks.cpp - ${PROJECT_SOURCE_DIR}/api/delegates.cpp - ${PROJECT_SOURCE_DIR}/api/node.cpp - ${PROJECT_SOURCE_DIR}/api/peers.cpp - ${PROJECT_SOURCE_DIR}/api/rounds.cpp - ${PROJECT_SOURCE_DIR}/api/transactions.cpp - ${PROJECT_SOURCE_DIR}/api/votes.cpp - ${PROJECT_SOURCE_DIR}/api/wallets.cpp -) +add_executable(${PROJECT_NAME} ${ARK_TEST_SOURCE}) -find_library(Ark-Cpp-Client-tests PUBLIC) +target_link_libraries(${PROJECT_NAME} ark_cpp_client gtest gmock gmock_main) -add_executable(Ark-Cpp-Client-tests - ${TEST_CONNECTION_SRC} - ${TEST_HOST_SRC} - ${TEST_HTTP_SRC} - ${TEST_API_PATHS_SRC} - ${TEST_API_SRC} -) +add_test(NAME test COMMAND ${PROJECT_NAME}) -target_link_libraries(Ark-Cpp-Client-tests Ark-Cpp-Client-lib gtest gmock gmock_main) +# ------------------------------------------------------------------------------ -add_test(NAME test COMMAND Ark-Cpp-Client-tests) +# ------------------------------------------------------------------------------ +# Coverage +# ------------------------------------------------------------------------------ if (CMAKE_BUILD_TYPE STREQUAL "Coverage") - include("${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake") + include("${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake") - setup_target_for_coverage(${PROJECT_NAME}_coverage Ark-Cpp-Client-tests coverage) + setup_target_for_coverage(${PROJECT_NAME}_coverage ${PROJECT_NAME} coverage) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") endif() #CMAKE_BUILD_TYPE STREQUAL "Coverage" +# ------------------------------------------------------------------------------ diff --git a/test/lib/googletest b/test/lib/googletest deleted file mode 160000 index 3cf8f514..00000000 --- a/test/lib/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3cf8f514d859d65b7202e51c662a03a92887b8e2 diff --git a/test/platformio.ini b/test/platformio.ini index df5701ef..464af605 100644 --- a/test/platformio.ini +++ b/test/platformio.ini @@ -10,16 +10,16 @@ [platformio] description = "Unit Tests for Ark-Cpp-Client" -src_dir = .. -lib_dir = .. +src_dir = ../src +build_dir = ../build/.pioenvs +libdeps_dir = ../extern/.piolibdeps [common] -lib_ldf_mode = deep lib_deps = googletest # ignore the 'test' lib. This isn't real but the build system somehow thinks that the test directory is also a library and does some double compiling of files lib_ignore = test build_flags = -I../src -I../src/include/cpp-client -I./test -I. -I.. -DUNIT_TEST -src_filter = +<*> -<.git/> - - - -<_3rdParty> - - - #ignore live HTTP tests on IoT +src_filter = +<*> - - #ignore live HTTP tests on IoT upload_speed = 921600 # esp8266 unit tests disabled until GTest/GMock support is worked out @@ -27,7 +27,6 @@ upload_speed = 921600 #platform = espressif8266 #board = huzzah #framework = arduino -#lib_ldf_mode = ${common.lib_ldf_mode} #lib_deps = ${common.lib_deps} #lib_ignore = ${common.lib_ignore} #build_flags = ${common.build_flags} @@ -38,7 +37,6 @@ upload_speed = 921600 platform = espressif32 board = esp32dev framework = arduino -lib_ldf_mode = ${common.lib_ldf_mode} lib_ignore = ${common.lib_ignore} lib_deps = ${common.lib_deps} build_flags = ${common.build_flags} From 485c5afa923e4513b418455815a99743c00bf0bf Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 8 Oct 2019 09:45:33 -0700 Subject: [PATCH 2/2] fix: src filter --- test/platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/platformio.ini b/test/platformio.ini index 532882e2..f833d017 100644 --- a/test/platformio.ini +++ b/test/platformio.ini @@ -18,8 +18,8 @@ libdeps_dir = ../extern/.piolibdeps lib_deps = googletest@1.8.1 # ignore the 'test' lib. This isn't real but the build system somehow thinks that the test directory is also a library and does some double compiling of files lib_ignore = test -build_flags = -I../src -I../src/include/cpp-client -I./test -I. -I.. -DUNIT_TEST -src_filter = +<*> - - #ignore live HTTP tests on IoT +build_flags = -I../test -I../src -I../src/include/cpp-client -DUNIT_TEST +src_filter = +<../src> +<../test/iot> -<../src/http/os> -<../test/http> #ignore live HTTP tests on IoT upload_speed = 921600 # esp8266 unit tests disabled until GTest/GMock support is worked out