Skip to content

Commit

Permalink
[skip ci] Switch to VCPKG as a dependency manager for lib3mf project …
Browse files Browse the repository at this point in the history
…+ CMake refactoring begins (Tests do not work)
  • Loading branch information
vijaiaeroastro committed Oct 20, 2024
1 parent 5abad20 commit cc589ce
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "submodules/googletest"]
path = submodules/googletest
url = https://github.com/google/googletest.git
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git
51 changes: 32 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
cmake_minimum_required (VERSION 3.0)
cmake_minimum_required (VERSION 3.5)

cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0048 NEW)


set_property(GLOBAL PROPERTY USE_FOLDERS ON)

include(GNUInstallDirs)
# Automatically set the vcpkg toolchain file if vcpkg exists as a submodule
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()

# Define Version
set(LIB3MF_VERSION_MAJOR 2) # increase on every backward-compatibility breaking change of the API
Expand All @@ -17,15 +21,18 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment ve
project(lib3mf
VERSION ${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}
DESCRIPTION "An implementation of the 3D Manufacturing Format file standard"
LANGUAGES CXX C
)

include(GNUInstallDirs)

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(USE_INCLUDED_ZLIB "Use included zlib" OFF)
option(USE_INCLUDED_LIBZIP "Use included libzip" OFF)
option(USE_INCLUDED_SSL "Use included libressl" OFF)
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 @@ -116,13 +123,6 @@ add_library(${PROJECT_NAME} SHARED ${SRCS_COMMON} ${HDRS_COMMON}
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)
Expand Down Expand Up @@ -170,20 +170,33 @@ if (USE_INCLUDED_LIBZIP)
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)
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()

#devendor base64
# Include the directory for header files
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})

#devendor FastFloat
find_package(FastFloat CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE FastFloat::fast_float)

set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" IMPORT_PREFIX "" )
# This makes sure symbols are exported
target_compile_options(${PROJECT_NAME} PRIVATE "-D__LIB3MF_EXPORTS")
Expand Down Expand Up @@ -237,7 +250,7 @@ install(TARGETS ${PROJECT_NAME}
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR_AUTOGENERATED}/Bindings DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

#########################################################
option(LIB3MF_TESTS "Switch whether the tests of lib3mf should be build" ON)
option(LIB3MF_TESTS "Switch whether the tests of lib3mf should be build" OFF)
message("LIB3MF_TESTS ... " ${LIB3MF_TESTS})

if(LIB3MF_TESTS)
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
1 change: 0 additions & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ if (USE_INCLUDED_ZLIB)
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")

# sources
set(SRCS_PLATFORM
Expand Down
3 changes: 3 additions & 0 deletions cmake/lib3mfConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# lib3mfConfig.cmake
include(CMakeFindDependencyMacro)
find_dependency(libzip)
find_dependency(ZLIB)

if(VCPKG_TOOLCHAIN)
message("Lib3MF - VCPKG Tool Chain")
Expand Down
1 change: 1 addition & 0 deletions vcpkg
Submodule vcpkg added at d567b6
22 changes: 22 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "lib3mf",
"version": "2.3.2",
"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))",
"dependencies": [
"cpp-base64",
"fast-float",
"libzip",
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
"zlib"
]
}

0 comments on commit cc589ce

Please sign in to comment.