Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCPKG as primary dependency manager (and internal submodules as optional) #397

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive
fetch-depth: 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

- name: Run version extraction script and set environment variable
id: set-version
run: |
Expand All @@ -28,8 +29,11 @@ jobs:
- run: sudo apt install -y valgrind uuid-dev
- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive
fetch-depth: 0
- run: sh cmake/GenerateMake.sh
- run: cmake --build . --target help
working-directory: ./build
- run: cmake --build . --target lib3mf_memcheck
working-directory: ./build

Expand All @@ -43,7 +47,8 @@ jobs:
- run: sudo apt install -y uuid-dev
- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive
fetch-depth: 0
- run: mkdir -p build
- run: zip -r build/bindings.zip Autogenerated/Bindings
- name: Archive bindings
Expand Down Expand Up @@ -117,7 +122,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive
fetch-depth: 0
- run: sh cmake/GenerateMake.sh
- run: cmake --build .
working-directory: ./build
Expand Down Expand Up @@ -148,7 +154,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive
fetch-depth: 0
- run: sh cmake/GenerateMake.sh "Debug"
- run: cmake --build .
working-directory: ./build
Expand All @@ -166,7 +173,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive
fetch-depth: 0
- name: Install Prerequisites
run: |
brew install lcov
Expand Down Expand Up @@ -196,7 +204,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive
fetch-depth: 0
- run: ./cmake/GenerateVS2019.bat
- run: cmake --build . --config Release
working-directory: ./build
Expand Down Expand Up @@ -231,7 +240,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive
fetch-depth: 0
- run: ./cmake/GenerateVS2019.bat
- run: cmake --build . --config Debug
working-directory: ./build
Expand All @@ -256,7 +266,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive
fetch-depth: 0
- run: ./cmake/GenerateVS2019_32bit.bat
- run: cmake --build . --config Release
working-directory: ./build_32bit
Expand All @@ -279,7 +290,8 @@ jobs:
- run: choco install mingw -y
- uses: actions/checkout@v4
with:
submodules: true
submodules: recursive
fetch-depth: 0
- run: ./cmake/GenerateMinGW.bat
- run: cmake --build .
working-directory: ./build
Expand Down Expand Up @@ -417,6 +429,11 @@ jobs:
./Examples/CppDynamic/GenerateVS2019.bat
cd Examples/CppDynamic/build
cmake --build . --config Release
dir
dir ../
dir ../../
dir Release
dir x64
./Release/Example_ExtractInfo.exe ../../Files/Helix.3mf
- name: Build Cpp
run: |
Expand Down
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
[submodule "submodules/googletest"]
path = submodules/googletest
url = https://github.com/google/googletest.git

