From cb59c1cc83b089ec5092cbfd5eb46fb88214c226 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 22 Mar 2019 11:00:13 +0100 Subject: [PATCH] Fix bug in MacOS when BeiDou was enabled in rtklib.h The BLAS and LAPACK implementations that come with the Accelerate Framework (soft-linked in /usr/bin) caused a random crash when exiting the program, only if the variable ENABDS was set. This bug disappears when linking to the libraries that Homebrew or Macports install, or when manually downloaded, built and installed by the user --- CMakeLists.txt | 40 ++++++++++++---- README.md | 5 +- cmake/Modules/AvoidAccelerate.cmake | 58 +++++++++++++++++++++++ src/algorithms/libs/rtklib/CMakeLists.txt | 8 +--- src/algorithms/libs/rtklib/rtklib.h | 2 - 5 files changed, 96 insertions(+), 17 deletions(-) create mode 100644 cmake/Modules/AvoidAccelerate.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 547772040..005286a12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1331,14 +1331,30 @@ endif() # Check that BLAS (Basic Linear Algebra Subprograms) is found in the system # See http://www.netlib.org/blas/ ################################################################################ -find_library(BLAS blas) -if(NOT BLAS) +if(OS_IS_MACOSX) + # Avoid using the implementation that comes with the Accelerate framework + include(AvoidAccelerate) +else() + find_package(BLAS) + set_package_properties(BLAS PROPERTIES + URL "http://www.netlib.org/blas/" + DESCRIPTION "Basic Linear Algebra Subprograms" + PURPOSE "Used for matrix algebra computations." + TYPE REQUIRED + ) +endif() +if(NOT BLAS_FOUND) message(" The BLAS library has not been found.") message(" You can try to install it by typing:") - if(${LINUX_DISTRIBUTION} MATCHES "Fedora" OR ${LINUX_DISTRIBUTION} MATCHES "Red Hat") - message(" sudo yum install blas-devel") + if(OS_IS_MACOSX) + message(" 'sudo port install lapack' if you are using Macports, or") + message(" 'brew install lapack' if you are using Homebrew.") else() - message(" sudo apt-get install libblas-dev") + if(${LINUX_DISTRIBUTION} MATCHES "Fedora" OR ${LINUX_DISTRIBUTION} MATCHES "Red Hat") + message(" sudo yum install blas-devel") + else() + message(" sudo apt-get install libblas-dev") + endif() endif() message(FATAL_ERROR "BLAS is required to build gnss-sdr") endif() @@ -1349,8 +1365,16 @@ endif() # Check that LAPACK (Linear Algebra PACKage) is found in the system # See http://www.netlib.org/lapack/ ################################################################################ -find_library(LAPACK lapack) -if(NOT LAPACK) +if(NOT OS_IS_MACOSX) + find_package(LAPACK) + set_package_properties(LAPACK PROPERTIES + URL "http://www.netlib.org/lapack/" + DESCRIPTION "Linear Algebra PACKage" + PURPOSE "Used for matrix algebra computations." + TYPE REQUIRED + ) +endif() +if(NOT LAPACK_FOUND) message(" The LAPACK library has not been found.") message(" You can try to install it by typing:") if(${LINUX_DISTRIBUTION} MATCHES "Fedora" OR ${LINUX_DISTRIBUTION} MATCHES "Red Hat") @@ -1457,7 +1481,7 @@ if(NOT ARMADILLO_FOUND OR ENABLE_OWN_ARMADILLO) if(NOT GFORTRAN) set(GFORTRAN "") endif() - set(ARMADILLO_LIBRARIES ${BLAS} ${LAPACK} ${GFORTRAN} ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}armadillo${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(ARMADILLO_LIBRARIES ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN} ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}armadillo${CMAKE_STATIC_LIBRARY_SUFFIX}) set(LOCAL_ARMADILLO true CACHE STRING "Armadillo downloaded and built automatically" FORCE) set(ARMADILLO_VERSION_STRING ${armadillo_RELEASE}) file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/armadillo/armadillo-${armadillo_RELEASE}/include) diff --git a/README.md b/README.md index 4e6e0b11c..0cec356ac 100644 --- a/README.md +++ b/README.md @@ -545,6 +545,7 @@ $ sudo port selfupdate $ sudo port upgrade outdated $ sudo port install doxygen +docs $ sudo port install gnuradio +$ sudo port install lapack $ sudo port install armadillo $ sudo port install gnutls $ sudo port install google-glog +gflags @@ -586,7 +587,9 @@ Install the required dependencies: ~~~~~~ $ brew install cmake -$ brew install hdf5 arpack superlu armadillo +$ brew install hdf5 +$ brew install lapack +$ brew install arpack superlu armadillo $ brew install glog gflags $ brew install gnuradio $ brew install libmatio diff --git a/cmake/Modules/AvoidAccelerate.cmake b/cmake/Modules/AvoidAccelerate.cmake new file mode 100644 index 000000000..ab6e54cde --- /dev/null +++ b/cmake/Modules/AvoidAccelerate.cmake @@ -0,0 +1,58 @@ +# Copyright (C) 2011-2019 (see AUTHORS file for a list of contributors) +# +# This file is part of GNSS-SDR. +# +# GNSS-SDR is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GNSS-SDR is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNSS-SDR. If not, see . + +# Avoid using the BLAS and LAPACK implementations that comes with the Accelerate +# framework, which causes a bug when the BeiDou constellation is enabled + +find_library(BLAS_LIBRARIES + libblas.dylib + PATHS + /opt/local/lib/lapack + /usr/local/opt/lapack/lib + /usr/local/lib + ${BLAS_ROOT}/lib + $ENV{BLAS_ROOT}/lib + NO_DEFAULT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH +) + +if(BLAS_LIBRARIES) + set(BLAS_FOUND TRUE) +endif() + + +find_library(LAPACK_LIBRARIES + liblapack.dylib + PATHS + /opt/local/lib/lapack + /usr/local/opt/lapack/lib + /usr/local/lib + ${BLAS_ROOT}/lib + $ENV{BLAS_ROOT}/lib + NO_DEFAULT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH +) + +if(LAPACK_LIBRARIES) + set(LAPACK_FOUND TRUE) +endif() diff --git a/src/algorithms/libs/rtklib/CMakeLists.txt b/src/algorithms/libs/rtklib/CMakeLists.txt index f15c1c074..814ad6eaf 100644 --- a/src/algorithms/libs/rtklib/CMakeLists.txt +++ b/src/algorithms/libs/rtklib/CMakeLists.txt @@ -70,14 +70,10 @@ target_link_libraries(algorithms_libs_rtklib core_system_parameters Gflags::gflags Glog::glog + ${LAPACK_LIBRARIES} + ${BLAS_LIBRARIES} ) -if(OS_IS_MACOSX) - target_link_libraries(algorithms_libs_rtklib PRIVATE "-framework Accelerate") -else() - target_link_libraries(algorithms_libs_rtklib PRIVATE ${LAPACK} ${BLAS}) -endif() - set_property(TARGET algorithms_libs_rtklib APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $ diff --git a/src/algorithms/libs/rtklib/rtklib.h b/src/algorithms/libs/rtklib/rtklib.h index 1b8cd9cbe..0f8cf61b7 100644 --- a/src/algorithms/libs/rtklib/rtklib.h +++ b/src/algorithms/libs/rtklib/rtklib.h @@ -215,9 +215,7 @@ const int NSATQZS = 0; const int NSYSQZS = 0; #endif -#ifndef __APPLE__ #define ENABDS -#endif #ifdef ENABDS const int MINPRNBDS = 1; //!< min satellite sat number of BeiDou const int MAXPRNBDS = 37; //!< max satellite sat number of BeiDou