diff --git a/.github/workflows/cmake-build.yml b/.github/workflows/cmake-build.yml index 896dc5d6..4fc9b23c 100644 --- a/.github/workflows/cmake-build.yml +++ b/.github/workflows/cmake-build.yml @@ -14,6 +14,8 @@ on: branches: [ "master" ] paths: - 'knp/**' + - 'examples/**' + - 'CMakeLists.txt' - '.github/workflows/cmake-build.yml' - '!/doc/**' - '!/docker/**' diff --git a/.gitignore b/.gitignore index 06e4aff9..aea66e12 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,7 @@ gmon.out # QtCreator CMakeLists.txt.user + +# MSVS. + +/.vs \ No newline at end of file diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json index 9633574b..b0b5af20 100644 --- a/.vs/ProjectSettings.json +++ b/.vs/ProjectSettings.json @@ -1,3 +1,3 @@ { - "CurrentProjectSetting": "Windows x64 Debug (windows-default)" -} + "CurrentProjectSetting": "Windows x64 Debug (windows-ninja)" +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c3380dd..b29c21a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,10 +219,6 @@ include(print-variables) # Build third-party. # -if (MSVC) - set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) -endif() - if (KNP_BUILD_AUTONOMOUS) if (NOT CPM_SOURCE_CACHE_DEFAULT) set(CPM_SOURCE_CACHE_DEFAULT "${CMAKE_CURRENT_SOURCE_DIR}/third-party") @@ -243,6 +239,15 @@ else() set(ZMQ_ENABLE_PRECOMPS ON) endif() +add_third_party("gh:gabime/spdlog@1.13.0" + OPTIONS + "SPDLOG_BUILD_PIC ON" + "SPDLOG_BUILD_SHARED OFF") + +if (MSVC) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) +endif() + add_third_party(NAME "libzmq" GITHUB_REPOSITORY "zeromq/libzmq" VERSION "4.3.5" @@ -305,7 +310,7 @@ add_third_party("gh:p-ranav/csv2@0.1" "CSV2_TEST OFF" "CSV2_SAMPLES OFF") -if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "^x86.*") +if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(x86.*)|(X86.*)|(amd64)|(AMD64)") add_third_party("gh:intel/pcm" GIT_TAG 2f9b0c2 OPTIONS @@ -314,16 +319,11 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "^x86.*") include_directories("${CPM_PACKAGE_pcm_SOURCE_DIR}/src") endif() -add_third_party("gh:gabime/spdlog@1.13.0" - OPTIONS - "SPDLOG_BUILD_PIC ON" - "SPDLOG_BUILD_SHARED OFF") - add_third_party("gh:zeromq/cppzmq@4.10.0" OPTIONS "CPPZMQ_BUILD_TESTS OFF") -add_third_party("gh:Tencent/rapidjson#7c73dd7" +add_third_party("gh:Tencent/rapidjson#ebd87cb" OPTIONS "RAPIDJSON_BUILD_DOC OFF" "RAPIDJSON_BUILD_ASAN OFF" diff --git a/knp/backends/cpu/cpu-library/CMakeLists.txt b/knp/backends/cpu/cpu-library/CMakeLists.txt index 223eef6d..aa71c305 100644 --- a/knp/backends/cpu/cpu-library/CMakeLists.txt +++ b/knp/backends/cpu/cpu-library/CMakeLists.txt @@ -14,43 +14,43 @@ 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) - -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-backends-library VERSION "${KNP_VERSION}" LANGUAGES C CXX) - -find_package(Boost ${KNP_BOOST_MIN_VERSION} REQUIRED) - -include(clang-tidy) -include(knp-functions) - -file(GLOB_RECURSE ${PROJECT_NAME}_headers include/knp/backends/cpu-library/*.h) - -knp_add_library("${PROJECT_NAME}" - INTERFACE - include/knp/backends/cpu-library/impl/synaptic_resource_stdp_impl.h - ${${PROJECT_NAME}_headers}) -add_library(KNP::Backends::CPU::Library ALIAS "${PROJECT_NAME}") - -source_group(source REGULAR_EXPRESSION "impl/.*") -source_group(headers FILES ${${PROJECT_NAME}_headers} REGULAR_EXPRESSION "include/.*") -source_group(headers REGULAR_EXPRESSION "impl/.*") - -target_include_directories("${PROJECT_NAME}" INTERFACE ${Boost_INCLUDE_DIRS}) -target_include_directories("${PROJECT_NAME}" INTERFACE "impl") - -target_link_libraries("${PROJECT_NAME}" INTERFACE Boost::headers spdlog::spdlog) -target_link_libraries("${PROJECT_NAME}" INTERFACE KNP::Core KNP::Devices::CPU) - -# Internal library, used by backends. -# This doesn't require installation. +cmake_minimum_required(VERSION 3.25) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +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-backends-library VERSION "${KNP_VERSION}" LANGUAGES C CXX) + +find_package(Boost ${KNP_BOOST_MIN_VERSION} REQUIRED) + +include(clang-tidy) +include(knp-functions) + +file(GLOB_RECURSE ${PROJECT_NAME}_headers include/knp/backends/cpu-library/*.h) + +knp_add_library("${PROJECT_NAME}" + INTERFACE + include/knp/backends/cpu-library/impl/synaptic_resource_stdp_impl.h + ${${PROJECT_NAME}_headers}) +add_library(KNP::Backends::CPU::Library ALIAS "${PROJECT_NAME}") + +source_group(source REGULAR_EXPRESSION "impl/.*") +source_group(headers FILES ${${PROJECT_NAME}_headers} REGULAR_EXPRESSION "include/.*") +source_group(headers REGULAR_EXPRESSION "impl/.*") + +target_include_directories("${PROJECT_NAME}" INTERFACE ${Boost_INCLUDE_DIRS}) +target_include_directories("${PROJECT_NAME}" INTERFACE "impl") + +target_link_libraries("${PROJECT_NAME}" INTERFACE Boost::headers spdlog::spdlog_header_only) +target_link_libraries("${PROJECT_NAME}" INTERFACE KNP::Core KNP::Devices::CPU) + +# Internal library, used by backends. +# This doesn't require installation. diff --git a/knp/backends/cpu/cpu-multi-threaded-backend/CMakeLists.txt b/knp/backends/cpu/cpu-multi-threaded-backend/CMakeLists.txt index 83acc170..061ee6c0 100644 --- a/knp/backends/cpu/cpu-multi-threaded-backend/CMakeLists.txt +++ b/knp/backends/cpu/cpu-multi-threaded-backend/CMakeLists.txt @@ -51,7 +51,7 @@ knp_add_library("${PROJECT_NAME}" ${${PROJECT_NAME}_headers} ALIAS KNP::Backends::CPUMultiThreaded LINK_PRIVATE - Boost::headers spdlog::spdlog + Boost::headers spdlog::spdlog_header_only KNP::Backends::CPU::Library KNP::Backends::CPU::ThreadPool LINK_PUBLIC KNP::Devices::CPU diff --git a/knp/backends/cpu/cpu-single-threaded-backend/CMakeLists.txt b/knp/backends/cpu/cpu-single-threaded-backend/CMakeLists.txt index 0d20cabd..0f8f4624 100644 --- a/knp/backends/cpu/cpu-single-threaded-backend/CMakeLists.txt +++ b/knp/backends/cpu/cpu-single-threaded-backend/CMakeLists.txt @@ -51,7 +51,7 @@ knp_add_library("${PROJECT_NAME}" ${${PROJECT_NAME}_headers} ALIAS KNP::Backends::CPUSingleThreaded LINK_PRIVATE - Boost::headers ${Boost_LIBRARIES} spdlog::spdlog KNP::Backends::CPU::Library + Boost::headers ${Boost_LIBRARIES} spdlog::spdlog_header_only KNP::Backends::CPU::Library LINK_PUBLIC KNP::Core KNP::Devices::CPU ) diff --git a/knp/backends/cpu/thread_pool/CMakeLists.txt b/knp/backends/cpu/thread_pool/CMakeLists.txt index 931c4572..062e5326 100644 --- a/knp/backends/cpu/thread_pool/CMakeLists.txt +++ b/knp/backends/cpu/thread_pool/CMakeLists.txt @@ -14,41 +14,41 @@ See the License for the specific language governing permissions and limitations under the License. ]] -cmake_minimum_required(VERSION 3.22) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -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-thread-pool-library VERSION "${KNP_VERSION}" LANGUAGES C CXX) - -find_package(Boost ${KNP_BOOST_MIN_VERSION} REQUIRED) - -include(clang-tidy) -include(knp-functions) - -file(GLOB_RECURSE ${PROJECT_NAME}_headers include/knp/backends/thread_pool/*.h) - -knp_add_library("${PROJECT_NAME}" - STATIC - impl/thread_pool_context.cpp - ${${PROJECT_NAME}_headers} -) -add_library(KNP::Backends::CPU::ThreadPool ALIAS "${PROJECT_NAME}") - -source_group(source REGULAR_EXPRESSION "impl/.*") -source_group(headers FILES ${${PROJECT_NAME}_headers} REGULAR_EXPRESSION "include/.*") - -target_include_directories("${PROJECT_NAME}" PRIVATE ${Boost_INCLUDE_DIRS}) - -target_link_libraries("${PROJECT_NAME}" PRIVATE Boost::headers spdlog::spdlog) - -# Internal library, used by backends. -# This doesn't require installation. +cmake_minimum_required(VERSION 3.22) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +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-thread-pool-library VERSION "${KNP_VERSION}" LANGUAGES C CXX) + +find_package(Boost ${KNP_BOOST_MIN_VERSION} REQUIRED) + +include(clang-tidy) +include(knp-functions) + +file(GLOB_RECURSE ${PROJECT_NAME}_headers include/knp/backends/thread_pool/*.h) + +knp_add_library("${PROJECT_NAME}" + STATIC + impl/thread_pool_context.cpp + ${${PROJECT_NAME}_headers} +) +add_library(KNP::Backends::CPU::ThreadPool ALIAS "${PROJECT_NAME}") + +source_group(source REGULAR_EXPRESSION "impl/.*") +source_group(headers FILES ${${PROJECT_NAME}_headers} REGULAR_EXPRESSION "include/.*") + +target_include_directories("${PROJECT_NAME}" PRIVATE ${Boost_INCLUDE_DIRS}) + +target_link_libraries("${PROJECT_NAME}" PRIVATE Boost::headers spdlog::spdlog_header_only) + +# Internal library, used by backends. +# This doesn't require installation. diff --git a/knp/base-framework/CMakeLists.txt b/knp/base-framework/CMakeLists.txt index 7c6126e6..52865c4a 100644 --- a/knp/base-framework/CMakeLists.txt +++ b/knp/base-framework/CMakeLists.txt @@ -76,7 +76,7 @@ knp_add_library("${PROJECT_NAME}-core" ${${PROJECT_NAME}_headers} ALIAS KNP::BaseFramework::Core LINK_PRIVATE - spdlog::spdlog Boost::headers Boost::filesystem HighFive ${HDF5_LIB} csv2 # RapidJSON + spdlog::spdlog_header_only Boost::headers Boost::filesystem HighFive ${HDF5_LIB} csv2 # Hack to build with CLang. ${ADD_LIBS} LINK_PUBLIC diff --git a/knp/base-framework/impl/storage/native/data_storage_json.cpp b/knp/base-framework/impl/storage/native/data_storage_json.cpp index 45f6a36f..7cb3bbcb 100644 --- a/knp/base-framework/impl/storage/native/data_storage_json.cpp +++ b/knp/base-framework/impl/storage/native/data_storage_json.cpp @@ -140,7 +140,7 @@ bool is_json_has_magic(const rapidjson::Document &doc) // cppcheck-suppress con bool has_magic = false; for (auto group_iter = attributes.Begin(); group_iter != attributes.End(); ++group_iter) { - const auto &group = group_iter->GetObject(); + const auto &group = *group_iter; if (group.HasMember("name") && group["name"].GetString() == magic) { if (group.HasMember("value") && group["value"].GetInt() != MAGIC_NUMBER) break; @@ -163,7 +163,7 @@ bool is_correct_version(const rapidjson::Document &doc) // cppcheck-suppress co for (auto group_iter = attributes.Begin(); group_iter != attributes.End(); ++group_iter) { - const auto &group = group_iter->GetObject(); + const auto &group = *group_iter; if (!group.HasMember("name") || group["name"].GetString() != version_str) continue; if (!group.HasMember("value") || !group["value"].IsArray()) return false; @@ -191,7 +191,7 @@ auto read_nodes(const rapidjson::Document::Object &spikes_group) // Reading node IDs. if (!spikes_group.HasMember("node_ids") || !spikes_group["node_ids"].IsObject()) throw std::runtime_error("No \"node_ids\" array in \"spikes\" group."); - const auto &nodes_ids = spikes_group["node_ids"].GetObject(); + const auto &nodes_ids = spikes_group["node_ids"]; if (!nodes_ids.HasMember("value") || !nodes_ids["value"].IsArray()) throw std::runtime_error("Missing node data in JSON data file."); @@ -253,7 +253,7 @@ KNP_DECLSPEC std::vector load_messages_from_json( if (!doc.HasMember("spikes") || !doc["spikes"].IsObject()) throw std::runtime_error("Unable to find \"spikes\" group in data file."); - const auto &spikes_group = doc["spikes"].GetObject(); + const auto &spikes_group = doc["spikes"].GetObj(); auto nodes = read_nodes(spikes_group); auto timestamps = read_timestamps(spikes_group); diff --git a/knp/core-library/CMakeLists.txt b/knp/core-library/CMakeLists.txt index 6ea8c271..97f0f7c6 100644 --- a/knp/core-library/CMakeLists.txt +++ b/knp/core-library/CMakeLists.txt @@ -14,146 +14,146 @@ 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 it 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-core VERSION "${KNP_VERSION}" LANGUAGES C CXX - DESCRIPTION "Kaspersky Neuromorphic Platform core library" - HOMEPAGE_URL "https://neuro.kaspersky.ru/neyromorfnye-tekhnologii/") - -if(NOT TARGET Boost::headers) - find_package(Boost ${KNP_BOOST_MIN_VERSION} REQUIRED) -endif() - -if(NOT TARGET cppzmq) - find_package(cppzmq REQUIRED) -endif() - -if (MSVC) - set(CPP_ZMQ cppzmq-static) -else() - set(CPP_ZMQ cppzmq) -endif() - -include(GNUInstallDirs) -# Need it for installation. -include(CMakePackageConfigHelpers) -include(clang-tidy) -include(knp-functions) -include(third-party) - -set(${PROJECT_NAME}_PUBLIC_INCLUDE_DIR "knp/core") - -file(GLOB_RECURSE ${PROJECT_NAME}_headers include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/*.h) - -set(${PROJECT_NAME}_FB_SOURCES - impl/messaging/fbs/message_envelope.fbs - impl/messaging/fbs/message_header.fbs - impl/messaging/fbs/synapse_traits.fbs - impl/messaging/fbs/spike_message.fbs - impl/messaging/fbs/synaptic_impact_message.fbs) - - -# -# Build. -# - -flatbuffers_generate_headers( - TARGET "${PROJECT_NAME}_messaging" - INCLUDE_PREFIX "knp_gen_headers" - SCHEMAS ${${PROJECT_NAME}_FB_SOURCES} - # BINARY_SCHEMAS_DIR "${CMAKE_BINARY_DIR}/gen_includes" - # FLAGS --gen-object-api -) - -knp_add_library("${PROJECT_NAME}" - STATIC - impl/backend.cpp - impl/device.cpp - impl/population.cpp - impl/uid.cpp - impl/projection.cpp - impl/message_bus.cpp - impl/message_endpoint.cpp - impl/message_bus_zmq_impl/message_bus_zmq_impl.h - impl/message_bus_zmq_impl/message_endpoint_zmq_impl.h - impl/message_bus_zmq_impl/message_bus_zmq_impl.cpp - impl/message_bus_zmq_impl/message_endpoint_zmq_impl.cpp - impl/message_bus_cpu_impl/message_bus_cpu_impl.cpp - impl/message_bus_cpu_impl/message_bus_cpu_impl.h - impl/message_bus_cpu_impl/message_endpoint_cpu_impl.h - impl/message_bus_impl.h - impl/message_header.cpp - impl/messaging/message_envelope.cpp - impl/messaging/uid_marshal.h - impl/messaging/spike_message_impl.h - impl/messaging/spike_message.cpp - impl/messaging/synaptic_impact_message_impl.h - impl/messaging/synaptic_impact_message.cpp - impl/subscription.cpp - - ${${PROJECT_NAME}_headers} - # PRECOMP impl/common_precomp.h - LINK_PRIVATE - Boost::headers spdlog::spdlog ${CPP_ZMQ} flatbuffers "${PROJECT_NAME}_messaging" - LINK_PUBLIC - # This is used in the library for message parameters. - KNP::Neuron::Traits KNP::Synapse::Traits - ALIAS KNP::Core -) - -source_group(source REGULAR_EXPRESSION "impl/.*") - -target_include_directories("${PROJECT_NAME}" PRIVATE ${Boost_INCLUDE_DIRS} "impl") - -# Flatbuffer headers must be generated before core compilation starts. -add_dependencies("${PROJECT_NAME}" "GENERATE_${PROJECT_NAME}_messaging" "${PROJECT_NAME}_messaging") - -# add_clang_tidy("${PROJECT_NAME}" CONFIG_FILE_PATH "${CMAKE_TIDY_CONFIG}" EXTRA_ARGS "--use-color") - - -# -# Installation. -# - -message(STATUS "Configuring installation...") - -set(PACKAGE_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}) - -configure_file( - "${CMAKE_CURRENT_LIST_DIR}/include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/version.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/version.h") - -if (KNP_INSTALL) - set(COMPONENT_NAME "cpp-framework") - - install(TARGETS "${PROJECT_NAME}_messaging" - EXPORT "${PROJECT_NAME}_messaging" - COMPONENT "${COMPONENT_NAME}-dev") - - install(TARGETS "${PROJECT_NAME}" - EXPORT "${PROJECT_NAME}" - ARCHIVE - COMPONENT "${COMPONENT_NAME}-dev") - - install(DIRECTORY "include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}" - COMPONENT "${COMPONENT_NAME}-dev" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/knp" - FILES_MATCHING PATTERN "*.h") - - install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/version.h" - COMPONENT "${COMPONENT_NAME}-dev" - DESTINATION "include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}") -endif() +cmake_minimum_required(VERSION 3.25) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Required it 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-core VERSION "${KNP_VERSION}" LANGUAGES C CXX + DESCRIPTION "Kaspersky Neuromorphic Platform core library" + HOMEPAGE_URL "https://neuro.kaspersky.ru/neyromorfnye-tekhnologii/") + +if(NOT TARGET Boost::headers) + find_package(Boost ${KNP_BOOST_MIN_VERSION} REQUIRED) +endif() + +if(NOT TARGET cppzmq) + find_package(cppzmq REQUIRED) +endif() + +if (MSVC) + set(CPP_ZMQ cppzmq-static) +else() + set(CPP_ZMQ cppzmq) +endif() + +include(GNUInstallDirs) +# Need it for installation. +include(CMakePackageConfigHelpers) +include(clang-tidy) +include(knp-functions) +include(third-party) + +set(${PROJECT_NAME}_PUBLIC_INCLUDE_DIR "knp/core") + +file(GLOB_RECURSE ${PROJECT_NAME}_headers include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/*.h) + +set(${PROJECT_NAME}_FB_SOURCES + impl/messaging/fbs/message_envelope.fbs + impl/messaging/fbs/message_header.fbs + impl/messaging/fbs/synapse_traits.fbs + impl/messaging/fbs/spike_message.fbs + impl/messaging/fbs/synaptic_impact_message.fbs) + + +# +# Build. +# + +flatbuffers_generate_headers( + TARGET "${PROJECT_NAME}_messaging" + INCLUDE_PREFIX "knp_gen_headers" + SCHEMAS ${${PROJECT_NAME}_FB_SOURCES} + # BINARY_SCHEMAS_DIR "${CMAKE_BINARY_DIR}/gen_includes" + # FLAGS --gen-object-api +) + +knp_add_library("${PROJECT_NAME}" + STATIC + impl/backend.cpp + impl/device.cpp + impl/population.cpp + impl/uid.cpp + impl/projection.cpp + impl/message_bus.cpp + impl/message_endpoint.cpp + impl/message_bus_zmq_impl/message_bus_zmq_impl.h + impl/message_bus_zmq_impl/message_endpoint_zmq_impl.h + impl/message_bus_zmq_impl/message_bus_zmq_impl.cpp + impl/message_bus_zmq_impl/message_endpoint_zmq_impl.cpp + impl/message_bus_cpu_impl/message_bus_cpu_impl.cpp + impl/message_bus_cpu_impl/message_bus_cpu_impl.h + impl/message_bus_cpu_impl/message_endpoint_cpu_impl.h + impl/message_bus_impl.h + impl/message_header.cpp + impl/messaging/message_envelope.cpp + impl/messaging/uid_marshal.h + impl/messaging/spike_message_impl.h + impl/messaging/spike_message.cpp + impl/messaging/synaptic_impact_message_impl.h + impl/messaging/synaptic_impact_message.cpp + impl/subscription.cpp + + ${${PROJECT_NAME}_headers} + # PRECOMP impl/common_precomp.h + LINK_PRIVATE + Boost::headers spdlog::spdlog_header_only ${CPP_ZMQ} flatbuffers "${PROJECT_NAME}_messaging" + LINK_PUBLIC + # This is used in the library for message parameters. + KNP::Neuron::Traits KNP::Synapse::Traits + ALIAS KNP::Core +) + +source_group(source REGULAR_EXPRESSION "impl/.*") + +target_include_directories("${PROJECT_NAME}" PRIVATE ${Boost_INCLUDE_DIRS} "impl") + +# Flatbuffer headers must be generated before core compilation starts. +add_dependencies("${PROJECT_NAME}" "GENERATE_${PROJECT_NAME}_messaging" "${PROJECT_NAME}_messaging") + +# add_clang_tidy("${PROJECT_NAME}" CONFIG_FILE_PATH "${CMAKE_TIDY_CONFIG}" EXTRA_ARGS "--use-color") + + +# +# Installation. +# + +message(STATUS "Configuring installation...") + +set(PACKAGE_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}) + +configure_file( + "${CMAKE_CURRENT_LIST_DIR}/include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/version.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/version.h") + +if (KNP_INSTALL) + set(COMPONENT_NAME "cpp-framework") + + install(TARGETS "${PROJECT_NAME}_messaging" + EXPORT "${PROJECT_NAME}_messaging" + COMPONENT "${COMPONENT_NAME}-dev") + + install(TARGETS "${PROJECT_NAME}" + EXPORT "${PROJECT_NAME}" + ARCHIVE + COMPONENT "${COMPONENT_NAME}-dev") + + install(DIRECTORY "include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}" + COMPONENT "${COMPONENT_NAME}-dev" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/knp" + FILES_MATCHING PATTERN "*.h") + + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/version.h" + COMPONENT "${COMPONENT_NAME}-dev" + DESTINATION "include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}") +endif() diff --git a/knp/devices-library/CMakeLists.txt b/knp/devices-library/CMakeLists.txt index f4a3d9f4..c7fbb729 100644 --- a/knp/devices-library/CMakeLists.txt +++ b/knp/devices-library/CMakeLists.txt @@ -33,7 +33,7 @@ include(knp-functions) set(${PROJECT_NAME}_PUBLIC_INCLUDE_DIR "knp/devices") -if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86.*") +if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(x86.*)|(X86.*)|(amd64)|(AMD64)") set(${PROJECT_NAME}_CPU_SOURCE impl/x86_cpu.cpp impl/x86_cpu_power.cpp impl/x86_cpu_power.h) set(${PROJECT_NAME}_ADD_LINK_LIBRARIES PCM_STATIC) else() @@ -48,7 +48,7 @@ knp_add_library("${PROJECT_NAME}-cpu" include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/cpu.h LINK_PRIVATE - spdlog::spdlog ${${PROJECT_NAME}_ADD_LINK_LIBRARIES} + spdlog::spdlog_header_only ${${PROJECT_NAME}_ADD_LINK_LIBRARIES} KNP::Core ALIAS KNP::Devices::CPU ) @@ -66,7 +66,7 @@ knp_add_library("${PROJECT_NAME}-altai" include/${${PROJECT_NAME}_PUBLIC_INCLUDE_DIR}/altai.h LINK_PRIVATE - spdlog::spdlog PCM_STATIC + spdlog::spdlog_header_only KNP::Core ALIAS KNP::Devices::AltAI ) diff --git a/knp/tests/CMakeLists.txt b/knp/tests/CMakeLists.txt index 98584678..2870ba33 100644 --- a/knp/tests/CMakeLists.txt +++ b/knp/tests/CMakeLists.txt @@ -14,117 +14,117 @@ 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) - -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-tester VERSION "${KNP_VERSION}" LANGUAGES CXX - DESCRIPTION "Kaspersky Neuromorphic Platform tester and tests") - -if (NOT KNP_BUILD_TESTS) - message(STATUS "Building of tests is disabled.") - return() -endif() - -include(CTest) - -include(memcheck) - -enable_testing() - -include(GoogleTest) - -file(GLOB_RECURSE COMMON_SOURCE CONFIGURE_DEPENDS - "*.h" - "*_test.cpp") - -add_executable("${PROJECT_NAME}" ${COMMON_SOURCE} tester.cpp utility.cpp) - -target_include_directories("${PROJECT_NAME}" - PRIVATE "${CMAKE_CURRENT_LIST_DIR}/common" - PRIVATE "${GTEST_DIR}/googletest/include" - PRIVATE "${GTEST_DIR}/googlemock/include" -) - -#knp_get_hdf5_target(HDF5_LIB) - -target_link_libraries("${PROJECT_NAME}" PRIVATE KNP::BaseFramework::CoreStatic KNP::Backends::CPUSingleThreaded KNP::Backends::CPUMultiThreaded - KNP::Backends::CPU::ThreadPool) -target_link_libraries("${PROJECT_NAME}" PRIVATE gtest gtest_main spdlog::spdlog) # HighFive - -add_dependencies("${PROJECT_NAME}" knp-base-framework-core_static) - -if (${BUILD_GMOCK}) - target_link_libraries("${PROJECT_NAME}" PRIVATE gmock gmock_main) -endif() - -gtest_discover_tests("${PROJECT_NAME}" - # Set a working directory to find test data via paths relative to the project root. - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" -) - -if (KNP_ENABLE_COVERAGE) - message(STATUS "Coverage enabled.") - - set(COV_EXECUTABLE "${PROJECT_NAME}") - #set(COV_EXECUTABLE "$") - set(COV_NAME "${PROJECT_NAME}_coverage") - set(COV_DEPENDENCIES "${PROJECT_NAME}") - set(COV_BASE_DIRECTORY "${CMAKE_SOURCE_DIR}") - set(COV_EXCLUDES "/usr/*;third-party/*") - - set(CODE_COVERAGE_VERBOSE ON) - - if (GCOVR_PATH) - set(GCOVR_ADDITIONAL_ARGS --gcov-ignore-parse-errors) - setup_target_for_coverage_gcovr_xml( - NAME "${COV_NAME}" - EXECUTABLE ${COV_EXECUTABLE} - DEPENDENCIES ${COV_DEPENDENCIES} - BASE_DIRECTORY "${COV_BASE_DIRECTORY}" - ) - message(VERBOSE "Gcovr selected.") - elseif (LCOV_PATH) - setup_target_for_coverage_lcov( - NAME "${COV_NAME}" - EXECUTABLE ${COV_EXECUTABLE} - DEPENDENCIES ${COV_DEPENDENCIES} - BASE_DIRECTORY "${COV_BASE_DIRECTORY}" - EXCLUDE ${COV_EXCLUDES} - LCOV_ARGS - --ignore-errors empty,inconsistent - ) - message(VERBOSE "Lcov selected.") - elseif (FASTCOV_PATH) - setup_target_for_coverage_fastcov( - NAME "${COV_NAME}" - EXECUTABLE ${COV_EXECUTABLE} - DEPENDENCIES ${COV_DEPENDENCIES} - BASE_DIRECTORY "${COV_BASE_DIRECTORY}" - ) - message(VERBOSE "Fastcov selected.") - else() - message(WARNING "Coverage cannot be enabled.") - endif() -endif() - - -set(CTEST_MEMORYCHECK_COMMAND "/usr/bin/valgrind") -set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--tool=memcheck --leak-check=full --undef-value-errors=yes --error-limit=no --time-stamp=yes --trace-children=yes --track-fds=yes --track-origins=yes --gen-suppressions=all --undef-value-errors=yes --error-exitcode=1") - -add_custom_target(test_with_memcheck - COMMAND ${CMAKE_CTEST_COMMAND} - --force-new-ctest-process --test-action memcheck - --rerun-failed --output-on-failure - COMMAND cat "Testing/Temporary/MemoryChecker.*.log" - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/knp/tests") +cmake_minimum_required(VERSION 3.25) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +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-tester VERSION "${KNP_VERSION}" LANGUAGES CXX + DESCRIPTION "Kaspersky Neuromorphic Platform tester and tests") + +if (NOT KNP_BUILD_TESTS) + message(STATUS "Building of tests is disabled.") + return() +endif() + +include(CTest) + +include(memcheck) + +enable_testing() + +include(GoogleTest) + +file(GLOB_RECURSE COMMON_SOURCE CONFIGURE_DEPENDS + "*.h" + "*_test.cpp") + +add_executable("${PROJECT_NAME}" ${COMMON_SOURCE} tester.cpp utility.cpp) + +target_include_directories("${PROJECT_NAME}" + PRIVATE "${CMAKE_CURRENT_LIST_DIR}/common" + PRIVATE "${GTEST_DIR}/googletest/include" + PRIVATE "${GTEST_DIR}/googlemock/include" +) + +#knp_get_hdf5_target(HDF5_LIB) + +target_link_libraries("${PROJECT_NAME}" PRIVATE KNP::BaseFramework::CoreStatic KNP::Backends::CPUSingleThreaded KNP::Backends::CPUMultiThreaded + KNP::Backends::CPU::ThreadPool) +target_link_libraries("${PROJECT_NAME}" PRIVATE gtest gtest_main spdlog::spdlog_header_only) # HighFive + +add_dependencies("${PROJECT_NAME}" knp-base-framework-core_static) + +if (${BUILD_GMOCK}) + target_link_libraries("${PROJECT_NAME}" PRIVATE gmock gmock_main) +endif() + +gtest_discover_tests("${PROJECT_NAME}" + # Set a working directory to find test data via paths relative to the project root. + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" +) + +if (KNP_ENABLE_COVERAGE) + message(STATUS "Coverage enabled.") + + set(COV_EXECUTABLE "${PROJECT_NAME}") + #set(COV_EXECUTABLE "$") + set(COV_NAME "${PROJECT_NAME}_coverage") + set(COV_DEPENDENCIES "${PROJECT_NAME}") + set(COV_BASE_DIRECTORY "${CMAKE_SOURCE_DIR}") + set(COV_EXCLUDES "/usr/*;third-party/*") + + set(CODE_COVERAGE_VERBOSE ON) + + if (GCOVR_PATH) + set(GCOVR_ADDITIONAL_ARGS --gcov-ignore-parse-errors) + setup_target_for_coverage_gcovr_xml( + NAME "${COV_NAME}" + EXECUTABLE ${COV_EXECUTABLE} + DEPENDENCIES ${COV_DEPENDENCIES} + BASE_DIRECTORY "${COV_BASE_DIRECTORY}" + ) + message(VERBOSE "Gcovr selected.") + elseif (LCOV_PATH) + setup_target_for_coverage_lcov( + NAME "${COV_NAME}" + EXECUTABLE ${COV_EXECUTABLE} + DEPENDENCIES ${COV_DEPENDENCIES} + BASE_DIRECTORY "${COV_BASE_DIRECTORY}" + EXCLUDE ${COV_EXCLUDES} + LCOV_ARGS + --ignore-errors empty,inconsistent + ) + message(VERBOSE "Lcov selected.") + elseif (FASTCOV_PATH) + setup_target_for_coverage_fastcov( + NAME "${COV_NAME}" + EXECUTABLE ${COV_EXECUTABLE} + DEPENDENCIES ${COV_DEPENDENCIES} + BASE_DIRECTORY "${COV_BASE_DIRECTORY}" + ) + message(VERBOSE "Fastcov selected.") + else() + message(WARNING "Coverage cannot be enabled.") + endif() +endif() + + +set(CTEST_MEMORYCHECK_COMMAND "/usr/bin/valgrind") +set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--tool=memcheck --leak-check=full --undef-value-errors=yes --error-limit=no --time-stamp=yes --trace-children=yes --track-fds=yes --track-origins=yes --gen-suppressions=all --undef-value-errors=yes --error-exitcode=1") + +add_custom_target(test_with_memcheck + COMMAND ${CMAKE_CTEST_COMMAND} + --force-new-ctest-process --test-action memcheck + --rerun-failed --output-on-failure + COMMAND cat "Testing/Temporary/MemoryChecker.*.log" + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/knp/tests")