[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git
shallow = false
2 changes: 2 additions & 0 deletions CI/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN \
glibc-langpack-en \
tar \
gzip \
git \
zip \
rpm-build \
${GCCTOOLSET} \
Expand All @@ -38,6 +39,7 @@ RUN ldd --version
RUN cmake --version
RUN cmake3 --version
RUN gcc --version
RUN g++ --version


ADD . lib3mf-repo
Expand Down
91 changes: 65 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ cmake_policy(SET CMP0048 NEW)


set_property(GLOBAL PROPERTY USE_FOLDERS ON)
option(USE_PACKAGED_SUBMODULES OFF)

if (APPLE)
message(STATUS "Detected Apple platform. Forcing USE_PACKAGED_SUBMODULES=ON (Universal binary issue)")
set(USE_PACKAGED_SUBMODULES ON CACHE BOOL "Use packaged submodules" FORCE)
endif()

# Conditionally set the vcpkg toolchain file if USE_PACKAGED_SUBMODULES is OFF
if (USE_PACKAGED_SUBMODULES)
message("USE_PACKAGED_SUBMODULES is ON")
option(USE_INCLUDED_ZLIB "Use included zlib" ON)
option(USE_INCLUDED_LIBZIP "Use included libzip" ON)
option(USE_INCLUDED_SSL "Use included libressl" ON)
else()
message("USE_PACKAGED_SUBMODULES is OFF")
if (CMAKE_GENERATOR MATCHES "MinGW")
set(VCPKG_TARGET_TRIPLET "x64-mingw-dynamic")
endif ()
if (EXISTS "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
message("Using VCPKG Toolchain")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
endif()
option(USE_INCLUDED_ZLIB "Use included zlib" OFF)
option(USE_INCLUDED_LIBZIP "Use included libzip" OFF)
option(USE_INCLUDED_SSL "Use included libressl" OFF)
endif()


include(GNUInstallDirs)

Expand All @@ -28,9 +55,6 @@ set(CMAKE_INSTALL_BINDIR bin CACHE PATH "directory for installing binary files")
set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "directory for installing library files")
set(CMAKE_INSTALL_INCLUDEDIR include/lib3mf CACHE PATH "directory for installing header files")

option(USE_INCLUDED_ZLIB "Use included zlib" ON)
option(USE_INCLUDED_LIBZIP "Use included libzip" ON)
option(USE_INCLUDED_SSL "Use included libressl" ON)
option(BUILD_FOR_CODECOVERAGE "Build for code coverage analysis" OFF)
option(STRIP_BINARIES "Strip binaries (on non-apple)" ON)
option(USE_PLATFORM_UUID "Use UUID geneator that is provided by the OS (always ON for Windows)" OFF)
Expand Down Expand Up @@ -144,23 +168,22 @@ endif()

SOURCE_GROUP("Source Files\\Autogenerated" FILES ${ACT_GENERATED_SOURCE})


file(GLOB
LIBS_INCLUDE
LIST_DIRECTORIES true
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/*/Include
)
list(FILTER LIBS_INCLUDE EXCLUDE REGEX "zlib|libzip|libressl")
target_include_directories(${PROJECT_NAME} PRIVATE ${LIBS_INCLUDE})

# allow FASTFLOAT_ALLOWS_LEADING_PLUS
add_definitions(-DFASTFLOAT_ALLOWS_LEADING_PLUS=1)
if (USE_PACKAGED_SUBMODULES)
file(GLOB
LIBS_INCLUDE
LIST_DIRECTORIES true
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/*/Include
)
list(FILTER LIBS_INCLUDE EXCLUDE REGEX "zlib|libzip|libressl")
target_include_directories(${PROJECT_NAME} PRIVATE ${LIBS_INCLUDE})
endif ()

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR_AUTOGENERATED}/Source)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include/API)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Include)

if (USE_INCLUDED_LIBZIP)
# Libzip
if (USE_PACKAGED_SUBMODULES)
# Something goes here to check if submodules exist and initialize the submodules if it does not
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/libzip/Include)
if(MSVC)
Expand Down Expand Up @@ -197,25 +220,41 @@ if (USE_INCLUDED_LIBZIP)
target_compile_options(${PROJECT_NAME} PRIVATE "-DHAVE_STRCASECMP")
target_compile_options(${PROJECT_NAME} PRIVATE "-DHAVE_UNISTD_H")
endif()

else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBZIP REQUIRED libzip)
target_link_libraries(${PROJECT_NAME} ${LIBZIP_LIBRARIES})
find_package(LIBZIP REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE libzip::zip)
endif()


if (USE_INCLUDED_ZLIB)
# ZLIB
if (USE_PACKAGED_SUBMODULES)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/zlib/Include)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZLIB REQUIRED zlib)
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES})
find_package(ZLIB REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ZLIB::ZLIB)
endif()


target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/submodules/fast_float/include)

# Fast float
if (USE_PACKAGED_SUBMODULES)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/submodules/fast_float/include)
add_definitions(-DFASTFLOAT_ALLOWS_LEADING_PLUS=1)
else()
find_package(FastFloat CONFIG REQUIRED)
add_definitions(-DFASTFLOAT_ALLOWS_LEADING_PLUS=1)
target_link_libraries(${PROJECT_NAME} PRIVATE FastFloat::fast_float)
endif ()

# Base 64
if(NOT USE_PACKAGED_SUBMODULES)
find_path(CPP_BASE64_INCLUDE_DIRS "cpp-base64/base64.cpp")
include_directories("${CPP_BASE64_INCLUDE_DIRS}/cpp-base64")
set(BASE64_SRC
${CPP_BASE64_INCLUDE_DIRS}/cpp-base64/base64.h
${CPP_BASE64_INCLUDE_DIRS}/cpp-base64/base64.cpp)
message("BASE64_SRC" ${BASE64_SRC})
# Append BASE64_SRC to the target
target_sources(${PROJECT_NAME} PRIVATE ${BASE64_SRC})
endif ()

set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" IMPORT_PREFIX "" )
# This makes sure symbols are exported
Expand Down
2 changes: 1 addition & 1 deletion Include/Common/NMR_StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ and Exception-safe
#include "Common/NMR_Types.h"
#include "Common/NMR_Local.h"

#include <fast_float.h>
#include <fast_float/fast_float.h>

#include <string>
#include <string.h>
Expand Down
13 changes: 9 additions & 4 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@

