|
| 1 | +# Copyright (c) 2019, Max Planck Society / Software Workshop - Max Planck Institute for Intelligent Systems |
| 2 | +# Distributed under the GNU GPL license version 3 |
| 3 | +# See file LICENSE.md or at https://github.com/MPI-IS/multitensor/LICENSE.md |
| 4 | + |
| 5 | + |
| 6 | +cmake_minimum_required (VERSION 3.5) |
| 7 | +cmake_policy(SET CMP0054 NEW) |
| 8 | + |
| 9 | +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13") |
| 10 | + cmake_policy(SET CMP0076 OLD) |
| 11 | +endif() |
| 12 | + |
| 13 | +set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 14 | + |
| 15 | +# Extract version number |
| 16 | +file(READ ${CMAKE_SOURCE_DIR}/version.txt ver) |
| 17 | +project(MultiTensor VERSION ${ver}) |
| 18 | +message(STATUS "Project ${CMAKE_PROJECT_NAME} v${CMAKE_PROJECT_VERSION}") |
| 19 | + |
| 20 | +enable_testing() |
| 21 | + |
| 22 | +option(ENABLE_PYTHON_WRAPPER "Enable the python extensions" ON) |
| 23 | +option(ENABLE_BENCHMARK "Enable the benchmark" ON) |
| 24 | + |
| 25 | +# 0:silent |
| 26 | +add_definitions(-DMULTITENSOR_VERBOSE=1) |
| 27 | + |
| 28 | +################################# |
| 29 | +# thirdparties and configurations |
| 30 | +include(cmake/compiler_settings.cmake) |
| 31 | +include(cmake/thirdparty.cmake) |
| 32 | + |
| 33 | + |
| 34 | +################################ |
| 35 | +# Main libraries and executables |
| 36 | +set(multitensor_src |
| 37 | + ${CMAKE_SOURCE_DIR}/include/multitensor/graph.hpp |
| 38 | + ${CMAKE_SOURCE_DIR}/include/multitensor/initialization.hpp |
| 39 | + ${CMAKE_SOURCE_DIR}/include/multitensor/params.hpp |
| 40 | + ${CMAKE_SOURCE_DIR}/include/multitensor/solver.hpp |
| 41 | + ${CMAKE_SOURCE_DIR}/include/multitensor/tensor.hpp |
| 42 | + ${CMAKE_SOURCE_DIR}/include/multitensor/utils.hpp |
| 43 | + ${CMAKE_SOURCE_DIR}/include/multitensor/main.hpp) |
| 44 | + |
| 45 | +# libraries |
| 46 | +add_library(multitensor INTERFACE) |
| 47 | +target_include_directories(multitensor |
| 48 | + INTERFACE |
| 49 | + ${CMAKE_SOURCE_DIR}/include/ |
| 50 | + ${CMAKE_SOURCE_DIR}/src/) |
| 51 | +target_sources(multitensor |
| 52 | + INTERFACE |
| 53 | + $<BUILD_INTERFACE:${multitensor_src} >) # for the IDE to see the library |
| 54 | + |
| 55 | +add_library(multitensor_utils |
| 56 | + ${CMAKE_SOURCE_DIR}/applications/include/app_params.hpp |
| 57 | + ${CMAKE_SOURCE_DIR}/applications/include/app_utils.hpp |
| 58 | + ${CMAKE_SOURCE_DIR}/applications/src/app_utils.cpp) |
| 59 | +target_link_libraries(multitensor_utils PUBLIC multitensor Boost::filesystem) |
| 60 | +target_include_directories(multitensor_utils |
| 61 | + PUBLIC |
| 62 | + ${CMAKE_SOURCE_DIR}/applications/include/ |
| 63 | + ${CMAKE_SOURCE_DIR}/applications/src/) |
| 64 | + |
| 65 | +# executables |
| 66 | +add_executable(Multitensor applications/src/multitensor.cpp) |
| 67 | +target_link_libraries(Multitensor multitensor multitensor_utils) |
| 68 | + |
| 69 | +# Unit tests |
| 70 | +add_executable(test_multitensor |
| 71 | + tests/fixtures.hpp |
| 72 | + tests/test_graph.cpp |
| 73 | + tests/test_initialization.cpp |
| 74 | + tests/test_multitensor.cpp |
| 75 | + tests/test_solver.cpp |
| 76 | + tests/test_tensor.cpp |
| 77 | + tests/test_utils.cpp) |
| 78 | +target_link_libraries(test_multitensor |
| 79 | + multitensor |
| 80 | + Boost::unit_test_framework |
| 81 | + Boost::system |
| 82 | + Boost::filesystem) |
| 83 | +add_test( |
| 84 | + NAME multitensor_unit_tests |
| 85 | + COMMAND test_multitensor) |
| 86 | + |
| 87 | +# Functional tests |
| 88 | +# Helper for command line run |
| 89 | +function(add_test_cmd_line |
| 90 | + test_name |
| 91 | + test_program) |
| 92 | + |
| 93 | + # Set test folder and copy adjacency file |
| 94 | + set(test_folder ${CMAKE_BINARY_DIR}/tests/${test_name}) |
| 95 | + file(COPY ${CMAKE_SOURCE_DIR}/data/${test_name}/ DESTINATION ${test_folder}/) |
| 96 | + file(COPY ${CMAKE_SOURCE_DIR}/tests/data/compare.sh DESTINATION ${test_folder}/) |
| 97 | + file(COPY ${CMAKE_SOURCE_DIR}/tests/data/${test_name}/ DESTINATION ${test_folder}/) |
| 98 | + |
| 99 | + # Run |
| 100 | + add_test( |
| 101 | + NAME "command-line-${test_name}-run" |
| 102 | + COMMAND ${test_program} ${ARGN} |
| 103 | + WORKING_DIRECTORY ${test_folder} |
| 104 | + ) |
| 105 | + |
| 106 | + if("${test_program}" STREQUAL "Multitensor") |
| 107 | + add_test( |
| 108 | + NAME "command-line-${test_name}-verify-content" |
| 109 | + COMMAND ${CMAKE_COMMAND} |
| 110 | + "-Dresults=${test_folder}/results" |
| 111 | + "-Dground_truth=${CMAKE_SOURCE_DIR}/tests/data/${test_name}" |
| 112 | + -P ${CMAKE_SOURCE_DIR}/cmake/verify_content.cmake |
| 113 | + ) |
| 114 | + |
| 115 | + set_tests_properties( |
| 116 | + "command-line-${test_name}-verify-content" |
| 117 | + PROPERTIES |
| 118 | + DEPENDS "command-line-${test_name}-run" |
| 119 | + ) |
| 120 | + endif() |
| 121 | + |
| 122 | +endfunction() |
| 123 | + |
| 124 | +add_test_cmd_line( |
| 125 | + "main" |
| 126 | + Multitensor |
| 127 | + --a adjacency.dat |
| 128 | + --k 2 |
| 129 | + --s 5489 |
| 130 | + --maxit 100) |
| 131 | + |
| 132 | +add_test_cmd_line( |
| 133 | + "undirected" |
| 134 | + Multitensor |
| 135 | + --a adjacency.dat |
| 136 | + --k 2 |
| 137 | + --s 5489 |
| 138 | + --undirected |
| 139 | + --maxit 100) |
| 140 | + |
| 141 | +add_test_cmd_line( |
| 142 | + "w_input" |
| 143 | + Multitensor |
| 144 | + --a adjacency_k2L4.dat |
| 145 | + --k 2 |
| 146 | + --s 5489 |
| 147 | + --w w_k2_k2L4_A.dat |
| 148 | + --maxit 100) |
| 149 | + |
| 150 | +add_test_cmd_line( |
| 151 | + "multi_real" |
| 152 | + Multitensor |
| 153 | + --a adjacency_k2L4.dat |
| 154 | + --k 2 |
| 155 | + --s 5489 |
| 156 | + --w w_k2_k2L4_r2.dat |
| 157 | + --r 2 |
| 158 | + --maxit 100) |
| 159 | + |
| 160 | +add_test_cmd_line( |
| 161 | + "assortative" |
| 162 | + Multitensor |
| 163 | + --a adjacency_assortative_k3L4.dat |
| 164 | + --k 3 |
| 165 | + --s 5489 |
| 166 | + --assortative |
| 167 | + --maxit 100) |
| 168 | + |
| 169 | + |
| 170 | +######################### |
| 171 | +# Python Bindings + Tests |
| 172 | +include(cmake/python.cmake) |
| 173 | + |
| 174 | + |
| 175 | +######################### |
| 176 | +# Documentation (Doxygen) |
| 177 | +include(cmake/doxygen_doc.cmake) |
| 178 | + |
| 179 | + |
| 180 | +########### |
| 181 | +# Benchmark |
| 182 | +include(cmake/benchmark.cmake) |
0 commit comments