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

Dependencies loading fix: #18 #19

Merged
merged 9 commits into from
Nov 21, 2024
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
33 changes: 24 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ endif()
# Kaspersky Neuromorphic Platform build option set.
#

# Build is not from source directory, it is possible to specify it via add_subdirectory().
if (NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(KNP_BUILD_AUTONOMOUS FALSE)
else()
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(KNP_BUILD_AUTONOMOUS TRUE)
else()
# Build is not from source directory, it is possible to specify it via add_subdirectory().
set(KNP_BUILD_AUTONOMOUS FALSE)
endif()

if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
Expand Down Expand Up @@ -187,7 +187,7 @@ if (KNP_ENABLE_AVX)
# -include bits/stdc++.h
endif()

if (NOT KNP_MAINTAINER_BUILD)
if (NOT KNP_MAINTAINER_BUILD AND KNP_BUILD_AUTONOMOUS)
execute_process(COMMAND pre-commit install
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
if(ret AND NOT ret EQUAL 0)
Expand Down Expand Up @@ -223,8 +223,16 @@ if (MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()

set(CPM_SOURCE_CACHE_DEFAULT "${CMAKE_CURRENT_SOURCE_DIR}/third-party" CACHE STRING "" FORCE)
set(CPM_SOURCE_CACHE "${CMAKE_CURRENT_SOURCE_DIR}/third-party" CACHE STRING "" FORCE)
if (KNP_BUILD_AUTONOMOUS)
if (NOT CPM_SOURCE_CACHE_DEFAULT)
set(CPM_SOURCE_CACHE_DEFAULT "${CMAKE_CURRENT_SOURCE_DIR}/third-party")
endif()

if (NOT CPM_SOURCE_CACHE)
message(STATUS "Autonomous build. Setting source cached directory to \"${CPM_SOURCE_CACHE_DEFAULT}\".")
set(CPM_SOURCE_CACHE "${CPM_SOURCE_CACHE_DEFAULT}")
endif()
endif()

# Make cache variables for installation destinations.
include(GNUInstallDirs)
Expand Down Expand Up @@ -314,10 +322,15 @@ add_third_party("gh:zeromq/[email protected]"
add_third_party("gh:Tencent/rapidjson#7c73dd7"
OPTIONS
"RAPIDJSON_BUILD_DOC OFF"
"RAPIDJSON_BUILD_ASAN OFF"
"RAPIDJSON_BUILD_UBSAN OFF"
"RAPIDJSON_BUILD_CXX17 ON"
"RAPIDJSON_BUILD_EXAMPLES OFF"
"RAPIDJSON_BUILD_TESTS OFF"
"RAPIDJSON_HAS_STDSTRING ON")

include_directories("${CPM_PACKAGE_pcm_SOURCE_DIR}/src" "${CPM_PACKAGE_rapidjson_SOURCE_DIR}/include")

if (KNP_BUILD_TESTS)
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=0)
add_third_party("gh:google/[email protected]"
Expand All @@ -326,8 +339,10 @@ if (KNP_BUILD_TESTS)
"INSTALL_GTEST OFF")
endif()

file(GLOB THIRD_PARTY_INCLUDES LIST_DIRECTORIES true "${CPM_SOURCE_CACHE}/**/include")
include_directories("${CPM_SOURCE_CACHE}" ${THIRD_PARTY_INCLUDES})
#if (CPM_SOURCE_CACHE)
# file(GLOB THIRD_PARTY_INCLUDES LIST_DIRECTORIES true "${CPM_SOURCE_CACHE}/**/include")
# include_directories("${CPM_SOURCE_CACHE}" ${THIRD_PARTY_INCLUDES})
#endif()

if (MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS FALSE)
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ build()
fi

if [[ ${SINGLE_PROCESS} == 0 ]]; then
BUILD_ADD_OPTS="${BUILD_ADD_OPTS} --parallel"
BUILD_ADD_OPTS="${BUILD_ADD_OPTS} --parallel $(nproc)"
fi

set -e
Expand Down
1 change: 0 additions & 1 deletion cmake/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ See https://github.com/cpm-cmake/CPM.cmake for more information."
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
include(FetchContent)
endif()
return()
endif()

get_property(
Expand Down
68 changes: 34 additions & 34 deletions cmake/third-party.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ See the License for the specific language governing permissions and
limitations under the License.
]]

#
# CMake third-party support functions. Artiom N.(cl)2022
#

include_guard(GLOBAL)

# include(get_cpm)
include("CPM")


function(add_third_party module_name)
# add_git_submodule("${CMAKE_CURRENT_SOURCE_DIR}/third-party/${module_name}")
set(CPM_USE_LOCAL_PACKAGES ON)
if(NOT KNP_ROOT_DIR)
set(KNP_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()

if(NOT "${module_name}" STREQUAL NAME)
cpm_parse_add_package_single_arg("${module_name};${ARGN}" ARGN)
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
list(GET ARGN 1 _repo_name)
get_filename_component(_repo_name ${_repo_name} NAME)
CPMADDPackage(${ARGN}
EXCLUDE_FROM_ALL YES
SYSTEM YES
SOURCE_DIR "${KNP_ROOT_DIR}/third-party/${_repo_name}")
else()
list(GET ARGN 0 _m_name)
CPMADDPackage("${module_name}" ${ARGN}
EXCLUDE_FROM_ALL YES
SYSTEM YES
SOURCE_DIR "${KNP_ROOT_DIR}/third-party/${_m_name}")
endif()
endfunction()
#
# CMake third-party support functions. Artiom N.(cl)2022
#
include_guard(GLOBAL)
# include(get_cpm)
include(CPM)
function(add_third_party module_name)
# add_git_submodule("${CMAKE_CURRENT_SOURCE_DIR}/third-party/${module_name}")
set(CPM_USE_LOCAL_PACKAGES ON)
if(NOT KNP_ROOT_DIR)
set(KNP_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()
if(NOT "${module_name}" STREQUAL NAME)
cpm_parse_add_package_single_arg("${module_name};${ARGN}" ARGN)
# The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
list(GET ARGN 1 _repo_name)
get_filename_component(_repo_name ${_repo_name} NAME)
CPMAddPackage(${ARGN}
EXCLUDE_FROM_ALL YES
SYSTEM YES)
# SOURCE_DIR "${KNP_ROOT_DIR}/third-party/${_repo_name}")
else()
list(GET ARGN 0 _m_name)
CPMAddPackage("${module_name}" ${ARGN}
EXCLUDE_FROM_ALL YES
SYSTEM YES)
# SOURCE_DIR "${KNP_ROOT_DIR}/third-party/${_m_name}")
endif()
endfunction()
6 changes: 3 additions & 3 deletions cmake/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ endfunction()


function(determine_version_with_git)
message(STATUS "Determining version from Git...")
message(STATUS "Determining version from Git in \"${CMAKE_CURRENT_SOURCE_DIR}\"...")
execute_process(COMMAND git describe --tags
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE GIT_EXECUTION_RESULT
OUTPUT_VARIABLE GIT_PKG_VERSION_FULL
ERROR_VARIABLE GIT_VERSION_ERROR
Expand All @@ -60,7 +60,7 @@ function(knp_get_version)
determine_version_with_git()

if (NOT KNP_VERSION)
read_version_file("${CMAKE_SOURCE_DIR}/VERSION")
read_version_file("${CMAKE_CURRENT_SOURCE_DIR}/VERSION")
endif()

message(STATUS "Kaspersky Neuromorphic Platform version: ${KNP_VERSION}.")
Expand Down
152 changes: 76 additions & 76 deletions knp/backends/cpu/cpu-multi-threaded-backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,79 +14,79 @@ See the License for the specific language governing permissions and
limitations under the License.
]]

cmake_minimum_required(VERSION 3.25)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Required for the linters.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.30")
# Suppress Boost warning.
cmake_policy(SET CMP0167 OLD)
endif()

project(knp-cpu-multi-threaded-backend VERSION "${KNP_VERSION}" LANGUAGES C CXX
DESCRIPTION "CPU multi-threaded backend"
HOMEPAGE_URL "https://neuro.kaspersky.ru/neyromorfnye-tekhnologii/")

set(${PROJECT_NAME}_PUBLIC_INCLUDE_DIR "knp/backends/cpu-multi-threaded")

include(GNUInstallDirs)
include(clang-tidy)
include(knp-functions)

find_package(Boost ${KNP_BOOST_MIN_VERSION} COMPONENTS system REQUIRED)

file(GLOB_RECURSE ${PROJECT_NAME}_headers include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/*.h)
source_group(source REGULAR_EXPRESSION "impl/.*")
source_group(headers REGULAR_EXPRESSION "include/.*")

knp_add_library("${PROJECT_NAME}"
BOTH
impl/backend.cpp
impl/get_network.cpp
${${PROJECT_NAME}_headers}
ALIAS KNP::Backends::CPUMultiThreaded
LINK_PRIVATE
Boost::headers spdlog::spdlog
KNP::Backends::CPU::Library KNP::Backends::CPU::ThreadPool
LINK_PUBLIC
KNP::Core KNP::Devices::CPUStatic
)

set_target_properties(
"${PROJECT_NAME}"
PROPERTIES
VERSION "${CMAKE_PROJECT_VERSION}"
SOVERSION "${CMAKE_PROJECT_VERSION_MAJOR}")

if (KNP_INSTALL)
knp_get_component_name("${PROJECT_NAME}" COMPONENT_NAME)

install(TARGETS "${PROJECT_NAME}"
EXPORT "${PROJECT_NAME}"
COMPONENT "${COMPONENT_NAME}"
LIBRARY)

install(TARGETS "${PROJECT_NAME}_static"
EXPORT "${PROJECT_NAME}_static"
COMPONENT "${COMPONENT_NAME}-dev"
ARCHIVE)

install(DIRECTORY "include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}"
COMPONENT "${COMPONENT_NAME}-dev"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/knp/backends"
FILES_MATCHING PATTERN "*.h")

knp_packaging_set_parameters("${COMPONENT_NAME}" "${PROJECT_NAME}"
DESCRIPTION "${PROJECT_DESCRIPTION}"
DEPENDS "libboost-all (= ${Boost_VERSION})" "libzmq"
PROVIDES "knp-backend")

knp_packaging_set_parameters("${COMPONENT_NAME}-dev" "${PROJECT_NAME}"
DESCRIPTION "${PROJECT_DESCRIPTION} development package: C++ headers and CMake modules"
DEPENDS "${COMPONENT_NAME}")
endif()
cmake_minimum_required(VERSION 3.25)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Required for the linters.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.30")
# Suppress Boost warning.
cmake_policy(SET CMP0167 OLD)
endif()
project(knp-cpu-multi-threaded-backend VERSION "${KNP_VERSION}" LANGUAGES C CXX
DESCRIPTION "CPU multi-threaded backend"
HOMEPAGE_URL "https://neuro.kaspersky.ru/neyromorfnye-tekhnologii/")
set(${PROJECT_NAME}_PUBLIC_INCLUDE_DIR "knp/backends/cpu-multi-threaded")
include(GNUInstallDirs)
include(clang-tidy)
include(knp-functions)
find_package(Boost ${KNP_BOOST_MIN_VERSION} COMPONENTS system REQUIRED)
file(GLOB_RECURSE ${PROJECT_NAME}_headers include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/*.h)
source_group(source REGULAR_EXPRESSION "impl/.*")
source_group(headers REGULAR_EXPRESSION "include/.*")
knp_add_library("${PROJECT_NAME}"
BOTH
impl/backend.cpp
impl/get_network.cpp
${${PROJECT_NAME}_headers}
ALIAS KNP::Backends::CPUMultiThreaded
LINK_PRIVATE
Boost::headers spdlog::spdlog
KNP::Backends::CPU::Library KNP::Backends::CPU::ThreadPool
LINK_PUBLIC
KNP::Devices::CPU
)
set_target_properties(
"${PROJECT_NAME}"
PROPERTIES
VERSION "${CMAKE_PROJECT_VERSION}"
SOVERSION "${CMAKE_PROJECT_VERSION_MAJOR}")
if (KNP_INSTALL)
knp_get_component_name("${PROJECT_NAME}" COMPONENT_NAME)
install(TARGETS "${PROJECT_NAME}"
EXPORT "${PROJECT_NAME}"
COMPONENT "${COMPONENT_NAME}"
LIBRARY)
install(TARGETS "${PROJECT_NAME}_static"
EXPORT "${PROJECT_NAME}_static"
COMPONENT "${COMPONENT_NAME}-dev"
ARCHIVE)
install(DIRECTORY "include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}"
COMPONENT "${COMPONENT_NAME}-dev"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/knp/backends"
FILES_MATCHING PATTERN "*.h")
knp_packaging_set_parameters("${COMPONENT_NAME}" "${PROJECT_NAME}"
DESCRIPTION "${PROJECT_DESCRIPTION}"
DEPENDS "libboost-all (= ${Boost_VERSION})" "libzmq"
PROVIDES "knp-backend")
knp_packaging_set_parameters("${COMPONENT_NAME}-dev" "${PROJECT_NAME}"
DESCRIPTION "${PROJECT_DESCRIPTION} development package: C++ headers and CMake modules"
DEPENDS "${COMPONENT_NAME}")
endif()
Loading