| … | … | @@ -0,0 +1,230 @@ |
| 1 | # |
| 2 | # Master AtomSpace Matrix CMake file. |
| 3 | # |
| 4 | # General organization: |
| 5 | # -- check for different compilers, OS'es |
| 6 | # -- search for various required & optional libraries/tools |
| 7 | # -- decide what to build based on above results. |
| 8 | # -- configure various config files. |
| 9 | # -- print pretty summary |
| 10 | # |
| 11 | |
| 12 | # cogutils already requires 3.0.2, so may as well ask for that. |
| 13 | CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2) |
| 14 | IF (COMMAND CMAKE_POLICY) |
| 15 | # These must be explicitly set, as otherwise warnings are printed. |
| 16 | CMAKE_POLICY(SET CMP0003 NEW) |
| 17 | CMAKE_POLICY(SET CMP0037 NEW) |
| 18 | CMAKE_POLICY(SET CMP0045 NEW) |
| 19 | ENDIF (COMMAND CMAKE_POLICY) |
| 20 | |
| 21 | PROJECT(matrix) |
| 22 | |
| 23 | # ---------------------------------------------------------- |
| 24 | # User-modifiable options. Feel free to change these! |
| 25 | # |
| 26 | # Uncomment to be in Release mode [default]. |
| 27 | # SET(CMAKE_BUILD_TYPE Release) |
| 28 | |
| 29 | # Uncomment to build in debug mode. |
| 30 | # SET(CMAKE_BUILD_TYPE Debug) |
| 31 | |
| 32 | # Uncomment to be in coverage testing mode. |
| 33 | # SET(CMAKE_BUILD_TYPE Coverage) |
| 34 | |
| 35 | # Uncomment to build in profile mode. |
| 36 | # SET(CMAKE_BUILD_TYPE Profile) |
| 37 | |
| 38 | # Uncomment to build in release mode with debug information. |
| 39 | # SET(CMAKE_BUILD_TYPE RelWithDebInfo) |
| 40 | |
| 41 | # default build type |
| 42 | IF (CMAKE_BUILD_TYPE STREQUAL "") |
| 43 | SET(CMAKE_BUILD_TYPE Release) |
| 44 | ENDIF (CMAKE_BUILD_TYPE STREQUAL "") |
| 45 | |
| 46 | MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}") |
| 47 | |
| 48 | ADD_DEFINITIONS(-DPROJECT_SOURCE_DIR="${CMAKE_SOURCE_DIR}" |
| 49 | -DPROJECT_BINARY_DIR="${CMAKE_BINARY_DIR}") |
| 50 | |
| 51 | # =============================================================== |
| 52 | # Check for existance of various required, optional packages. |
| 53 | # Listed in alphabetical order, more or less. |
| 54 | # CogUtil must come first, because it supplies various FindXXX macros. |
| 55 | |
| 56 | # Add the 'lib' dir to cmake's module search path |
| 57 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/lib/") |
| 58 | |
| 59 | # Cogutil |
| 60 | FIND_PACKAGE(CogUtil 2.0.1 CONFIG REQUIRED) |
| 61 | IF (COGUTIL_FOUND) |
| 62 | MESSAGE(STATUS "CogUtil version ${COGUTIL_VERSION} found.") |
| 63 | ADD_DEFINITIONS(-DHAVE_COGUTIL) |
| 64 | SET(HAVE_COGUTIL 1) |
| 65 | ELSE (COGUTIL_FOUND) |
| 66 | MESSAGE(FATAL_ERROR "CogUtil missing: it is needed!") |
| 67 | ENDIF (COGUTIL_FOUND) |
| 68 | |
| 69 | # add the 'cmake' directory from cogutil to search path |
| 70 | list(APPEND CMAKE_MODULE_PATH ${COGUTIL_DATA_DIR}/cmake) |
| 71 | |
| 72 | include(OpenCogGccOptions) |
| 73 | include(OpenCogLibOptions) |
| 74 | include(OpenCogInstallOptions) |
| 75 | include(Summary) |
| 76 | |
| 77 | # =================================================================== |
| 78 | # Check for existance of various required, optional packages. |
| 79 | |
| 80 | # AtomSpace |
| 81 | FIND_PACKAGE(AtomSpace 5.0.3 CONFIG REQUIRED) |
| 82 | IF (ATOMSPACE_FOUND) |
| 83 | MESSAGE(STATUS "AtomSpace found.") |
| 84 | ADD_DEFINITIONS(-DHAVE_ATOMSPACE) |
| 85 | SET(HAVE_ATOMSPACE 1) |
| 86 | ELSE (ATOMSPACE_FOUND) |
| 87 | MESSAGE(FATAL_ERROR "AtomSpace missing: it is needed!") |
| 88 | ENDIF (ATOMSPACE_FOUND) |
| 89 | |
| 90 | # ---------------------------------------------------------- |
| 91 | # Needed for unit tests |
| 92 | |
| 93 | FIND_PACKAGE(Cxxtest) |
| 94 | IF (NOT CXXTEST_FOUND) |
| 95 | MESSAGE(STATUS "CxxTest missing: needed for unit tests.") |
| 96 | ENDIF (NOT CXXTEST_FOUND) |
| 97 | |
| 98 | # ---------------------------------------------------------- |
| 99 | # Is guile installed? |
| 100 | |
| 101 | include(OpenCogFindGuile) |
| 102 | |
| 103 | # =================================================================== |
| 104 | # Include configuration. |
| 105 | |
| 106 | # Set default include paths. |
| 107 | INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR} |
| 108 | ${COGUTIL_INCLUDE_DIR} ${ATOMSPACE_INCLUDE_DIR}) |
| 109 | |
| 110 | INCLUDE(OpenCogMacros) |
| 111 | INCLUDE(OpenCogGuile) |
| 112 | |
| 113 | # ========================================================== |
| 114 | # Decide what to build, based on the packages found. |
| 115 | |
| 116 | ADD_SUBDIRECTORY(cmake) |
| 117 | ADD_SUBDIRECTORY(opencog) |
| 118 | |
| 119 | IF (CXXTEST_FOUND) |
| 120 | ADD_CUSTOM_TARGET(tests) |
| 121 | ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL) |
| 122 | IF (CMAKE_BUILD_TYPE STREQUAL "Coverage") |
| 123 | # doing coverage stuff while running tests if this is the Coverage build |
| 124 | ADD_CUSTOM_TARGET(check |
| 125 | # TODO lcov should be found by cmake first |
| 126 | # TODO set it up so that we can pick to run coverage per test, or |
| 127 | # combined across all tests (the latter is MUCH faster). Use a define? |
| 128 | # There is coverage specific stuff in AddCxxTest.cmake now... |
| 129 | WORKING_DIRECTORY tests |
| 130 | COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure $(ARGS) |
| 131 | |
| 132 | # This script combines the coverage analysis of each test, |
| 133 | # then creates html in tests/lcov |
| 134 | # Note: this should now be run separately... |
| 135 | #COMMAND ${PROJECT_SOURCE_DIR}/scripts/combine_lcov.sh |
| 136 | COMMENT "Running tests with coverage..." |
| 137 | ) |
| 138 | ELSE (CMAKE_BUILD_TYPE STREQUAL "Coverage") |
| 139 | # Coverage is disabled; test normally |
| 140 | ADD_CUSTOM_TARGET(check |
| 141 | DEPENDS tests |
| 142 | WORKING_DIRECTORY tests |
| 143 | COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure $(ARGS) |
| 144 | COMMENT "Running tests..." |
| 145 | ) |
| 146 | ENDIF (CMAKE_BUILD_TYPE STREQUAL "Coverage") |
| 147 | |
| 148 | ADD_CUSTOM_TARGET(test_mono |
| 149 | DEPENDS tests |
| 150 | WORKING_DIRECTORY tests/persist/monospace |
| 151 | COMMAND ${CMAKE_CTEST_COMMAND} $(ARGS) |
| 152 | COMMENT "Running Monospace tests..." |
| 153 | ) |
| 154 | |
| 155 | ADD_CUSTOM_TARGET(test_multi |
| 156 | DEPENDS tests |
| 157 | WORKING_DIRECTORY tests/persist/matrix |
| 158 | COMMAND ${CMAKE_CTEST_COMMAND} $(ARGS) |
| 159 | COMMENT "Running Multispace tests..." |
| 160 | ) |
| 161 | |
| 162 | ENDIF (CXXTEST_FOUND) |
| 163 | |
| 164 | ADD_CUSTOM_TARGET(cscope |
| 165 | COMMAND find opencog examples tests -name '*.cc' -o -name '*.h' -o -name '*.cxxtest' -o -name '*.scm' > ${CMAKE_SOURCE_DIR}/cscope.files |
| 166 | COMMAND cscope -b |
| 167 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 168 | COMMENT "Generating CScope database" |
| 169 | ) |
| 170 | |
| 171 | # =================================================================== |
| 172 | # Packaging |
| 173 | # XXX FIXME. Packging below is stale/wrong/broken. |
| 174 | ## Architecture the package is for. |
| 175 | ## TODO: Will give error on non debian distros, fix it. |
| 176 | EXECUTE_PROCESS(COMMAND dpkg --print-architecture |
| 177 | OUTPUT_VARIABLE PACKAGE_ARCHITECTURE |
| 178 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 179 | STRING(TIMESTAMP UTC_DATE %Y%m%d UTC) |
| 180 | # If 'sudo make install' is run before 'make package', then install_manifest.txt |
| 181 | # will be owned by root. Creating the file during configuration stage ensures |
| 182 | # that it is owned by the builder thus avoiding 'Permission denied' error when |
| 183 | # packaging. |
| 184 | FILE(WRITE "${PROJECT_BINARY_DIR}/install_manifest.txt") |
| 185 | ## It doesn't have a header-file declaring the version similar to cogutil and |
| 186 | ## atomspace. |
| 187 | # SEMANTIC_VERSION is set in `lib/AtomSpaceMatrixConfig.cmake.in` |
| 188 | # SET(SEMANTIC_VERSION 1.3.0) |
| 189 | |
| 190 | ## Cpack configuration |
| 191 | SET(CPACK_GENERATOR "DEB") |
| 192 | SET(CPACK_PACKAGE_CONTACT "opencog@googlegroups.com") |
| 193 | SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") |
| 194 | SET(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/packages") |
| 195 | SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The AtomSpace Matrix Toolset") |
| 196 | SET(CPACK_PACKAGE_NAME "atomspace-matrix-dev") |
| 197 | SET(CPACK_PACKAGE_VENDOR "opencog.org") |
| 198 | SET(CPACK_PACKAGE_VERSION "${SEMANTIC_VERSION}-${UTC_DATE}") |
| 199 | SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") |
| 200 | SET(CPACK_PACKAGE_FILE_NAME |
| 201 | "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${PACKAGE_ARCHITECTURE}") |
| 202 | SET(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local") |
| 203 | |
| 204 | ## Debian specific configurations |
| 205 | SET(DEPENDENCY_LIST |
| 206 | "guile-3.0-dev (>= 3.0.0)" |
| 207 | "libstdc++6 (>= 7.0)" |
| 208 | "libcogutil-dev (>= 2.0.2)" |
| 209 | "atomspace-dev (>= 5.0.3)" |
| 210 | ) |
| 211 | |
| 212 | STRING(REPLACE ";" ", " MAIN_DEPENDENCIES "${DEPENDENCY_LIST}") |
| 213 | SET(CPACK_DEBIAN_PACKAGE_DEPENDS "${MAIN_DEPENDENCIES}") |
| 214 | SET(CPACK_DEBIAN_PACKAGE_SECTION "libdevel") |
| 215 | SET(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://opencog.org") |
| 216 | INCLUDE(CPack) |
| 217 | |
| 218 | # =================================================================== |
| 219 | # Documentation. |
| 220 | FIND_PACKAGE(Doxygen) |
| 221 | # ADD_SUBDIRECTORY(doc EXCLUDE_FROM_ALL) |
| 222 | |
| 223 | # =================================================================== |
| 224 | # Show a summary of what we found, what we will do. |
| 225 | |
| 226 | SUMMARY_ADD("Matrix" "AtomSpace Sparse Matrix Tools" HAVE_ATOMSPACE) |
| 227 | SUMMARY_ADD("Doxygen" "Code documentation" DOXYGEN_FOUND) |
| 228 | SUMMARY_ADD("Unit tests" "Unit tests" CXXTEST_FOUND) |
| 229 | |
| 230 | SUMMARY_SHOW() |