From a8312714b994d88f030e91159a22a7f7fd6e53ae Mon Sep 17 00:00:00 2001 From: Tamas Kenez Date: Sat, 29 Apr 2023 11:15:19 +0200 Subject: [PATCH 1/3] install cmake config --- .github/workflows/install.yml | 47 ++++++++++++ CMakeLists.txt | 85 ++++++++++++++------- README.md | 30 ++++++-- cmake/FindLibUUID.cmake | 42 ++++++++++ cmake/FindUUID.cmake | 37 --------- cmake/snowplow-config.cmake.in | 16 ++++ include/snowplow/http/http_client_curl.cpp | 2 +- include/snowplow/http/http_client_curl.hpp | 2 +- include/snowplow/storage/sqlite_storage.cpp | 1 + include/snowplow/storage/sqlite_storage.hpp | 6 +- test/install/CMakeLists.txt | 10 +++ test/install/conanfile.py | 14 ++++ test/install/main.cpp | 15 ++++ 13 files changed, 236 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/install.yml create mode 100644 cmake/FindLibUUID.cmake delete mode 100644 cmake/FindUUID.cmake create mode 100644 cmake/snowplow-config.cmake.in create mode 100644 test/install/CMakeLists.txt create mode 100644 test/install/conanfile.py create mode 100644 test/install/main.cpp diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml new file mode 100644 index 0000000..edc17b4 --- /dev/null +++ b/.github/workflows/install.yml @@ -0,0 +1,47 @@ +name: Install + +on: + workflow_dispatch: + +jobs: + install-matrix: + strategy: + matrix: + os: [macos-latest, windows-latest, ubuntu-latest] + build_shared_libs: [0, 1] + system_curl_uuid: ["False"] + include: + - os: ubuntu-latest + build_shared_libs: 0 + system_curl_uuid: "True" + - os: ubuntu-latest + build_shared_libs: 1 + system_curl_uuid: "True" + name: "${{ matrix.os }}: shared: ${{ matrix.build_shared_libs }}, system_curl_uuid ${{ matrix.system_curl_uuid }}" + runs-on: ${{ matrix.os }} + steps: + - name: Install Conan + id: conan + uses: turtlebrowser/get-conan@main + with: + version: 1.60.0 + - name: Checkout + uses: actions/checkout@v3 + - name: Install Snowplow dependencies with apt-get + run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev uuid-dev + if: matrix.system_curl_uuid == 'True' + - name: Create Conan default profile + run: conan profile new default --detect + - name: Enable new gcc ABI + run: conan profile update settings.compiler.libcxx=libstdc++11 default + if: matrix.os == 'ubuntu-latest' + - name: Install Snowplow dependencies with Conan + run: conan install test/install -b missing -if i/cmake -pr:b=default -pr:h=default -s build_type=Debug -g=CMakeDeps -o system_curl_uuid=${{ matrix.system_curl_uuid }} + - name: Build and Install Snowplow + run: | + cmake -S . -B b1 -DCMAKE_INSTALL_PREFIX=i -DCMAKE_BUILD_TYPE=Debug -DSNOWPLOW_USE_EXTERNAL_JSON=1 -DSNOWPLOW_USE_EXTERNAL_SQLITE=1 -DSNOWPLOW_BUILD_TESTS=0 -DSNOWPLOW_BUILD_EXAMPLE=0 -DSNOWPLOW_BUILD_PERFORMANCE=0 -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=1 -DBUILD_SHARED_LIBS=${{ matrix.build_shared_libs }} + cmake --build b1 --target install --config Debug + - name: Build the test project + run: | + cmake -S test/install -B b2 -DCMAKE_INSTALL_PREFIX=i -DCMAKE_BUILD_TYPE=Debug -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=1 + cmake --build b2 --config Debug diff --git a/CMakeLists.txt b/CMakeLists.txt index 5824aa7..3f1ce0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.15) # 3.15 for CMAKE_FIND_PACKAGE_PREFER_CONFIG and CMAKE_MSVC_RUNTIME_LIBRARY file(READ ${CMAKE_CURRENT_SOURCE_DIR}/include/snowplow/constants.hpp CONSTANTS_HPP_CONTENTS) string(REGEX MATCH "const string SNOWPLOW_TRACKER_VERSION_LABEL = \"cpp-[^\"]+\"" SNOWPLOW_TRACKER_VERSION ${CONSTANTS_HPP_CONTENTS}) @@ -55,32 +55,33 @@ add_library(snowplow ${SNOWPLOW_SOURCES}) target_include_directories(snowplow PUBLIC $ - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) + $) set_target_properties(snowplow PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES - CXX_EXTENSIONS NO) + CXX_EXTENSIONS NO + VERSION ${SNOWPLOW_TRACKER_VERSION}) # add nlohmann/json library include(FetchContent) +set(NLOHMANN_JSON_VERSION 3.10.5) if(SNOWPLOW_USE_EXTERNAL_JSON) - find_package(nlohmann_json 3.10.5 REQUIRED) + find_package(nlohmann_json ${NLOHMANN_JSON_VERSION} REQUIRED) else() FetchContent_Declare( nlohmann_json GIT_REPOSITORY https://github.com/nlohmann/json - GIT_TAG v3.10.5 + GIT_TAG v${NLOHMANN_JSON_VERSION} ) FetchContent_MakeAvailable(nlohmann_json) endif() -target_link_libraries(snowplow nlohmann_json::nlohmann_json) +target_link_libraries(snowplow PUBLIC nlohmann_json::nlohmann_json) # add sqlite3 if(SNOWPLOW_USE_EXTERNAL_SQLITE) find_package(SQLite3 REQUIRED) - target_include_directories(snowplow PUBLIC ${SQLite3_INCLUDE_DIRS}) - target_link_libraries(snowplow ${SQLite3_LIBRARIES}) + target_link_libraries(snowplow PRIVATE SQLite::SQLite3) else() FetchContent_Declare(sqlite_amalgamation URL "https://www.sqlite.org/2022/sqlite-amalgamation-3380500.zip") if (NOT sqlite_amalgamation_POPULATED) @@ -91,31 +92,63 @@ else() endif() find_package(Threads) -target_link_libraries(snowplow Threads::Threads) +target_link_libraries(snowplow PRIVATE Threads::Threads) if (APPLE) - find_library(COREFOUNDATION CoreFoundation) - target_link_libraries(snowplow ${COREFOUNDATION}) - find_library(FOUNDATION Foundation) - target_link_libraries(snowplow ${FOUNDATION}) - find_library(CORESERVICES CoreServices) - target_link_libraries(snowplow ${CORESERVICES}) -endif() - -if (NOT WIN32) - find_package(CURL REQUIRED) - target_include_directories(snowplow PRIVATE ${CURL_INCLUDE_DIRS}) - target_link_libraries(snowplow ${CURL_LIBRARIES}) - target_link_libraries(snowplow ${CMAKE_DL_LIBS}) + target_link_libraries(snowplow PRIVATE + "-framework CoreFoundation" + "-framework Foundation" + "-framework CoreServices") endif() if (NOT APPLE AND NOT WIN32) - find_package(UUID REQUIRED) - include_directories("${UUID_INCLUDE_DIR}") - target_link_libraries(snowplow "${UUID_LIBRARY}") + find_package(CURL REQUIRED) + target_link_libraries(snowplow PRIVATE CURL::libcurl) + set(SNOWPLOW_NEEDS_CURL 1) + target_link_libraries(snowplow PRIVATE ${CMAKE_DL_LIBS}) + find_package(LibUUID REQUIRED) + target_link_libraries(snowplow PRIVATE libuuid::libuuid) + set(SNOWPLOW_NEEDS_LIBUUID 1) endif () -target_include_directories(snowplow PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +include(CMakePackageConfigHelpers) +if(SNOWPLOW_USE_EXTERNAL_SQLITE AND SNOWPLOW_USE_EXTERNAL_JSON) + install(TARGETS snowplow EXPORT snowplow-export + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib) + + install(DIRECTORY include/snowplow + DESTINATION include + FILES_MATCHING + PATTERN *.hpp + PATTERN *.h + PATTERN sqlite3.hpp EXCLUDE) + + install(EXPORT snowplow-export + DESTINATION lib/cmake/snowplow + NAMESPACE snowplow:: + FILE snowplow-targets.cmake) + + configure_file( + cmake/snowplow-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/configure_file/snowplow-config.cmake + @ONLY) + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/configure_file/snowplow-config-version.cmake + COMPATIBILITY SameMajorVersion) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/configure_file/snowplow-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/configure_file/snowplow-config-version.cmake + DESTINATION lib/cmake/snowplow) + if(SNOWPLOW_NEEDS_LIBUUID) + install(FILES ${SNOWPLOW_CMAKE_DIR}/FindLibUUID.cmake + DESTINATION lib/cmake/snowplow) + endif() +else() + message(STATUS "Install target not added because SNOWPLOW_USE_EXTERNAL_SQLITE or SNOWPLOW_USE_EXTERNAL_JSON is OFF") +endif() if(SNOWPLOW_BUILD_TESTS) add_executable(snowplow-tests diff --git a/README.md b/README.md index 4d82219..cbaa23f 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,15 @@ The tracker supports macOS, Windows, and Linux. ### Installation -There are two ways to install the tracker in your app: +There are three ways to install the tracker in your app: -1. By including the project using cmake. -2. By copying source files inside the `include` folder into your codebase. +1. By adding the project into your `CMakeLists.txt` as a subdirectory. +2. By installing the project and importing it into your app using CMake's `find_package` command. +3. By copying source files inside the `include` folder into your codebase. -#### Using cmake +#### As a subdirectory in your CMake project -Cmake version 3.14 or greater is required. You may add the library to your project target (`your-target`) using `FetchContent` like so: +CMake version 3.15 or greater is required. You may add the library to your project target (`your-target`) using `FetchContent` like so: ```cmake include(FetchContent) @@ -36,6 +37,25 @@ FetchContent_MakeAvailable(snowplow) target_link_libraries(your-target snowplow) ``` +#### As an imported target in your CMake project + +First build and install the project. Make sure the project uses the external JSON and SQLite3 libraries (`SNOWPLOW_USE_EXTERNAL_JSON=ON` and `SNOWPLOW_USE_EXTERNAL_SQLITE=ON`). Use `BUILD_SHARED_LIBS=ON` to build a shared library. Depending on how you're providing the dependencies for which there are find-modules (`sqlite3`, `libcurl`, `uuid`) you might need to set `CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON` to prevent linking to the system libraries. + +```cmake +cmake [...] -DCMAKE_INSTALL_PREFIX=[...] + -DSNOWPLOW_USE_EXTERNAL_JSON=ON -DSNOWPLOW_USE_EXTERNAL_SQLITE=ON \ + -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON \ + -DSNOWPLOW_BUILD_TESTS=0 -DSNOWPLOW_BUILD_EXAMPLE=0 -DSNOWPLOW_BUILD_PERFORMANCE=0 +``` + +After building and installing the project you can use `find_package` to import it into your CMakeLists.txt: + +```cmake +find_package(snowplow REQUIRED CONFIG) +... +target_link_libraries(your-target snowplow::snowplow) +``` + #### Copying files to your project Download the most recent release from the [releases section](https://github.com/snowplow/snowplow-cpp-tracker/releases). Everything in the `include` folder will need to be included in your application. diff --git a/cmake/FindLibUUID.cmake b/cmake/FindLibUUID.cmake new file mode 100644 index 0000000..31256a3 --- /dev/null +++ b/cmake/FindLibUUID.cmake @@ -0,0 +1,42 @@ +find_library(LibUUID_LIBRARY + NAMES uuid + PATHS /lib /usr/lib /usr/local/lib +) + +set(CMAKE_FIND_FRAMEWORK_SAVE ${CMAKE_FIND_FRAMEWORK}) +set(CMAKE_FIND_FRAMEWORK NEVER) + +find_path(LibUUID_INCLUDE_DIR uuid/uuid.h +/usr/local/include +/usr/include +) + +if (LibUUID_LIBRARY AND LibUUID_INCLUDE_DIR) + set(LibUUID_LIBRARIES ${LibUUID_LIBRARY}) + set(LibUUID_FOUND "YES") +else () + set(LibUUID_FOUND "NO") +endif () + +if (LibUUID_FOUND) + if (NOT LibUUID_FIND_QUIETLY) + message(STATUS "Found UUID: ${LibUUID_LIBRARIES}") + endif () + add_library(libuuid::libuuid SHARED IMPORTED) + set_target_properties(libuuid::libuuid PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${LibUUID_INCLUDE_DIR} + IMPORTED_LOCATION ${LibUUID_LIBRARY} + ) +else () + if (LibUUID_FIND_REQUIRED) + message( "library: ${LibUUID_LIBRARY}" ) + message( "include: ${LibUUID_INCLUDE_DIR}" ) + message(FATAL_ERROR "Could not find UUID library") + endif () +endif () + +mark_as_advanced( + LibUUID_LIBRARY + LibUUID_INCLUDE_DIR +) +set(CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_SAVE}) diff --git a/cmake/FindUUID.cmake b/cmake/FindUUID.cmake deleted file mode 100644 index 5ab522e..0000000 --- a/cmake/FindUUID.cmake +++ /dev/null @@ -1,37 +0,0 @@ -find_library(UUID_LIBRARY - NAMES uuid - PATHS /lib /usr/lib /usr/local/lib -) - -set(CMAKE_FIND_FRAMEWORK_SAVE ${CMAKE_FIND_FRAMEWORK}) -set(CMAKE_FIND_FRAMEWORK NEVER) - -find_path(UUID_INCLUDE_DIR uuid/uuid.h -/usr/local/include -/usr/include -) - -if (UUID_LIBRARY AND UUID_INCLUDE_DIR) - set(UUID_LIBRARIES ${UUID_LIBRARY}) - set(UUID_FOUND "YES") -else () - set(UUID_FOUND "NO") -endif () - -if (UUID_FOUND) - if (NOT UUID_FIND_QUIETLY) - message(STATUS "Found UUID: ${UUID_LIBRARIES}") - endif () -else () - if (UUID_FIND_REQUIRED) - message( "library: ${UUID_LIBRARY}" ) - message( "include: ${UUID_INCLUDE_DIR}" ) - message(FATAL_ERROR "Could not find UUID library") - endif () -endif () - -mark_as_advanced( - UUID_LIBRARY - UUID_INCLUDE_DIR -) -set(CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_SAVE}) diff --git a/cmake/snowplow-config.cmake.in b/cmake/snowplow-config.cmake.in new file mode 100644 index 0000000..d313c06 --- /dev/null +++ b/cmake/snowplow-config.cmake.in @@ -0,0 +1,16 @@ +include(CMakeFindDependencyMacro) + +find_dependency(nlohmann_json @nlohmann_json_VERSION@ EXACT REQUIRED) +find_dependency(SQLite3) +find_dependency(Threads) + +if(@SNOWPLOW_NEEDS_LIBUUID@) + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) + find_dependency(LibUUID) +endif() + +if(@SNOWPLOW_NEEDS_CURL@) + find_dependency(CURL) +endif() + +include(${CMAKE_CURRENT_LIST_DIR}/snowplow-targets.cmake) diff --git a/include/snowplow/http/http_client_curl.cpp b/include/snowplow/http/http_client_curl.cpp index f9d337c..0f61a09 100644 --- a/include/snowplow/http/http_client_curl.cpp +++ b/include/snowplow/http/http_client_curl.cpp @@ -11,7 +11,7 @@ software distributed under the Apache License Version 2.0 is distributed on an See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) || defined(__CYGWIN__) +#if !defined(__APPLE__) && !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) || defined(__CYGWIN__) #include "http_client_curl.hpp" #include "../constants.hpp" #include diff --git a/include/snowplow/http/http_client_curl.hpp b/include/snowplow/http/http_client_curl.hpp index 25be71e..7c93671 100644 --- a/include/snowplow/http/http_client_curl.hpp +++ b/include/snowplow/http/http_client_curl.hpp @@ -13,7 +13,7 @@ See the Apache License Version 2.0 for the specific language governing permissio #ifndef HTTP_CLIENT_CURL_H #define HTTP_CLIENT_CURL_H -#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) || defined(__CYGWIN__) +#if !defined(__APPLE__) && !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) || defined(__CYGWIN__) #include "http_client.hpp" diff --git a/include/snowplow/storage/sqlite_storage.cpp b/include/snowplow/storage/sqlite_storage.cpp index 7c07498..f532e49 100644 --- a/include/snowplow/storage/sqlite_storage.cpp +++ b/include/snowplow/storage/sqlite_storage.cpp @@ -15,6 +15,7 @@ See the Apache License Version 2.0 for the specific language governing permissio #include #include "../detail/utils/utils.hpp" +#include "../thirdparty/sqlite3.hpp" using namespace snowplow; using std::cerr; diff --git a/include/snowplow/storage/sqlite_storage.hpp b/include/snowplow/storage/sqlite_storage.hpp index b4eeee3..8fe0937 100644 --- a/include/snowplow/storage/sqlite_storage.hpp +++ b/include/snowplow/storage/sqlite_storage.hpp @@ -20,7 +20,11 @@ See the Apache License Version 2.0 for the specific language governing permissio #include #include #include "../thirdparty/json.hpp" -#include "../thirdparty/sqlite3.hpp" + +extern "C" { +typedef struct sqlite3 sqlite3; +typedef struct sqlite3_stmt sqlite3_stmt; +} using std::mutex; using std::string; diff --git a/test/install/CMakeLists.txt b/test/install/CMakeLists.txt new file mode 100644 index 0000000..170fe52 --- /dev/null +++ b/test/install/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.15) +project(snowplow-install-tester-client) + +set(CMAKE_CXX_STANDARD 11) +set(CXX_STANDARD_REQUIRED YES) + +find_package(snowplow REQUIRED CONFIG) + +add_executable(install-test main.cpp) +target_link_libraries(install-test PRIVATE snowplow::snowplow) diff --git a/test/install/conanfile.py b/test/install/conanfile.py new file mode 100644 index 0000000..0c78518 --- /dev/null +++ b/test/install/conanfile.py @@ -0,0 +1,14 @@ +from conans import ConanFile + +class LDDProDepsConan(ConanFile): + settings = "os", "compiler", "build_type", "arch", "arch_build" + + options = {"system_curl_uuid": [True, False]} + default_options = {"system_curl_uuid": False} + + def requirements(self): + self.requires("nlohmann_json/3.11.2") + self.requires("sqlite3/3.42.0") + if not self.options.system_curl_uuid and self.settings.os != "Macos" and (self.settings.os != "Windows" or self.settings.os.subsystem == "cygwin" or self.settings.os.subsystem == "wsl"): + self.requires("libcurl/8.0.1") + self.requires("libuuid/1.0.3") diff --git a/test/install/main.cpp b/test/install/main.cpp new file mode 100644 index 0000000..4ab4542 --- /dev/null +++ b/test/install/main.cpp @@ -0,0 +1,15 @@ +#include +#include +#include +#include + +#include + +int main() { + auto uuid = snowplow::Utils::get_uuid4(); + auto payload = snowplow::Utils::deserialize_json_str(""); + snowplow::NetworkConfiguration network_config(""); + snowplow::Emitter emitter(network_config, snowplow::EmitterConfiguration("")); + + return EXIT_SUCCESS; +} From cce6efa90eba39c6541d83c3d3655e6f105fd7b8 Mon Sep 17 00:00:00 2001 From: Tamas Kenez Date: Mon, 22 May 2023 08:53:10 +0200 Subject: [PATCH 2/3] snowplow test apple curl --- CMakeLists.txt | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f1ce0c..09bdcc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,25 +151,30 @@ else() endif() if(SNOWPLOW_BUILD_TESTS) - add_executable(snowplow-tests - ${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/http/test_http_client.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/client_session_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/cracked_url_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/emitter/emitter_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/emitter/retry_delay_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/http/http_client_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/http/http_request_result_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/payload/payload_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/payload/event_payload_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/payload/self_describing_json_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/storage/sqlite_storage_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/subject_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/tracker_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/snowplow_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/integration/integration_test.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/integration/micro.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test/utils_test.cpp) + add_executable(snowplow-tests + ${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/http/test_http_client.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/client_session_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/cracked_url_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/emitter/emitter_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/emitter/retry_delay_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/http/http_client_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/http/http_request_result_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/payload/payload_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/payload/event_payload_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/payload/self_describing_json_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/storage/sqlite_storage_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/subject_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/tracker_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/snowplow_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/integration/integration_test.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/integration/micro.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/utils_test.cpp) + + if (NOT WIN32) + find_package(CURL REQUIRED) + target_link_libraries(snowplow-tests CURL::libcurl) + endif () target_link_libraries(snowplow-tests snowplow) set_target_properties(snowplow-tests PROPERTIES From 6cf8554072708108d7105d08175084fabe07323d Mon Sep 17 00:00:00 2001 From: Tamas Kenez Date: Mon, 22 May 2023 09:35:38 +0200 Subject: [PATCH 3/3] tmp --- .github/workflows/install.yml | 22 ++++++++++++++++++---- CMakeLists.txt | 21 ++++++++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index edc17b4..d83bfa3 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -10,14 +10,28 @@ jobs: os: [macos-latest, windows-latest, ubuntu-latest] build_shared_libs: [0, 1] system_curl_uuid: ["False"] + external_sqlite: [1] include: + # Extra Linux jobs for using system curl/libuuid - os: ubuntu-latest build_shared_libs: 0 system_curl_uuid: "True" - os: ubuntu-latest build_shared_libs: 1 system_curl_uuid: "True" - name: "${{ matrix.os }}: shared: ${{ matrix.build_shared_libs }}, system_curl_uuid ${{ matrix.system_curl_uuid }}" + # Extra jobs to test installer with SQLite3 compiled into Snowplow + - os: macos-latest + build_shared_libs: 1 + system_curl_uuid: "False" + external_sqlite: 0 + - os: windows-latest + build_shared_libs: 1 + system_curl_uuid: "False" + external_sqlite: 0 + - os: ubuntu-latest + build_shared_libs: 1 + system_curl_uuid: "False" + external_sqlite: 0 runs-on: ${{ matrix.os }} steps: - name: Install Conan @@ -32,14 +46,14 @@ jobs: if: matrix.system_curl_uuid == 'True' - name: Create Conan default profile run: conan profile new default --detect - - name: Enable new gcc ABI + - name: Enable new gcc ABI for Conan builds run: conan profile update settings.compiler.libcxx=libstdc++11 default if: matrix.os == 'ubuntu-latest' - name: Install Snowplow dependencies with Conan run: conan install test/install -b missing -if i/cmake -pr:b=default -pr:h=default -s build_type=Debug -g=CMakeDeps -o system_curl_uuid=${{ matrix.system_curl_uuid }} - - name: Build and Install Snowplow + - name: Build and install Snowplow run: | - cmake -S . -B b1 -DCMAKE_INSTALL_PREFIX=i -DCMAKE_BUILD_TYPE=Debug -DSNOWPLOW_USE_EXTERNAL_JSON=1 -DSNOWPLOW_USE_EXTERNAL_SQLITE=1 -DSNOWPLOW_BUILD_TESTS=0 -DSNOWPLOW_BUILD_EXAMPLE=0 -DSNOWPLOW_BUILD_PERFORMANCE=0 -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=1 -DBUILD_SHARED_LIBS=${{ matrix.build_shared_libs }} + cmake -S . -B b1 -DCMAKE_INSTALL_PREFIX=i -DCMAKE_BUILD_TYPE=Debug -DSNOWPLOW_USE_EXTERNAL_JSON=1 -DSNOWPLOW_USE_EXTERNAL_SQLITE=${{ matrix.external_sqlite }} -DSNOWPLOW_BUILD_TESTS=0 -DSNOWPLOW_BUILD_EXAMPLE=0 -DSNOWPLOW_BUILD_PERFORMANCE=0 -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=1 -DBUILD_SHARED_LIBS=${{ matrix.build_shared_libs }} cmake --build b1 --target install --config Debug - name: Build the test project run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 09bdcc8..f82af79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,8 +87,8 @@ else() if (NOT sqlite_amalgamation_POPULATED) FetchContent_Populate(sqlite_amalgamation) endif() - target_include_directories(snowplow PUBLIC ${sqlite_amalgamation_SOURCE_DIR}) - target_sources(snowplow PUBLIC ${sqlite_amalgamation_SOURCE_DIR}/sqlite3.c) + target_include_directories(snowplow PRIVATE ${sqlite_amalgamation_SOURCE_DIR}) + target_sources(snowplow PRIVATE ${sqlite_amalgamation_SOURCE_DIR}/sqlite3.c) endif() find_package(Threads) @@ -112,7 +112,20 @@ if (NOT APPLE AND NOT WIN32) endif () include(CMakePackageConfigHelpers) -if(SNOWPLOW_USE_EXTERNAL_SQLITE AND SNOWPLOW_USE_EXTERNAL_JSON) + +set(create_install_target ON) + +if(NOT SNOWPLOW_USE_EXTERNAL_JSON) + set(create_install_target OFF) + message(STATUS "Install target not added because SNOWPLOW_USE_EXTERNAL_JSON is OFF") +endif() + +if(NOT BUILD_SHARED_LIBS AND NOT SNOWPLOW_USE_EXTERNAL_SQLITE) + set(create_install_target OFF) + message(STATUS "Install target not added because SNOWPLOW_USE_EXTERNAL_SQLITE is OFF while building a static library (BUILD_SHARED_LIBS is OFF)") +endif() + +if(create_install_target) install(TARGETS snowplow EXPORT snowplow-export RUNTIME DESTINATION bin ARCHIVE DESTINATION lib @@ -146,8 +159,6 @@ if(SNOWPLOW_USE_EXTERNAL_SQLITE AND SNOWPLOW_USE_EXTERNAL_JSON) install(FILES ${SNOWPLOW_CMAKE_DIR}/FindLibUUID.cmake DESTINATION lib/cmake/snowplow) endif() -else() - message(STATUS "Install target not added because SNOWPLOW_USE_EXTERNAL_SQLITE or SNOWPLOW_USE_EXTERNAL_JSON is OFF") endif() if(SNOWPLOW_BUILD_TESTS)