Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Hunterize Koinos Types #141

Merged
merged 2 commits into from
Mar 2, 2021
Merged
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
80 changes: 55 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,24 @@ HunterGate(
LOCAL
)

project( koinos-types )
project(koinos_types VERSION 0.1.0 LANGUAGES CXX)

#
# CONFIGURATION
#
include(GNUInstallDirs)

set(KOINOS_LIB_TARGET_NAME ${PROJECT_NAME})
set(KOINOS_LIB_TARGET_SHORT_NAME "types")
set(KOINOS_LIB_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" CACHE INTERNAL "")
set(KOINOS_LIB_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(KOINOS_LIB_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(KOINOS_LIB_CMAKE_CONFIG_TEMPLATE "cmake/config.cmake.in")
set(KOINOS_LIB_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(KOINOS_LIB_CMAKE_VERSION_CONFIG_FILE "${KOINOS_LIB_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(KOINOS_LIB_CMAKE_PROJECT_CONFIG_FILE "${KOINOS_LIB_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
set(KOINOS_LIB_CMAKE_PROJECT_TARGETS_FILE "${KOINOS_LIB_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
set(KOINOS_LIB_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." OFF)

Expand All @@ -54,31 +71,10 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror" )
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror" )

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas" )
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas" )

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")

set(PYTHON_BINARY "python3" CACHE STRING "The default python to invoke")

option( BUILD_KOINOS_TYPES_TESTS "Build Koinos-Types unit tests" ON )
option( INSTALL_KOINOS_TYPES_HEADERS "Install Koinos-Types headers" OFF )

set(Boost_USE_STATIC_LIBS ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(Boost_NO_BOOST_CMAKE ON)
if( NOT( Boost_VERSION_MACRO LESS 106900 ) )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
endif()

if(${CMAKE_GENERATOR} MATCHES "Xcode")
set(CMAKE_XCODE_GENERATE_SCHEME YES)
endif()
set(PYTHON_BINARY "python3" CACHE STRING "The default python to invoke")

if (NOT TARGET coverage)
if (COVERAGE)
Expand All @@ -98,6 +94,40 @@ hunter_add_package(nlohmann_json)
add_subdirectory(lang)
add_subdirectory(programs)

if( BUILD_KOINOS_TYPES_TESTS )
if(BUILD_TESTS)
add_subdirectory(tests)
endif()

# Install a pkg-config file, so other tools can find this.
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
)

#
# INSTALL
# install header files, generate and install cmake config files for find_package()
#
include(CMakePackageConfigHelpers)

configure_file(
"cmake/${PROJECT_NAME}ConfigVersion.cmake.in"
${KOINOS_LIB_CMAKE_VERSION_CONFIG_FILE}
@ONLY
)
configure_file(
${KOINOS_LIB_CMAKE_CONFIG_TEMPLATE}
${KOINOS_LIB_CMAKE_PROJECT_CONFIG_FILE}
@ONLY
)

install(
FILES ${KOINOS_LIB_CMAKE_PROJECT_CONFIG_FILE} ${KOINOS_LIB_CMAKE_VERSION_CONFIG_FILE}
DESTINATION ${KOINOS_LIB_CONFIG_INSTALL_DIR}
)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION ${KOINOS_LIB_PKGCONFIG_INSTALL_DIR}
)

4 changes: 2 additions & 2 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ mkdir build
pushd build

if [ "$RUN_TYPE" = "test" ]; then
cmake -DCMAKE_BUILD_TYPE=Release -DHUNTER_RUN_UPLOAD=ON ..
cmake -DCMAKE_BUILD_TYPE=Release -DHUNTER_RUN_UPLOAD=ON -DBUILD_TESTS=ON ..
cmake --build . --config Release --parallel 3
elif [ "$RUN_TYPE" = "coverage" ]; then
cmake -DCMAKE_BUILD_TYPE=Debug -DHUNTER_RUN_UPLOAD=ON -DCOVERAGE=ON ..
cmake -DCMAKE_BUILD_TYPE=Debug -DHUNTER_RUN_UPLOAD=ON -DCOVERAGE=ON -DBUILD_TESTS=ON ..
cmake --build . --config Debug --parallel 3 --target coverage --target golang

popd
Expand Down
16 changes: 16 additions & 0 deletions cmake/config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include(FindPackageHandleStandardArgs)
set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE})
find_package_handle_standard_args(@PROJECT_NAME@ CONFIG_MODE)

if(NOT TARGET Koinos::@KOINOS_LIB_TARGET_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@KOINOS_LIB_TARGETS_EXPORT_NAME@.cmake")
if((NOT TARGET @KOINOS_LIB_TARGET_NAME@) AND
(NOT @PROJECT_NAME@_FIND_VERSION OR
@PROJECT_NAME@_FIND_VERSION VERSION_LESS 3.2.0))
add_library(@KOINOS_LIB_TARGET_NAME@ INTERFACE IMPORTED GLOBAL)
set_target_properties(@KOINOS_LIB_TARGET_NAME@ PROPERTIES
INTERFACE_LINK_LIBRARIES Koinos::@KOINOS_LIB_TARGET_NAME@
)
endif()
add_library(Koinos::@KOINOS_LIB_TARGET_SHORT_NAME@ ALIAS @KOINOS_LIB_TARGET_NAME@)
endif()
67 changes: 67 additions & 0 deletions cmake/koinos_typesConfigVersion.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# This is a basic version file for the Config-mode of find_package().
# It is used by write_basic_package_version_file() as input file for configure_file()
# to create a version-file which can be installed along a config.cmake file.
#
# The created file sets PACKAGE_VERSION_EXACT if the current version string and
# the requested version string are exactly the same and it sets
# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version,
# but only if the requested major version is the same as the current one.
# The variable CVF_VERSION must be set before calling configure_file().


set(PACKAGE_VERSION "@CVF_VERSION@")

if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

if("@CVF_VERSION@" MATCHES "^([0-9]+)\\.")
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
else()
set(CVF_VERSION_MAJOR "@CVF_VERSION@")
endif()

if(PACKAGE_FIND_VERSION_RANGE)
# both endpoints of the range must have the expected major version
math (EXPR CVF_VERSION_MAJOR_NEXT "${CVF_VERSION_MAJOR} + 1")
if (NOT PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR
OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX_MAJOR STREQUAL CVF_VERSION_MAJOR)
OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX VERSION_LESS_EQUAL CVF_VERSION_MAJOR_NEXT)))
set(PACKAGE_VERSION_COMPATIBLE FALSE)
elseif(PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR
AND ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS_EQUAL PACKAGE_FIND_VERSION_MAX)
OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MAX)))
set(PACKAGE_VERSION_COMPATIBLE TRUE)
else()
set(PACKAGE_VERSION_COMPATIBLE FALSE)
endif()
else()
if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR)
set(PACKAGE_VERSION_COMPATIBLE TRUE)
else()
set(PACKAGE_VERSION_COMPATIBLE FALSE)
endif()

