diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 946bb059d..fa241b483 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,8 @@ jobs: steps: - uses: actions/checkout@v4 with: - submodules: true + submodules: recursive + fetch-depth: 0 - name: Run version extraction script and set environment variable id: set-version run: | @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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: | diff --git a/.gitmodules b/.gitmodules index db3aef4bb..ea4649024 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CI/Dockerfile b/CI/Dockerfile index efedb0943..ce8df9fe9 100644 --- a/CI/Dockerfile +++ b/CI/Dockerfile @@ -13,6 +13,7 @@ RUN \ glibc-langpack-en \ tar \ gzip \ + git \ zip \ rpm-build \ ${GCCTOOLSET} \ @@ -38,6 +39,7 @@ RUN ldd --version RUN cmake --version RUN cmake3 --version RUN gcc --version +RUN g++ --version ADD . lib3mf-repo diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e1911e52..f97a87e69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/Include/Common/NMR_StringUtils.h b/Include/Common/NMR_StringUtils.h index 4cafe3a76..b32bc76a1 100644 --- a/Include/Common/NMR_StringUtils.h +++ b/Include/Common/NMR_StringUtils.h @@ -37,7 +37,7 @@ and Exception-safe #include "Common/NMR_Types.h" #include "Common/NMR_Local.h" -#include +#include #include #include diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 27973c844..497d6964d 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -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 diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index e4352882a..5b393eea9 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -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) @@ -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}/") diff --git a/Tests/CPP_Bindings/CMakeLists.txt b/Tests/CPP_Bindings/CMakeLists.txt index 63daeeff4..dd9bb00a2 100644 --- a/Tests/CPP_Bindings/CMakeLists.txt +++ b/Tests/CPP_Bindings/CMakeLists.txt @@ -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 @@ -49,11 +54,16 @@ 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) @@ -61,10 +71,14 @@ 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() diff --git a/vcpkg b/vcpkg new file mode 160000 index 000000000..5e5d0e1cd --- /dev/null +++ b/vcpkg @@ -0,0 +1 @@ +Subproject commit 5e5d0e1cd7785623065e77eff011afdeec1a3574 diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 000000000..01692f77d --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,41 @@ +{ + "name": "lib3mf", + "version": "2.4.0", + "description": "lib3mf is an implementation of the 3D Manufacturing Format file standard", + "homepage": "https://github.com/3MFConsortium/lib3mf", + "license": "BSD-2-Clause", + "supports": "(windows & (x86 | x64) & !static & !staticcrt) | (linux & x64) | (osx & (x64 | arm64))", + "builtin-baseline": "5e5d0e1cd7785623065e77eff011afdeec1a3574", + "dependencies": [ + "cpp-base64", + { + "name": "fast-float", + "version>=": "6.1.6" + }, + { + "name": "libzip", + "default-features": false, + "version>=": "1.10.1" + }, + { + "name": "zlib", + "version>=": "1.3.1" + }, + { + "name" : "libressl", + "version>=": "3.9.2#2" + }, + { + "name": "gtest", + "version>=": "1.15.2" + }, + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} \ No newline at end of file