Skip to content

Commit

Permalink
refactor: cmake setup (#23)
Browse files Browse the repository at this point in the history
* feat:  Initial refactor of cmake

Refactor cmake and project organization to be more modular and to better conform to best practices.

* chore:  Remove unused file

* fix: Correct build errors

Corrected tests link errors by reverting GTest back to hunter package instead of submodule.  Removed Windows compile flags for /MT

* fix: Added missing header

* chore: Moved helpers to private header

* fix:  Made http public header

* chore:  Removed unused headers

* fix:  Remove unnecessary strings

Changed tests to just compare native types instead of converting to strings when not needed.

* fix:  Fix PlatformIO builds

Fixed PlatformIO builds to work with new folder structure.  Removed submodule python script in favor of just ignoring the directory.  This will allow desktop and IoT to better co-exist in the same source tree. Remove [common] section of test/platformio.ini as it did not seem to actually be respected.

* fix:  Remove old submodule

* fix: Correct test binary path

* fix:  Corrected tests

* chore:  Added Windows build files to .gitignore

* fix:  Correct test where blocks can be a zero value

* fix:  Add missing macro

Added missing adapter macro to GTest adapter.

Will submit PR to AUnit library for proper fix.
  • Loading branch information
ciband authored and faustbrian committed Nov 30, 2018
1 parent 0148291 commit 3d9e138
Show file tree
Hide file tree
Showing 52 changed files with 83 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .circleci/script_desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ cmake . -DCMAKE_BUILD_TYPE=Coverage
cmake --build .

# run Gtest
./bin/Ark-Cpp-Client-tests
./test/Ark-Cpp-Client-tests
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@
/ALL_BUILD.vcxproj.filters
/ALL_BUILD.vcxproj
/src/Win32
/test/Debug
/src/Debug
/test/Release
/src/Release
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "test/include/ArduinoJson"]
path = test/include/ArduinoJson
[submodule "test/lib/ArduinoJson"]
path = test/lib/ArduinoJson
url = https://github.com/bblanchon/ArduinoJson
[submodule "test/lib/googletest"]
path = test/lib/googletest
url = https://github.com/google/googletest.git
31 changes: 12 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.2.2)

set(HUNTER_STATUS_DEBUG ON)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/cmake/toolchain.cmake")

Expand All @@ -8,35 +9,27 @@ HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.23.29.tar.gz"
SHA1 "797be99a8a4f4666766257563fad8aa3aa032da2"
)

project(Ark-Cpp-Client)

set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)

set(PROJECT_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/test/include)
set(CMAKE_CXX_STANDARD 11)

# clone submodules
execute_process(
COMMAND git submodule update --init --recursive
WORKING_DIRECTORY ${PROJECT_INCLUDE_DIR}
)
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})

