CMake scripts for painless usage of SuiteSparse+METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake

Overview

Build Status Grunt status

CMake scripts for painless usage of Tim Davis' SuiteSparse (CHOLMOD,UMFPACK,AMD,LDL,SPQR,...) and METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake. The project includes precompiled BLAS/LAPACK DLLs for easy use with Visual C++. Licensed under BSD 3-Clause License.

The goal is using one single CMake code to build against SuiteSparse in standard Linux package systems (e.g. libsuitesparse-dev) and in manual compilations under Windows.

Credits: Jose Luis Blanco (Universidad de Almeria); Jerome Esnault (INRIA); @NeroBurner

logo

1. Instructions

  • (1) Install CMake.

  • (2) Only for Linux/Mac: Install LAPACK & BLAS. In Debian/Ubuntu: sudo apt-get install liblapack-dev libblas-dev

  • (3) Clone or download this project (latest release) and extract it somewhere in your disk, say SP_ROOT.

    • (OPTIONAL) CMake will download SuiteSparse sources automatically for you (skip to step 4), but you may do it manually if preferred:
      • Populate the directories within SP_ROOT with the original sources from each project:
        • SuiteSparse:
          • Download SuiteSparse-X.Y.Z.tar.gz from Tim Davis' webpage.
          • Extract it.
          • Merge (e.g. copy and paste from Windows Explorer) the tree SuiteSparse/* into SP_ROOT/SuiteSparse/*.
          • Make sure of looking for patches in the original webpage and apply them to prevent build errors.
        • METIS: (Optional, only if need METIS for partitioning)
          • Download metis-X.Y.Z.tar.gz.
          • Extract it.
          • Merge the tree metis-X.Y.Z/* into SP_ROOT/metis/*.
          • Add the command cmake_policy(SET CMP0022 NEW) right after the line project(METIS) in metis/CMakeLists.txt.
  • (4) Run CMake (cmake-gui), then:

    • Set the "Source code" directory to SP_ROOT
    • Set the "Build" directory to any empty directory, typically SP_ROOT/build
    • Press "Configure", change anything (if needed)
    • Important: I recommend setting the CMAKE_INSTALL_PREFIX to some other directory different than "Program Files" or "/usr/local" so the INSTALL command does not require Admin privileges. By default it will point to SP_ROOT/build/install.
    • If you have an error like: "Cannot find source file: GKlib/conf/check_thread_storage.c", then manually adjust GKLIB_PATH to the correct path SP_ROOT/metis/GKlib.
    • HAVE_COMPLEX is OFF by default to avoid errors related to complex numbers in some compilers.
    • Press "Generate".
  • (5) Compile and install:

    • In Visual Studio, open SuiteSparseProject.sln and build the INSTALL project in Debug and Release. You may get hundreds of warnings, but it's ok.
    • In Unix: Just execute make install or sudo make install if you did set the install prefix to /usr/*
  • (6) Notice that a file SuiteSparseConfig.cmake should be located in your install directory. It will be required for your programs to correctly build and link against SuiteSparse.

  • (7) Only for Windows: You will have to append CMAKE_INSTALL_PREFIX\lib*\lapack_blas_windows\ and CMAKE_INSTALL_PREFIX\lib* to the environment variable PATH before executing any program, for Windows to localize the required BLAS/Fortran libraries (.DLLs).

2. Test program

Example CMake programs are provided for testing, based on Tim Davis' code in his manual:

An example to test CUDA support can be found here.

3. Integration in your code (unique code for Windows/Linux)

  • Add a block like this to your CMake code (see complete example), and set the CMake variable SuiteSparse_DIR to SP_INSTALL_DIR/lib/cmake/suitesparse-5.4.0/ or the equivalent place where SuiteSparse-config.cmake was installed.

    # ------------------------------------------------------------------
    # Detect SuiteSparse libraries:
    # If not found automatically, set SuiteSparse_DIR in CMake to the
    # directory where SuiteSparse-config.cmake was installed.
    # ------------------------------------------------------------------
    find_package(SuiteSparse CONFIG REQUIRED)
    target_link_libraries(MY_PROGRAM PRIVATE ${SuiteSparse_LIBRARIES})
    
    # or directly add only the libs you need:
    target_link_libraries(MY_PROGRAM PRIVATE
      	SuiteSparse::suitesparseconfig
      	SuiteSparse::amd
      	SuiteSparse::btf
      	SuiteSparse::camd
      	SuiteSparse::ccolamd
      	SuiteSparse::colamd
      	SuiteSparse::cholmod
      	SuiteSparse::cxsparse
      	SuiteSparse::klu
      	SuiteSparse::ldl
      	SuiteSparse::umfpack
      	SuiteSparse::spqr
      	SuiteSparse::metis
      )
    
  • In Windows, if you have a CMake error like:

    Could not find a package configuration file provided by "LAPACK" with any
     of the following names:
    
       LAPACKConfig.cmake
       lapack-config.cmake
    

    set the CMake variable LAPACK_DIR to SP_ROOT/lapack_windows/x64/ (or x32 for 32bit builds).

4. Why did you create this project?

Porting SuiteSparse to CMake wasn't trivial because this package makes extensive usage of a one-source-multiple-objects philosophy by compiling the same sources with different compiler flags, and this ain't directly possible to CMake's design.

My workaround to this limitation includes auxiliary Python scripts and dummy source files, so the whole thing became large enough to be worth publishing online so many others may benefit.

Comments
  • Unresolved external symbol: METIS_NODEND and METIS_ComputeVertexSeparator

    Unresolved external symbol: METIS_NODEND and METIS_ComputeVertexSeparator

    I have problems with unresolved symbols similar to #7 when using suitesparse and ceres:

    1>libcholmod.lib(cholmod_metis.o.obj) : error LNK2019: unresolved external symbol METIS_NodeND referenced in function cholmod_metis
    1>libcholmod.lib(cholmod_metis.o.obj) : error LNK2019: unresolved external symbol METIS_ComputeVertexSeparator referenced in function cholmod_metis_bisector
    

    Versions:

    • Compiler: VS 2017
    • Suitesparse-Metis: 1.4.0 (static)
    • Ceres: 1.14.0 (static)
    • OpenBLAS: 0.3.5 (shared)
    • clapack: 3.2.1 (static)
    • CMake: 3.14.0

    A similar setup is working on a PC with VS 2015, but I think the problem is not related to the compiler itself. The libraries should be setup in a similar way as well, but I am not 100% sure about all CMake options (the old installation is a bit older than the new one). Any hints about possible causes of the error are welcome.

    I need to look into a minimal example program, because I am not using suitesparse-metis directly.

    opened by aschier 23
  • Unresolved external: METIS

    Unresolved external: METIS

    Hi, Compilation with Metis goes ok but when I compile the cholmod example it says

    libcholmod.lib(cholmod_metis.o.obj) : error LNK2019: unresolved external symbol _METIS_NodeComputeSeparator referenced in function _cholmod_metis_bisector

    I'm using SuiteSparse 4.4.3 and I've tried Metis 5.0 and 5.1.

    opened by plumonito 11
  • Could NOT find BLAS

    Could NOT find BLAS

    Here is the error message: Could NOT find BLAS (missing: BLAS_LIBRARIES) Could NOT find BLAS (missing: BLAS_LIBRARIES) LAPACK requires BLAS A library with LAPACK API not found. Please specify library location. Configuring done

    I have set the path to the folder which contains these: image

    but still has this issue.

    opened by What-a-stupid-username 9
  • CMake Error: include called with wrong number of arguments.  include() only takes one file

    CMake Error: include called with wrong number of arguments. include() only takes one file

    I finish the Instructions part, and there is no problem. But when it comes to Test program part, I try to generate Visual Studio projects for spqr using provided CMakeLists.txt, I have the following error:

    CMake Error at CMakeLists.txt:27 (include): include called with wrong number of arguments. include() only takes one file.

    I check the CMakeLists.txt, and can't find where the USE_SuiteSparse comes from. Then I just comment out some code like this:

    LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmakemodule/") # Add the directory where FindSuiteSparse.cmake module can be found.
    
    set(SuiteSparse_USE_LAPACK_BLAS ON)
    find_package(SuiteSparse QUIET NO_MODULE)  # 1st: Try to locate the *config.cmake file.
    if(NOT SuiteSparse_FOUND)
            #set(SuiteSparse_VERBOSE ON)
            find_package(SuiteSparse REQUIRED) # 2nd: Use FindSuiteSparse.cmake module
            include_directories(${SuiteSparse_INCLUDE_DIRS})
    else()
            # I comment out the following 2 lines of code using USE_SuiteSparse variable
            # message(STATUS "Find SuiteSparse : include(${USE_SuiteSparse})")
            # include(${USE_SuiteSparse})
    endif()
    

    Then, I can successfully generate the Visual Studio Solution and it seems to work.

    So, I don't know whether my fix is the correct way and whether there is a bug in the CMakeLists.txt?

    opened by whiteeat 8
  • problem on windows visual studio 2013 express

    problem on windows visual studio 2013 express

    I followed your guide and created a project for msvs 2013. However, compiling gives an error in the cxsparse project.

    error C2143: syntax error : missing ';' before '*

    in cs.h for project cxsparse

    Is this simply a suitesparse problem or someway related to the package? Anyone else has similar issues? I use version 4.2.1

    Cheers

    opened by flj 8
  • Update examples to use generated suitesparse-config.cmake

    Update examples to use generated suitesparse-config.cmake

    related Issues:

    • https://github.com/jlblancoc/suitesparse-metis-for-windows/issues/85
    • https://github.com/jlblancoc/suitesparse-metis-for-windows/issues/80
    • https://github.com/jlblancoc/suitesparse-metis-for-windows/issues/87#issuecomment-481974332

    could someone try those examples on Windows with Visual Studio? I have tested them on Linux

    Also we still need to update the README.md Section 3. Integration in your code https://github.com/jlblancoc/suitesparse-metis-for-windows#3-integration-in-your-code-unique-code-for-windowslinux

    mabye also add a list of the available SuiteSparse:: targets

    	SuiteSparse::suitesparseconfig
    	SuiteSparse::amd
    	SuiteSparse::btf
    	SuiteSparse::camd
    	SuiteSparse::ccolamd
    	SuiteSparse::colamd
    	SuiteSparse::cholmod
    	SuiteSparse::cxsparse
    	SuiteSparse::klu
    	SuiteSparse::ldl
    	SuiteSparse::umfpack
    	SuiteSparse::spqr
    	SuiteSparse::metis
    
    opened by NeroBurner 7
  • Error to build example project if enable BUILD_METIS

    Error to build example project if enable BUILD_METIS

    Hi Jose Luis Blanco,

    First of all, thanks for creating this project!

    When I build the project with BUILD_METIS on, everything builds fine. However if I build the example project "cholmod", a linking error shows "METIS_NodeComputeSeparator" cannot be found in any .lib file (I checked that all lib files were correctly linked). I believe this might be due to the reason that the METIS 5.1.0 do not have this function anymore. Maybe we should switch back to METIS 4?

    Best, Chen

    opened by simbaforrest 7
  • Windows shared build failed

    Windows shared build failed

    Hello, I use Windows 7 64 bits with Visual studio 2012.

    I tried to compile suitesparse under windows with SHARED=ON. The build failed because lib/suitesparse_config.lib was not found. cmake clearly wants to build the shared libs, but it's still looking for statically linked libraries.

    Best regards,

    YC

    opened by ycollet 7
  • Problems building from Matlab R2018a with

    Problems building from Matlab R2018a with "Visual Studio 15 2017"

    Are there any updates that apply to this? I use windows 10. I get a lot of the following when building from Matlab R2018a with "Visual Studio 15 2017" :

    ....\metis-5.1.0\GKlib\gk_types.h(22): error C2061: syntax error: identifier 'gk_idx_t' ....\metis-5.1.0\GKlib\gk_types.h(22): error C2059: syntax error: ';' ....\metis-5.1.0\GKlib\gk_struct.h(24): error C2061: syntax error: identifier 'ssize_t' ....\metis-5.1.0\GKlib\gk_struct.h(24): error C2059: syntax error: '}' ....\metis-5.1.0\GKlib\gk_struct.h(25): error C2061: syntax error: identifier 'ssize_t' ....\metis-5.1.0\GKlib\gk_struct.h(25): error C2059: syntax error: '}' ....\metis-5.1.0\GKlib\gk_struct.h(26): error C2061: syntax error: identifier 'ssize_t' ....\metis-5.1.0\GKlib\gk_struct.h(26): error C2059: syntax error: '}' ....\metis-5.1.0\GKlib\gk_struct.h(27): error C2061: syntax error: identifier 'ssize_t' ....\metis-5.1.0\GKlib\gk_struct.h(27): error C2059: syntax error: '}' ....\metis-5.1.0\GKlib\gk_struct.h(28): error C2061: syntax error: identifier 'ssize_t' ....\metis-5.1.0\GKlib\gk_struct.h(28): error C2061: syntax error: identifier 'val' ....\metis-5.1.0\GKlib\gk_struct.h(28): error C2059: syntax error: ';' ....\metis-5.1.0\GKlib\gk_struct.h(28): error C2059: syntax error: '}'

    Yet I can use make/cmake to create METIS.sln Visual Studio Project that I seem to be able to compile I also seem to have similar problems compiling directly from Cygwin. (Somewhere I saw a comment that this is untested).

    opened by plebelshawca 6
  • GPU support in Windows

    GPU support in Windows

    Hi there, Firstly, thanks for maintaining this cmake repo - it's been really helpful in my domain of applications (especially with Ceres Solver)!

    During my recent attempt to compile this code with CUDA support on Windows, I edited some bits that can lead to a successful build using MSVC 2015. By no means these are perfect but I was wondering if some of these may be applicable to others who want similar build conditions.

    Looking forward to hearing back.

    Best, John

    opened by jhh37 6
  • Errors when compile with WITH_CUDA option

    Errors when compile with WITH_CUDA option

    I got some errors when compile suitesparse with WITH_CUDA option enabled. "GPUQREngine.hpp" cannot be opened for compiling SPQR. And some "unknown size" errors in t_cholmod_gpu.c.

    I use the lastest package 1.3.0 with VS 2013, Windows 10 64bit

    opened by letienhung 6
  • multiple definition

    multiple definition

    I had installed these. When I use these to compile G2O, I got into trouble:

    D:/MinGW/libraries/lib/libcxsparse.a(cs_util_di.o.c.obj):cs_util_di.o.c:(.text+0x1e0): multiple definition of cs_di_spfree' ../../../../bin/libg2o_csparse_extension.dll.a(d000026.o):(.text+0x0): first defined here D:/MinGW/libraries/lib/libcxsparse.a(cs_util_di.o.c.obj):cs_util_di.o.c:(.text+0x220): multiple definition ofcs_di_nfree' ../../../../bin/libg2o_csparse_extension.dll.a(d000021.o):(.text+0x0): first defined here D:/MinGW/libraries/lib/libcxsparse.a(cs_util_di.o.c.obj):cs_util_di.o.c:(.text+0x2b0): multiple definition of cs_di_sfree' ../../../../bin/libg2o_csparse_extension.dll.a(d000024.o):(.text+0x0): first defined here D:/MinGW/libraries/lib/libcxsparse.a(cs_malloc_di.o.c.obj):cs_malloc_di.o.c:(.text+0x0): multiple definition ofcs_di_malloc' ../../../../bin/libg2o_csparse_extension.dll.a(d000019.o):(.text+0x0): first defined here D:/MinGW/libraries/lib/libcxsparse.a(cs_malloc_di.o.c.obj):cs_malloc_di.o.c:(.text+0x20): multiple definition of cs_di_calloc' ../../../../bin/libg2o_csparse_extension.dll.a(d000007.o):(.text+0x0): first defined here D:/MinGW/libraries/lib/libcxsparse.a(cs_malloc_di.o.c.obj):cs_malloc_di.o.c:(.text+0x40): multiple definition ofcs_di_free' ../../../../bin/libg2o_csparse_extension.dll.a(d000014.o):(.text+0x0): first defined here collect2.exe: error: ld returned 1 exit status

    Any help would be really appreciated.

    opened by boyob 1
  • In cuda test example, program is finished regularly, but the summary shows that GPU is not called.

    In cuda test example, program is finished regularly, but the summary shows that GPU is not called.

    I followed the example: https://gist.github.com/andr3wmac/78d294844484cb48342f88ef03e2776a The matrix is "nd6k: https://www.cise.ufl.edu/research/sparse/MM/ND/nd6k.tar.gz"

    The program is finished regularly, but the summary shows that GPU is not called.

    The summary is:

    CHOLMOD GPU/CPU statistics: SYRK CPU calls 799 time 3.7243e+00 GPU calls 0 time 0.0000e+00 GEMM CPU calls 628 time 2.0252e+00 GPU calls 0 time 0.0000e+00 POTRF CPU calls 172 time 2.9389e+00 GPU calls 0 time 0.0000e+00 TRSM CPU calls 171 time 1.1470e+00 GPU calls 0 time 0.0000e+00

    opened by luoyin500 1
  • How to compile suitesparse for Windows on Linux with mingw ?

    How to compile suitesparse for Windows on Linux with mingw ?

    I am working a cross compiling project on Linux for Windows. My project needs this suitesparse package. I have cross compiled BLAS and LAPACK through MXE. However, I couldn't use the same progress to cross compile "suitesparse-metis-for-windows".

    If I want to cross compile suitesparse through mingw, is there any tutorial or comment? Thanks.

    opened by G86char 9
  • Broken CMakeList on Linux

    Broken CMakeList on Linux

    There are two typos in two CMakeLists that break the build on linux system.

    1. https://github.com/jlblancoc/suitesparse-metis-for-windows/blob/master/CMakeLists.txt#L213 FIND_PACKAGE(cuda) -> FIND_PACKAGE(CUDA) The lowercase 'cuda' is not recognized on linux which is case sensitive

    2. https://github.com/jlblancoc/suitesparse-metis-for-windows/blob/master/SuiteSparse/GPUQREngine/CMakeLists.txt#L9 CUDA_ADD_LIBRARY(GPUQREngine STATIC ${LIBHDRS} ${LIBSRCS}) Forcing a static GPUQR compilation prevent the building a suite-sparse as a shared lib. This Flag should be removed since the type of the build can be globally managed by the BUILD_SHARED_LIBS, see https://cmake.org/cmake/help/v3.0/variable/BUILD_SHARED_LIBS.html

    opened by jcouet 2
  • Better Support for using MKL as the Blas/Lapack Library

    Better Support for using MKL as the Blas/Lapack Library

    Thanks for maintaining this! It has made my life a lot easier. However, it would be nice to have better built-in support for building suitesparse with Intel's MKL.

    This PR adds a new option: USE_MKL. When this is ON (Off by default), it will use the FindMKL.cmake module to find an installed version of MKL.

    My cmake skills are not the best, so any suggestions for improvement are appreciated.

    Thanks, Kyle

    opened by kylemacfarlan 0
Releases(v1.5.0)
Owner
Jose Luis Blanco-Claraco
Robotics software developer. Lead developer of @MRPT since 2005. Associate Professor at University of Almería in sunny & windy Almería (Spain) :es: ☀ 🏄
Jose Luis Blanco-Claraco
🍩 A XMake integration in Visual Studio Code

xmake-vscode A XMake integration in Visual Studio Code Introduction A XMake integration in Visual Studio Code. You need install xmake first and a proj

xmake-io 127 Oct 1, 2022
Example library that shows best practices and proper usage of CMake by using targets

Modern CMake Sample Sample project that shows proper modern CMake usage on a dummy library and an executable that uses it. Accompanying code to my blo

Pablo Arias 578 Oct 1, 2022
CMake toolchain file and other scripts for the Android NDK

android-cmake CMake is great, and so is Android. This is a collection of CMake scripts that may be useful to the Android NDK community. It is based on

Andrey Kamaev 1.2k Oct 4, 2022
CMake and other scripts to help build process of FlyEM software

The BuildEM System The buildem repo is a modular CMake-based system that leverages CMake's ExternalProject to simplify and automate a complex build pr

null 27 Jun 9, 2022
Extra modules and scripts for CMake.

Extra CMake Modules Introduction The Extra CMake Modules package, or ECM, adds to the modules provided by CMake, including ones used by find_package()

KDE GitHub Mirror 101 Sep 23, 2022
CMake scripts for building OpenSceneGraph third party libraries.

osg-3rdparty-cmake CMake scripts for building OpenSceneGraph third party libraries. These scripts can be used to build third party libraries from sour

Björn Blissing 153 Aug 11, 2022
CMake scripts shared among other repositories

cmake-scripts Common CMake tools and wrappers to use in other repositories. scripts.cmake A wrapper file including all other CMake modules: conan.cmak

Mateusz Pusz 9 Jan 17, 2022
Disassembler for compiled Lua scripts

Luad English | Русский Luad - Disassembler for compiled Lua scripts. At the moment the program is in development (v0.12-pre-alpha). Supported compiler

Vitaliy Vorobets 11 Aug 26, 2022
CMake module to enable code coverage easily and generate coverage reports with CMake targets.

CMake-codecov CMake module to enable code coverage easily and generate coverage reports with CMake targets. Include into your project To use Findcodec

HPC 80 Sep 27, 2022
unmaintained - CMake module to activate certain C++ standard, feature checks and appropriate automated workarounds - basically an improved version of cmake-compile-features

Compatibility This library provides an advanced target_compile_features() and write_compiler_detection_header(). The problem with those is that they a

Jonathan Müller 72 Apr 14, 2022
📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Setup-free CMake dependency management CPM.cmake is a CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper

CPM.cmake 1.4k Oct 2, 2022
CMake checks cache helper modules – for fast CI CMake builds!

cmake-checks-cache Cross platform CMake projects do platform introspection by the means of "Check" macros. Have a look at CMake's How To Write Platfor

Cristian Adam 60 Aug 17, 2022
cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-font-lock - Advanced, type aware, highlight support for CMake

Anders Lindgren 37 Dec 30, 2021
cmake-avr - a cmake toolchain for AVR projects

cmake-avr - a cmake toolchain for AVR projects Testing the example provided The toolchain was created and tested within the following environment: Lin

Matthias Kleemann 161 Oct 2, 2022
Make CMake less painful when trying to write Modern Flexible CMake

Izzy's eXtension Modules IXM is a CMake library for writing Modern flexible CMake. This means: Reducing the amount of CMake written Selecting reasonab

IXM 107 Sep 1, 2022
[CMake] [BSD-2] CMake module to find ICU

FindICU.cmake A CMake module to find International Components for Unicode (ICU) Library Note that CMake, since its version 3.7.0, includes a FindICU m

julp 28 Sep 1, 2022
Installation example for a C++ project (Windows) with Cmake.

CMakeInstallExample Installation example for a C++ project (Windows) with Cmake. Contents This project demonstrates how to use cmake with cpack to gen

Paul T 28 Jul 13, 2022
CMake module for building Windows Installer packages with WiX toolset

FindWiX CMake module for building Windows Installer packages with WiX toolset Introduction Requirements Usage find_package() wix_add_project() WiX com

Apriorit Inc. 11 Aug 5, 2022
C++ Library Manager for Windows, Linux, and MacOS

Vcpkg: Overview 中文总览 Español 한국어 Français Vcpkg helps you manage C and C++ libraries on Windows, Linux and MacOS. This tool and ecosystem are constant

Microsoft 16.8k Sep 26, 2022