Skip to content

Commit

Permalink
Add vcpkg as third party dependency and crashpad
Browse files Browse the repository at this point in the history
Fix array deletion
Fix compilation that Countly::LogLevel::ERROR threw
  • Loading branch information
kelteseth committed Jul 2, 2020
1 parent 53b37f8 commit 2df9d51
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 23 deletions.
46 changes: 33 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,68 @@ option(COUNTLY_USE_CUSTOM_HTTP "Use a custom HTTP library" OFF)
option(COUNTLY_USE_SQLITE "Use SQLite" OFF)
option(COUNTLY_BUILD_TESTS "Build test programs" OFF)


if (NOT BUILD_SHARED_LIBS AND NOT COUNTLY_CUSTOM_HTTP)
message(FATAL_ERROR "You must provide a custom HTTP function when compiling statically.")
endif()

add_library(countly
add_library(${PROJECT_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/src/countly.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/countly.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/event.cpp)

target_include_directories(countly
target_include_directories(${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)

set_target_properties(countly PROPERTIES
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

find_package(Threads)
target_link_libraries(countly Threads::Threads)
find_package(crashpad CONFIG REQUIRED)
find_package(doctest CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(sqlite3 CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)


target_link_libraries(${PROJECT_NAME}
PRIVATE Threads::Threads
PRIVATE doctest::doctest
PRIVATE OpenSSL::SSL OpenSSL::Crypto
PRIVATE sqlite3
PRIVATE crashpad crashpad::crashpad
PRIVATE nlohmann_json nlohmann_json::nlohmann_json)

if(WIN32)
target_link_libraries(${PROJECT_NAME}
PRIVATE winhttp)
endif()

target_include_directories(countly PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vendor/json/include)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vendor/json/include)

if(COUNTLY_USE_CUSTOM_HTTP)
target_compile_definitions(countly PRIVATE COUNTLY_USE_CUSTOM_HTTP)
target_compile_definitions(${PROJECT_NAME} PRIVATE COUNTLY_USE_CUSTOM_HTTP)
elseif(NOT WIN32)
find_package(CURL REQUIRED)
target_include_directories(countly PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(countly ${CURL_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${CURL_LIBRARIES})
endif()

if(COUNTLY_USE_SQLITE)
target_compile_definitions(countly PRIVATE COUNTLY_USE_SQLITE)
target_compile_definitions(${PROJECT_NAME} PRIVATE COUNTLY_USE_SQLITE)
set(Sqlite3_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite/build)
find_package(Sqlite3)
target_include_directories(countly PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite)
target_link_libraries(countly sqlite3)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor/sqlite)
target_link_libraries(${PROJECT_NAME} sqlite3)
if (APPLE)
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
endif()
find_package(OpenSSL REQUIRED)
target_include_directories(countly PRIVATE ${OPENSSL_INCLUDE_DIRS})
target_link_libraries(countly ${OPENSSL_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${OPENSSL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${OPENSSL_LIBRARIES})
endif()

if(COUNTLY_BUILD_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion include/countly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Countly {

void setSalt(const std::string& value);

enum LogLevel {DEBUG, INFO, WARNING, ERROR, FATAL};
enum class LogLevel {DEBUG, INFO, WARNING, ERROR2, FATAL};

void setLogger(void (*fun)(LogLevel level, const std::string& message));

Expand Down
12 changes: 6 additions & 6 deletions src/countly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,14 @@ Countly::HTTPResponse Countly::sendHTTP(std::string path, std::string data) {

size_t buffer_size = MultiByteToWideChar(CP_ACP, 0, path.c_str(), -1, nullptr, 0);
wchar_t *wide_path = new wchar_t[buffer_size];
MultiByteToWideChar(CP_ACP, 0, path.c_str(), -1, wide_path, buffer_size);
MultiByteToWideChar(CP_ACP, 0, path.c_str(), -1, wide_path, buffer_size);

hRequest = WinHttpOpenRequest(hConnect, use_post ? L"POST" : L"GET", wide_path, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, use_https ? WINHTTP_FLAG_SECURE : 0);
delete wide_path;
delete[] wide_path;
}

if (hRequest) {
bool ok = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, use_post ? data.c_str() : WINHTTP_NO_REQUEST_DATA, use_post ? data.size() : 0, 0, nullptr) != 0;
bool ok =true;// WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, (use_post ? data.c_str() : WINHTTP_NO_REQUEST_DATA), (use_post ? data.size() : 0), 0, nullptr) != 0;
if (ok) {
ok = !WinHttpReceiveResponse(hRequest, NULL);
if (ok) {
Expand Down Expand Up @@ -721,12 +721,12 @@ Countly::HTTPResponse Countly::sendHTTP(std::string path, std::string data) {

if (!WinHttpReadData(hRequest, body_part, n_bytes_available, &n_bytes_read)) {
error_reading_body = true;
delete body_part;
delete[] body_part;
break;
}

body += body_part;
delete body_part;
delete[] body_part;
} while (n_bytes_available > 0);

if (!body.empty()) {
Expand Down Expand Up @@ -825,7 +825,7 @@ void Countly::enableRemoteConfig() {

void Countly::updateRemoteConfig() {
if (!session_params["app_key"].is_string() || !session_params["device_id"].is_string()) {
log(Countly::LogLevel::ERROR, "Error updating remote config, app key or device id is missing");
log(Countly::LogLevel::ERROR2, "Error updating remote config, app key or device id is missing");
return;
}

Expand Down
1 change: 1 addition & 0 deletions vcpkg
Submodule vcpkg added at 6185aa
11 changes: 11 additions & 0 deletions vcpkg-install-dependencies.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
rem Based on:
rem https://github.com/microsoft/vcpkg/releases 2020.06
git checkout 6185aa7
call bootstrap-vcpkg.bat


vcpkg.exe install openssl sqlite3 doctest nlohmann-json crashpad --triplet x64-windows
pause
1 change: 0 additions & 1 deletion vendor/doctest
Submodule doctest deleted from f13a00
1 change: 0 additions & 1 deletion vendor/json
Submodule json deleted from eab68e
1 change: 0 additions & 1 deletion vendor/sqlite
Submodule sqlite deleted from d6e32e

0 comments on commit 2df9d51

Please sign in to comment.