if (USE_INCLUDED_LIBZIP)
# libzip related sources
if (USE_PACKAGED_SUBMODULES)
file(GLOB LIBZIP_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "Libraries/libzip/Source/*.c")
if (UNIX)
file(GLOB LIBZIP_FILES_PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "Libraries/libzip/Source/unix/*.c")
else()
file(GLOB LIBZIP_FILES_PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "Libraries/libzip/Source/win/*.c")
endif()
endif()
endif ()

if (USE_INCLUDED_ZLIB)
# Zlib related sources
if (USE_PACKAGED_SUBMODULES)
file(GLOB ZLIB_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "Libraries/zlib/Source/*.c")
endif()

file (GLOB CPPBASE64_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "Libraries/cpp-base64/Source/*.cpp")
# Base 64 related sources
if(USE_PACKAGED_SUBMODULES)
file (GLOB CPPBASE64_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "Libraries/cpp-base64/Source/*.cpp")
endif ()

# sources
set(SRCS_PLATFORM
Expand Down
7 changes: 5 additions & 2 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
enable_testing()

if (USE_INCLUDED_SSL)
if (USE_PACKAGED_SUBMODULES)
message("Using packaged LibreSSL")
SET(LIBRESSL_APPS OFF CACHE BOOL "" FORCE)
SET(LIBRESSL_TESTS OFF CACHE BOOL "" FORCE)
SET(ENABLE_ASM OFF CACHE BOOL "" FORCE)
Expand All @@ -10,9 +11,11 @@ if (USE_INCLUDED_SSL)
SET_TARGET_PROPERTIES(crypto PROPERTIES FOLDER LibreSSL)
SET_TARGET_PROPERTIES(ssl_obj PROPERTIES FOLDER LibreSSL)
SET_TARGET_PROPERTIES(crypto_obj PROPERTIES FOLDER LibreSSL)
else()
message("Using vcpkg-managed LibreSSL")
find_package(LibreSSL REQUIRED CONFIG)
endif()


add_definitions( -DTESTFILESPATH="${CMAKE_CURRENT_SOURCE_DIR}/TestFiles/")
add_definitions( -DLTESTFILESPATH=L"${CMAKE_CURRENT_SOURCE_DIR}/TestFiles/")
add_definitions( -DLOUTFILESPATH=L"${CMAKE_BINARY_DIR}/")
Expand Down
24 changes: 19 additions & 5 deletions Tests/CPP_Bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

SET(TESTNAME "Test_CPP_Bindings")

file(GLOB GTEST_SRC_FILES "${CMAKE_SOURCE_DIR}/Libraries/googletest/Source/*cc")
if (USE_PACKAGED_SUBMODULES)
file(GLOB GTEST_SRC_FILES "${CMAKE_SOURCE_DIR}/Libraries/googletest/Source/*cc")
else()
find_package(GTest CONFIG REQUIRED)
endif ()


set(SRCS_UNITTEST
./Source/AllTests.cpp
Expand Down Expand Up @@ -49,22 +54,31 @@ set(STARTUPPROJECT ${TESTNAME})

target_include_directories(${TESTNAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Include
${CMAKE_SOURCE_DIR}/Libraries/googletest/Include
${CMAKE_CURRENT_SOURCE_DIR}/../../Libraries/libressl/include
${CMAKE_CURRENT_SOURCE_DIR_AUTOGENERATED}/Bindings/Cpp
)

if(USE_PACKAGED_SUBMODULES)
target_include_directories(${TESTNAME} PRIVATE
${CMAKE_SOURCE_DIR}/Libraries/googletest/Include
${CMAKE_CURRENT_SOURCE_DIR}/../../Libraries/libressl/include
)
endif ()

# pthreads Needed for googletest
if (LINUX)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${TESTNAME} PRIVATE Threads::Threads)
endif()

target_link_libraries(${TESTNAME} PRIVATE ${PROJECT_NAME} ssl crypto)
if (USE_PACKAGED_SUBMODULES)
target_link_libraries(${TESTNAME} PRIVATE ${PROJECT_NAME} ssl crypto)
else()
target_link_libraries(${TESTNAME} PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main LibreSSL::SSL LibreSSL::Crypto ${PROJECT_NAME})
endif ()

if (WIN32)
target_link_libraries(${TESTNAME} PRIVATE ws2_32)
target_link_libraries(${TESTNAME} PRIVATE ws2_32)
endif()


Expand Down
1 change: 1 addition & 0 deletions vcpkg
Submodule vcpkg added at 5e5d0e
Loading
Loading