Skip to content

Commit

Permalink
<feat>(project): project adapt vcpkg construct.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay committed Nov 20, 2023
1 parent f9de0c4 commit 0a0249e
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ deps
.vscode/
.idea/
.DS_Store
vcpkg_installed**
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg
119 changes: 55 additions & 64 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,43 @@ cmake_minimum_required(VERSION 3.14)

set(CMAKE_CXX_STANDARD 20)

if(NOT MSVC)
set(CMAKE_CXX_FLAGS "-pthread -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -fexceptions")
endif()

set(CMAKE_OSX_DEPLOYMENT_TARGET "13" CACHE STRING "Minimum OS X deployment version")

# export windows dll symbol
if(WIN32)
message(STATUS "Compile on Windows")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "ON")
endif()
#set(CMAKE_OSX_DEPLOYMENT_TARGET "13" CACHE STRING "Minimum OS X deployment version")

# URL_BASE download domain name
include(FetchContent)

if(NOT DEFINED URL_BASE)
if (NOT DEFINED URL_BASE)
set(URL_BASE "github.com")
endif ()

# set(URL_BASE "github.com.cnpmjs.org")
endif()

# include(FetchContent)
# set(BCOS_CMAKE_SCRIPTS_DIR ${CMAKE_CURRENT_BINARY_DIR}/bcos-cmake-scripts)
# FetchContent_Declare(bcos-cmake-scripts
# GIT_REPOSITORY https://${URL_BASE}/FISCO-BCOS/bcos-cmake-scripts.git
# GIT_TAG 364f603f4ec112cb79840ea4026243399d7c419b
# SOURCE_DIR ${BCOS_CMAKE_SCRIPTS_DIR}
# )
# FetchContent_MakeAvailable(bcos-cmake-scripts)
set(JAVA_SDK_JNI_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake" CACHE PATH "The cmake path for the library")

# list(APPEND CMAKE_MODULE_PATH ${BCOS_CMAKE_SCRIPTS_DIR})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${JAVA_SDK_JNI_CMAKE_DIR})

# include hunter
include(Options)
set(ARCH_NATIVE OFF)

if("${ARCHITECTURE}" MATCHES "aarch64")
if ("${ARCHITECTURE}" MATCHES "aarch64")
set(ARCH_NATIVE ON)
endif()
endif ()

include(HunterGate)
HunterGate(
URL "https://${URL_BASE}/FISCO-BCOS/hunter/archive/2b5b25ecffaba74393740bf0b8758c4e8d9297cf.tar.gz"
SHA1 "5d8365a327be260cf24d2b125a71ee7069aca28f"
FILEPATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake"
)
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
find_package(Git REQUIRED)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- vcpkg WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")
endif ()

# project name
project(bcos-c-sdk VERSION "3.4.0")
project(bcos-c-sdk VERSION "3.6.0")

# Debug, Release, RelWithDebInfo, MinSizeRel
if(NOT CMAKE_BUILD_TYPE)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

include_directories(${CMAKE_INSTALL_INCLUDEDIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include(InstallDependencies)
endif ()

# basic settings
include(Options)
Expand All @@ -91,15 +67,28 @@ include(InstallConfig)

# install the include files for hash
include(InstallInclude)
include(IncludeDirectories)
include(GNUInstallDirs)

find_package(Boost COMPONENTS log serialization)
find_package(OpenSSL REQUIRED)
find_package(Microsoft.GSL CONFIG REQUIRED)
find_package(fmt REQUIRED)
find_package(TBB REQUIRED)
find_package(unofficial-secp256k1 CONFIG REQUIRED)
find_package(jsoncpp CONFIG REQUIRED)
find_package(wedprcrypto REQUIRED)
find_package(HSM-CRYPTO REQUIRED)
find_package(fiscobcos REQUIRED)

file(GLOB_RECURSE SOURCES "bcos-c-sdk/*.h" "bcos-c-sdk/*.cpp" "bcos-c-sdk/*.c")

# rust static library linking requirements for macos
if(APPLE)
if (APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -framework Security -framework Foundation")
else()
else ()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed -ldl")
endif()
endif ()

# static lib
set(BCOS_C_SDK_STATIC_TARGET "bcos-c-sdk-static")
Expand All @@ -108,40 +97,42 @@ set(BCOS_C_SDK_STATIC_TARGET "bcos-c-sdk-static")
set(BCOS_C_SDK_TARGET "bcos-c-sdk")

# add suffix for arm
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64")
if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64")
message(STATUS "Building arm architecture, CMAKE_HOST_SYSTEM_PROCESSOR => ${CMAKE_HOST_SYSTEM_PROCESSOR}")
set(BCOS_C_SDK_TARGET "bcos-c-sdk-aarch64")
set(BCOS_C_SDK_STATIC_TARGET "bcos-c-sdk-static-aarch64")
endif()
endif ()

add_library(${BCOS_C_SDK_STATIC_TARGET} ${SOURCES})
target_link_libraries(${BCOS_C_SDK_STATIC_TARGET} PUBLIC bcos-cpp-sdk::bcos-cpp-sdk)
target_include_directories(${BCOS_C_SDK_STATIC_TARGET} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
target_link_libraries(${BCOS_C_SDK_STATIC_TARGET} PUBLIC fiscobcos::bcos-cpp-sdk)

add_library(${BCOS_C_SDK_TARGET} SHARED ${SOURCES})
target_link_libraries(${BCOS_C_SDK_TARGET} PUBLIC bcos-cpp-sdk::bcos-cpp-sdk)
target_include_directories(${BCOS_C_SDK_TARGET} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> $<INSTALL_INTERFACE:include/bcos-cpp-sdk>)
target_link_libraries(${BCOS_C_SDK_TARGET} PUBLIC fiscobcos::bcos-cpp-sdk)

add_dependencies(${BCOS_C_SDK_STATIC_TARGET} BuildInfo.h)
add_dependencies(${BCOS_C_SDK_TARGET} BuildInfo.h)

# build sample exec
if(BUILD_SAMPLE)
if (BUILD_SAMPLE)
add_subdirectory(sample)
endif()
endif ()

# build sample exec
if(BUILD_JNI)
if (BUILD_JNI)
# find JNI
find_package(JNI REQUIRED)
include_directories(${JNI_INCLUDE_DIRS})
add_subdirectory(bindings/java/jni/src/main/c)
endif()
add_subdirectory(${CMAKE_SOURCE_DIR}/bindings/java/jni/src/main/c)
endif ()

# ut and binary exe
if (TESTS)
enable_testing()
set(CTEST_OUTPUT_ON_FAILURE TRUE)
add_subdirectory(test)
endif()
endif ()

# for code coverage
if (COVERAGE)
Expand All @@ -151,19 +142,19 @@ endif ()

# SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
install(
TARGETS ${BCOS_C_SDK_TARGET}
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
TARGETS ${BCOS_C_SDK_TARGET}
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)

install(
TARGETS ${BCOS_C_SDK_STATIC_TARGET}
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
TARGETS ${BCOS_C_SDK_STATIC_TARGET}
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
24 changes: 24 additions & 0 deletions bindings/java/jni/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.gradle/
.idea/
log/
build/
dist/
.vscode/
.settings/**
java-sdk.iml

## eclipse ##
.classpath
.project
*/.settings/**
out/
*/dist/**
*/build/**
conf/

## integration test files
gradle.properties
gpg.gpg

## macOS
.DS_Store
9 changes: 2 additions & 7 deletions bindings/java/jni/src/main/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
# limitations under the License.
# ------------------------------------------------------------------------------

set(JAVA_SDK_JNI_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake" CACHE PATH "The cmake path for the library")

# list(APPEND CMAKE_MODULE_PATH ${BCOS_CMAKE_SCRIPTS_DIR})
list(APPEND CMAKE_MODULE_PATH ${JAVA_SDK_JNI_CMAKE_DIR})

# Debug, Release, RelWithDebInfo, MinSizeRel
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
Expand Down Expand Up @@ -53,10 +48,10 @@ else()
endif()

add_library(${FISCO_BCOS_JNI_TARGET} SHARED ${SOURCES})
target_link_libraries(${FISCO_BCOS_JNI_TARGET} PUBLIC wedpr-crypto::crypto wedpr-crypto::extend-crypto bcos-cpp-sdk::bcos-cpp-sdk ${BCOS_C_SDK_STATIC_TARGET})
target_link_libraries(${FISCO_BCOS_JNI_TARGET} PUBLIC wedprcrypto::crypto wedprcrypto::zkp fiscobcos::bcos-cpp-sdk ${BCOS_C_SDK_STATIC_TARGET})

add_library(${FISCO_BCOS_JNI_STATIC_TARGET} ${SOURCES})
target_link_libraries(${FISCO_BCOS_JNI_STATIC_TARGET} PUBLIC wedpr-crypto::crypto wedpr-crypto::extend-crypto bcos-cpp-sdk::bcos-cpp-sdk ${BCOS_C_SDK_STATIC_TARGET})
target_link_libraries(${FISCO_BCOS_JNI_STATIC_TARGET} PUBLIC wedprcrypto::crypto wedprcrypto::zkp fiscobcos::bcos-cpp-sdk ${BCOS_C_SDK_STATIC_TARGET})

if(BUILD_EXEC_TEST)
add_subdirectory(test/exe)
Expand Down
37 changes: 29 additions & 8 deletions cmake/CompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
# File: CompilerSettings.cmake
# Function: Common cmake file for setting compilation environment variables
# ------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 20)
set(Boost_NO_WARN_NEW_VERSIONS ON)
message(STATUS "COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")

# export windows dll symbol
if(WIN32)
message(STATUS "Compile on Windows")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "ON")
endif()

if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
find_program(CCACHE_PROGRAM ccache)
Expand All @@ -27,6 +36,7 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "/usr/bin/time")
# set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "/usr/bin/time")
# Use ISO C++17 standard language.
set(CMAKE_CXX_FLAGS "-pthread -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -fexceptions")
set(CMAKE_CXX_FLAGS "-pthread -fPIC -fexceptions")
# set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# Enables all the warnings about constructions that some users consider questionable,
Expand All @@ -37,13 +47,21 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
add_compile_options(-Wall)
add_compile_options(-pedantic)
add_compile_options(-Wextra)
# add_compile_options(-Wno-unused-variable)
# add_compile_options(-Wno-unused-parameter)
# add_compile_options(-Wno-unused-function)
# add_compile_options(-Wno-missing-field-initializers)
# Disable warnings about unknown pragmas (which is enabled by -Wall).
add_compile_options(-Wno-unknown-pragmas)

# Ignore warnings
add_compile_options(-Wno-unused-parameter)
add_compile_options(-Wno-unused-variable)
add_compile_options(-Wno-error=unknown-pragmas)
add_compile_options(-Wno-error=deprecated-declarations)
add_compile_options(-fno-omit-frame-pointer)
add_compile_options(-Wno-error=strict-aliasing)

if(NOT APPLE)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
add_compile_options(-fvisibility=hidden)
add_compile_options(-fvisibility-inlines-hidden)
endif()

# for boost json spirit
add_compile_options(-DBOOST_SPIRIT_THREADSAFE)
# for tbb, TODO: https://software.intel.com/sites/default/files/managed/b2/d2/TBBRevamp.pdf
Expand Down Expand Up @@ -89,8 +107,8 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA

# Additional GCC-specific compiler settings.
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
# Check that we've got GCC 7.0 or newer.
set(GCC_MIN_VERSION "7.0")
# Check that we've got GCC 10.0 or newer.
set(GCC_MIN_VERSION "10.0")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (NOT (GCC_VERSION VERSION_GREATER ${GCC_MIN_VERSION} OR GCC_VERSION VERSION_EQUAL ${GCC_MIN_VERSION}))
Expand Down Expand Up @@ -137,6 +155,7 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
endif()
endif ()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
add_compile_definitions(NOMINMAX)

# Only support visual studio 2017 and visual studio 2019
set(MSVC_MIN_VERSION "1914") # VS2017 15.7, for full-ish C++17 support
Expand Down Expand Up @@ -177,4 +196,6 @@ if(APPLE)
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ldl")
endif()
message("CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
message("CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY ON)
9 changes: 9 additions & 0 deletions cmake/IncludeDirectories.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")
include_directories(${CMAKE_INSTALL_INCLUDEDIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/bcos-c-sdk)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
include_directories(${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include)
1 change: 1 addition & 0 deletions vcpkg
Submodule vcpkg added at 51b14c
16 changes: 16 additions & 0 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"registries": [
{
"kind": "git",
"repository": "https://github.com/FISCO-BCOS/registry",
"baseline": "38007689d8085c2659c42a2b9919abc78de68ffd",
"packages": [
"openssl",
"hsm-crypto",
"fisco-bcos-cpp-sdk",
"wedprcrypto",
"secp256k1"
]
}
]
}
Loading

0 comments on commit 0a0249e

Please sign in to comment.