if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
endif()


# if the installed project requested no architecture check, don't perform the check
if("@CVF_ARCH_INDEPENDENT@")
return()
endif()

# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "")
return()
endif()

# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "@CMAKE_SIZEOF_VOID_P@")
math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8")
set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()
4 changes: 4 additions & 0 deletions cmake/pkg-config.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name: ${PROJECT_NAME}
Description: Koinos Log Library
Version: ${PROJECT_VERSION}
Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}
32 changes: 27 additions & 5 deletions lang/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,32 @@ add_library(Koinos::types ALIAS koinos_types)
# We specifically do not want to link to boost, only include boost headers.
# Any boost library that is not header only must be build against wasm.
# It is easier to simply to utilize those libraries. Most boost libraries are header only.
target_link_libraries(koinos_types INTERFACE nlohmann_json::nlohmann_json)
target_include_directories(koinos_types INTERFACE ${KOINOS_CPP_OUTPUT_INCLUDE_DIR} ${Boost_INCLUDE_DIR} )
target_link_libraries(koinos_types INTERFACE Boost::headers nlohmann_json::nlohmann_json)
target_include_directories(koinos_types INTERFACE
$<BUILD_INTERFACE:${KOINOS_CPP_OUTPUT_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
)

install(DIRECTORY ${KOINOS_CPP_OUTPUT_INCLUDE_DIR}/ DESTINATION include)

export(
TARGETS ${KOINOS_LIB_TARGET_NAME}
NAMESPACE Koinos::
FILE ${KOINOS_LIB_CMAKE_PROJECT_TARGETS_FILE}
)

if( INSTALL_KOINOS_TYPES_HEADERS )
install( DIRECTORY ${KOINOS_CPP_OUTPUT_INCLUDE_DIR}/ DESTINATION include )
endif()
install(
TARGETS ${KOINOS_LIB_TARGET_NAME}
EXPORT ${KOINOS_LIB_TARGETS_EXPORT_NAME}
INCLUDES DESTINATION ${KOINOS_LIB_INCLUDE_INSTALL_DIR}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

install(
EXPORT ${KOINOS_LIB_TARGETS_EXPORT_NAME}
NAMESPACE Koinos::
DESTINATION ${KOINOS_LIB_CONFIG_INSTALL_DIR}
)