|
| 1 | +#------------------------------------------------------------------------------- |
| 2 | +# SuiteSparse/AMD/CMakeLists.txt: cmake for AMD |
| 3 | +#------------------------------------------------------------------------------- |
| 4 | + |
| 5 | +# Copyright (c) 2022, Timothy A. Davis. All Rights Reserved. |
| 6 | +# SPDX-License-Identifier: BSD-3-clause |
| 7 | + |
| 8 | +#------------------------------------------------------------------------------- |
| 9 | +# get the version |
| 10 | +#------------------------------------------------------------------------------- |
| 11 | + |
| 12 | +# cmake 3.17 is required |
| 13 | +cmake_minimum_required ( VERSION 3.17 ) |
| 14 | + |
| 15 | +set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} |
| 16 | + ${CMAKE_SOURCE_DIR}/cmake_modules |
| 17 | + ${CMAKE_SOURCE_DIR}/../cmake_modules |
| 18 | + ${CMAKE_SOURCE_DIR}/../SuiteSparse/cmake_modules |
| 19 | + ) |
| 20 | + |
| 21 | +set ( AMD_DATE "Sept FIXME, 2022" ) |
| 22 | +set ( AMD_VERSION_MAJOR 3 ) |
| 23 | +set ( AMD_VERSION_MINOR 0 ) |
| 24 | +set ( AMD_VERSION_SUB 0 ) |
| 25 | + |
| 26 | +message ( STATUS "Building AMD version: v" |
| 27 | + ${AMD_VERSION_MAJOR}. |
| 28 | + ${AMD_VERSION_MINOR}. |
| 29 | + ${AMD_VERSION_SUB} " (" ${AMD_DATE} ")" ) |
| 30 | + |
| 31 | +project ( amd |
| 32 | + VERSION "${AMD_VERSION_MAJOR}.${AMD_VERSION_MINOR}.${AMD_VERSION_SUB}" |
| 33 | + LANGUAGES C ) # <-- add CXX here for packages that use C++ |
| 34 | + |
| 35 | +message ( STATUS "AMD project: " ${PROJECT_SOURCE_DIR} ) |
| 36 | +message ( STATUS "AMD build: " ${CMAKE_BINARY_DIR} ) |
| 37 | + |
| 38 | +#------------------------------------------------------------------------------- |
| 39 | +# find library dependencies |
| 40 | +#------------------------------------------------------------------------------- |
| 41 | + |
| 42 | +find_package ( OpenMP ) |
| 43 | +find_package ( SuiteSparse_config REQUIRED ) |
| 44 | + |
| 45 | +#------------------------------------------------------------------------------- |
| 46 | +# determine build type |
| 47 | +#------------------------------------------------------------------------------- |
| 48 | + |
| 49 | +if ( NOT CMAKE_BUILD_TYPE ) |
| 50 | + set ( CMAKE_BUILD_TYPE Release ) |
| 51 | +endif ( ) |
| 52 | + |
| 53 | +#------------------------------------------------------------------------------- |
| 54 | +# Configure amd.h with version number |
| 55 | +#------------------------------------------------------------------------------- |
| 56 | + |
| 57 | +configure_file ( |
| 58 | + "Config/amd.h.in" |
| 59 | + "${PROJECT_SOURCE_DIR}/Include/amd.h" |
| 60 | +) |
| 61 | + |
| 62 | +configure_file ( |
| 63 | + "Config/amd_version.tex.in" |
| 64 | + "${PROJECT_SOURCE_DIR}/Doc/amd_version.tex" |
| 65 | +) |
| 66 | + |
| 67 | +#------------------------------------------------------------------------------- |
| 68 | +# report status and set compile flags |
| 69 | +#------------------------------------------------------------------------------- |
| 70 | + |
| 71 | +message ( STATUS "CMAKE build type: " ${CMAKE_BUILD_TYPE} ) |
| 72 | + |
| 73 | +if ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug" ) |
| 74 | + message ( STATUS "CMAKE C Flags debug: " ${CMAKE_C_FLAGS_DEBUG} ) |
| 75 | +# message ( STATUS "CMAKE C++ Flags debug: " ${CMAKE_CXX_FLAGS_DEBUG} ) |
| 76 | +else ( ) |
| 77 | + message ( STATUS "CMAKE C Flags release: " ${CMAKE_C_FLAGS_RELEASE} ) |
| 78 | +# message ( STATUS "CMAKE C++ Flags release: " ${CMAKE_CXX_FLAGS_RELEASE} ) |
| 79 | +endif ( ) |
| 80 | + |
| 81 | +message ( STATUS "CMAKE C compiler: " ${CMAKE_C_COMPILER_ID} ) |
| 82 | +message ( STATUS "CMAKE have OpenMP: " ${OPENMP_FOUND} ) |
| 83 | + |
| 84 | +# message ( STATUS "CMAKE C++ compiler: " ${CMAKE_CXX_COMPILER_ID} ) |
| 85 | + |
| 86 | +#------------------------------------------------------------------------------- |
| 87 | +# include directories |
| 88 | +#------------------------------------------------------------------------------- |
| 89 | + |
| 90 | +set ( CMAKE_INCLUDE_CURRENT_DIR ON ) |
| 91 | +include_directories ( Source Include ${SUITESPARSE_CONFIG_INCLUDE_DIR} ) |
| 92 | + |
| 93 | +#------------------------------------------------------------------------------- |
| 94 | +# dynamic amd library properties |
| 95 | +#------------------------------------------------------------------------------- |
| 96 | + |
| 97 | +file ( GLOB AMD_SOURCES "Source/*.c" ) |
| 98 | + |
| 99 | +add_library ( amd SHARED ${AMD_SOURCES} ) |
| 100 | + |
| 101 | +SET_TARGET_PROPERTIES ( amd PROPERTIES |
| 102 | + VERSION ${AMD_VERSION_MAJOR}.${AMD_VERSION_MINOR}.${AMD_VERSION_SUB} |
| 103 | + SOVERSION ${AMD_VERSION_MAJOR} |
| 104 | + PUBLIC_HEADER "Include/amd.h" ) |
| 105 | + |
| 106 | +#------------------------------------------------------------------------------- |
| 107 | +# static amd library properties |
| 108 | +#------------------------------------------------------------------------------- |
| 109 | + |
| 110 | +add_library ( amd_static STATIC ${AMD_SOURCES} ) |
| 111 | + |
| 112 | +SET_TARGET_PROPERTIES ( amd_static PROPERTIES |
| 113 | + VERSION ${AMD_VERSION_MAJOR}.${AMD_VERSION_MINOR}.${AMD_VERSION_SUB} |
| 114 | + OUTPUT_NAME amd |
| 115 | + SOVERSION ${AMD_VERSION_MAJOR} ) |
| 116 | + |
| 117 | +#------------------------------------------------------------------------------- |
| 118 | +# add the library dependencies |
| 119 | +#------------------------------------------------------------------------------- |
| 120 | + |
| 121 | +target_link_libraries ( amd PUBLIC ${SUITESPARSE_CONFIG_LIBRARY} ) |
| 122 | +target_link_libraries ( amd_static PUBLIC ${SUITESPARSE_CONFIG_LIBRARY} ) |
| 123 | + |
| 124 | +# OpenMP: |
| 125 | +if ( OPENMP_FOUND ) |
| 126 | + message ( STATUS "OpenMP C libraries: " ${OpenMP_C_LIBRARIES} ) |
| 127 | + message ( STATUS "OpenMP C include: " ${OpenMP_C_INCLUDE_DIRS} ) |
| 128 | + message ( STATUS "OpenMP C flags: " ${OpenMP_C_FLAGS} ) |
| 129 | + target_link_libraries ( amd PUBLIC ${OpenMP_C_LIBRARIES} ) |
| 130 | + target_link_libraries ( amd_static PUBLIC ${OpenMP_C_LIBRARIES} ) |
| 131 | + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} " ) |
| 132 | + include_directories ( ${OpenMP_C_INCLUDE_DIRS} ) |
| 133 | +endif ( ) |
| 134 | + |
| 135 | +# libm: |
| 136 | +if ( NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" ) |
| 137 | + target_link_libraries ( amd PUBLIC m ) |
| 138 | + target_link_libraries ( amd_static PUBLIC m ) |
| 139 | +endif ( ) |
| 140 | + |
| 141 | +#------------------------------------------------------------------------------- |
| 142 | +# amd installation location |
| 143 | +#------------------------------------------------------------------------------- |
| 144 | + |
| 145 | +# install in /usr/local/lib and /usr/local/include |
| 146 | +include ( GNUInstallDirs ) |
| 147 | + |
| 148 | +install ( TARGETS amd |
| 149 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 150 | + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) |
| 151 | + |
| 152 | +install ( TARGETS amd_static |
| 153 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) |
| 154 | + |
| 155 | +# also install in ../lib and ../include |
| 156 | +install ( TARGETS amd |
| 157 | + LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/../lib |
| 158 | + PUBLIC_HEADER DESTINATION ${CMAKE_SOURCE_DIR}/../include ) |
| 159 | + |
| 160 | +install ( TARGETS amd_static |
| 161 | + ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/../lib) |
| 162 | + |
| 163 | +#------------------------------------------------------------------------------- |
| 164 | +# Demo library and programs |
| 165 | +#------------------------------------------------------------------------------- |
| 166 | + |
| 167 | +if ( DEMO ) |
| 168 | + |
| 169 | + #--------------------------------------------------------------------------- |
| 170 | + # demo library |
| 171 | + #--------------------------------------------------------------------------- |
| 172 | + |
| 173 | + message ( STATUS "Also compiling the demos in AMD/Demo" ) |
| 174 | + |
| 175 | + #--------------------------------------------------------------------------- |
| 176 | + # Demo programs |
| 177 | + #--------------------------------------------------------------------------- |
| 178 | + |
| 179 | + add_executable ( amd_demo "Demo/amd_demo.c" ) |
| 180 | + add_executable ( amd_l_demo "Demo/amd_l_demo.c" ) |
| 181 | + add_executable ( amd_demo2 "Demo/amd_demo2.c" ) |
| 182 | + add_executable ( amd_simple "Demo/amd_simple.c" ) |
| 183 | + |
| 184 | + # Libraries required for Demo programs |
| 185 | + target_link_libraries ( amd_demo PUBLIC amd ) |
| 186 | + target_link_libraries ( amd_l_demo PUBLIC amd ) |
| 187 | + target_link_libraries ( amd_demo2 PUBLIC amd ) |
| 188 | + target_link_libraries ( amd_simple PUBLIC amd ) |
| 189 | + |
| 190 | +else ( ) |
| 191 | + |
| 192 | + message ( STATUS "Skipping the demos in GraphBLAS/Demo" ) |
| 193 | + |
| 194 | +endif ( ) |
0 commit comments