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
This commit is contained in:
Carles Fernandez 2019-03-22 11:00:13 +01:00
parent c2917939ba
commit cb59c1cc83
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
5 changed files with 96 additions and 17 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 <https://www.gnu.org/licenses/>.
# 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()

View File

@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>

View File

@ -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