if (MSVC)
add_definitions(
-D_CRT_SECURE_NO_WARNINGS
add_definitions(
-D_CRT_SECURE_NO_WARNINGS
-D_SCL_SECURE_NO_WARNINGS
-DNOMINMAX
)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
elseif (UNIX)
set (CMAKE_CXX_FLAGS "-std=c++11")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
endif()

include_directories("${PROJECT_SOURCE_DIR}")
# clone submodules
execute_process(
COMMAND git submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

add_subdirectory(src)
add_subdirectory(test)

4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
platform = espressif8266
board = huzzah
framework = arduino
build_flags = -I./src/
build_flags = -I./src/ -I./src/include/cpp-client
src_filter = +<*> -<.git/> -<svn/> -<example/> -<examples/> -<http/os/> -<_3rdParty> -<CMakeFiles>
upload_speed = 921600

[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
build_flags = -I./src/
build_flags = -I./src/ -I./src/include/cpp-client
src_filter = +<*> -<.git/> -<svn/> -<example/> -<examples/> -<http/os/> -<_3rdParty> -<CMakeFiles>
upload_speed = 921600
49 changes: 26 additions & 23 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,31 @@ cmake_minimum_required(VERSION 3.2.2)

project(Ark-Cpp-Client-lib)

set (PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})

include_directories(${PROJECT_SOURCE_DIR})

hunter_add_package(CURL)
find_package(CURL CONFIG REQUIRED)

set(PLATFORM_SRC
${PROJECT_SOURCE_DIR}/http/os/http.cpp
http/os/http.cpp
)

set(API_ONE_SRC
${PROJECT_SOURCE_DIR}/api/one/accounts/one_accounts.cpp
${PROJECT_SOURCE_DIR}/api/one/blocks/one_blocks.cpp
${PROJECT_SOURCE_DIR}/api/one/delegates/one_delegates.cpp
${PROJECT_SOURCE_DIR}/api/one/loader/one_loader.cpp
${PROJECT_SOURCE_DIR}/api/one/peers/one_peers.cpp
${PROJECT_SOURCE_DIR}/api/one/signatures/one_signatures.cpp
${PROJECT_SOURCE_DIR}/api/one/transactions/one_transactions.cpp
api/one/accounts/one_accounts.cpp
api/one/blocks/one_blocks.cpp
api/one/delegates/one_delegates.cpp
api/one/loader/one_loader.cpp
api/one/peers/one_peers.cpp
api/one/signatures/one_signatures.cpp
api/one/transactions/one_transactions.cpp
)

set(API_TWO_SRC
${PROJECT_SOURCE_DIR}/api/two/blocks/two_blocks.cpp
${PROJECT_SOURCE_DIR}/api/two/delegates/two_delegates.cpp
${PROJECT_SOURCE_DIR}/api/two/node/two_node.cpp
${PROJECT_SOURCE_DIR}/api/two/peers/two_peers.cpp
${PROJECT_SOURCE_DIR}/api/two/transactions/two_transactions.cpp
${PROJECT_SOURCE_DIR}/api/two/votes/two_votes.cpp
${PROJECT_SOURCE_DIR}/api/two/wallets/two_wallets.cpp
api/two/blocks/two_blocks.cpp
api/two/delegates/two_delegates.cpp
api/two/node/two_node.cpp
api/two/peers/two_peers.cpp
api/two/transactions/two_transactions.cpp
api/two/votes/two_votes.cpp
api/two/wallets/two_wallets.cpp
)

add_library(Ark-Cpp-Client-lib STATIC
Expand All @@ -40,11 +36,18 @@ add_library(Ark-Cpp-Client-lib STATIC
${API_TWO_SRC}
)

target_link_libraries(Ark-Cpp-Client-lib
PUBLIC
CURL::libcurl
set(cpp_client_build_include_dirs
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/include/cpp-client
)
include_directories(${cpp_client_build_include_dirs})

target_include_directories( ${PROJECT_NAME}
PUBLIC ${cpp_client_build_include_dirs}
)

target_link_libraries(${PROJECT_NAME} PUBLIC CURL::libcurl)

if (MSVC)
target_link_libraries(Ark-Cpp-Client-lib PUBLIC crypt32)
target_link_libraries(${PROJECT_NAME} PUBLIC crypt32)
endif()
1 change: 1 addition & 0 deletions src/api/two/votes/two_votes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "api/two/votes/two_votes.h"

#include <cstdint>
#include <cstdio>

std::string Ark::Client::API::TWO::Votes::get(const char *const identifier)
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/one/one_paths.h"
#include "helpers/helpers.h"

namespace Ark {
namespace Client {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/one/one_paths.h"
#include "helpers/helpers.h"

namespace Ark {
namespace Client {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/one/one_paths.h"
#include "helpers/helpers.h"

namespace Ark {
namespace Client {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/one/one_paths.h"
#include "helpers/helpers.h"
#include <string>

namespace Ark {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/two/two_paths.h"
#include "helpers/helpers.h"

namespace Ark {
namespace Client {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/two/two_paths.h"
#include "helpers/helpers.h"

namespace Ark {
namespace Client {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/two/two_paths.h"
#include "helpers/helpers.h"

namespace Ark {
namespace Client {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/two/two_paths.h"
#include "helpers/helpers.h"

namespace Ark {
namespace Client {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/two/two_paths.h"
#include "helpers/helpers.h"

namespace Ark {
namespace Client {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/two/two_paths.h"
#include "helpers/helpers.h"

namespace Ark {
namespace Client {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "api/api_base.h"
#include "api/two/two_paths.h"
#include "helpers/helpers.h"
#include <string>

namespace Ark {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
67 changes: 0 additions & 67 deletions test/.travis.yml

This file was deleted.

22 changes: 8 additions & 14 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../lib")

include_directories(${PROJECT_SOURCE_DIR}/../src)
include_directories(${PROJECT_SOURCE_DIR}/../test)
include_directories(${PROJECT_SOURCE_DIR}/include/ArduinoJson)
include_directories(${PROJECT_SOURCE_DIR}/lib/ArduinoJson)
include_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})

set(TEST_API_SRC
Expand All @@ -41,30 +41,24 @@ set(TEST_TWO_SRC
${PROJECT_SOURCE_DIR}/api/two/two_wallets.cpp
)

find_library(Ark-Cpp-Client-tests
NAMES Ark-Cpp-Client-lib
PATHS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
)
find_library(Ark-Cpp-Client-tests PUBLIC)

add_executable(Ark-Cpp-Client-tests
${TEST_API_SRC}
${TEST_ONE_SRC}
${TEST_TWO_SRC}
)

target_link_libraries(Ark-Cpp-Client-tests Ark-Cpp-Client-lib)

target_link_libraries(Ark-Cpp-Client-tests GTest::main) # GTest::gtest will be linked automatically
target_link_libraries(Ark-Cpp-Client-tests GTest::gtest)
target_link_libraries(Ark-Cpp-Client-tests Ark-Cpp-Client-lib GTest::gtest GTest::main)

add_test(NAME test COMMAND Ark-Cpp-Client-tests)

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 Ark-Cpp-Client-tests 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"
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"

2 changes: 1 addition & 1 deletion test/api/one/one_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ TEST(api, test_one_loader_sync)
ASSERT_FALSE(syncing);

int blocks = root["blocks"];
ASSERT_STRNE("", std::to_string(blocks).c_str());
ASSERT_GE(0, blocks);

int height = root["height"];
ASSERT_NE(0, height);
Expand Down
2 changes: 1 addition & 1 deletion test/api/one/one_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST(api, test_one_transactions_transaction)
ASSERT_STREQ("4115750139916005265", blockid);

int height = transaction["height"];
ASSERT_STREQ("2695914", std::to_string(height).c_str());
ASSERT_EQ(2695914, height);

int type = transaction["type"];
ASSERT_EQ(0, type);
Expand Down

0 comments on commit 3d9e138

Please sign in to comment.