From b96267e80512890fa7b06b55753583420971526c Mon Sep 17 00:00:00 2001 From: Mu-Te Date: Thu, 29 Jan 2026 23:56:41 -0600 Subject: [PATCH 1/2] fix: Use pkg-config directly for BLAS/LAPACK on Linux --- CMakeLists.txt | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d604a9ac..98cc011c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,10 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_RELEASE "-O3") # Set BLA_VENDOR before project() so it's available during initialization -# Use CACHE so it persists across build directories (release vs debug) -set(BLA_VENDOR OpenBLAS CACHE STRING "BLAS vendor to search for") -# Prefer pkg-config on Linux where it works, but not on macOS where OpenBLAS -# from Homebrew doesn't provide pkg-config files -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - set(BLA_PREFER_PKGCONFIG ON CACHE BOOL "Prefer pkg-config for BLAS") +# On macOS, we need to specify OpenBLAS explicitly +# On Linux, we'll use pkg-config instead (see find_package(BLAS) below) +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(BLA_VENDOR OpenBLAS CACHE STRING "BLAS vendor to search for") endif() include(FetchContent) @@ -93,8 +91,26 @@ include(scripts/cmake/target_link_libraries_system.cmake) # find_package(OpenMP REQUIRED) -find_package(BLAS REQUIRED) -find_package(LAPACK REQUIRED) +# Use pkg-config to find BLAS and LAPACK on Linux where it's available and reliable +# On macOS, OpenBLAS from Homebrew doesn't provide pkg-config files, so use FindBLAS instead +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(BLAS IMPORTED_TARGET blas) + pkg_check_modules(LAPACK IMPORTED_TARGET lapack) + if(BLAS_FOUND AND LAPACK_FOUND) + # Set variables expected by the rest of the build + set(BLAS_LIBRARIES PkgConfig::BLAS) + set(LAPACK_LIBRARIES PkgConfig::LAPACK) + endif() + endif() +endif() + +# If pkg-config didn't find BLAS/LAPACK (or we're not on Linux), use CMake's find_package +if(NOT BLAS_FOUND OR NOT LAPACK_FOUND) + find_package(BLAS REQUIRED) + find_package(LAPACK REQUIRED) +endif() FetchContent_Declare( xtl From 9587797f490e4ec1c6bfdec4a85b4fc39ab3f309 Mon Sep 17 00:00:00 2001 From: Mu-Te Date: Fri, 30 Jan 2026 15:49:28 -0600 Subject: [PATCH 2/2] Fix BLAS/LAPACK detection and GCC-13 compatibility --- CMakeLists.txt | 26 ++++++++++++++++++++++++-- src/duostra/duostra_def.hpp | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98cc011c..404ff894 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,14 @@ if(NOT BLAS_FOUND OR NOT LAPACK_FOUND) find_package(LAPACK REQUIRED) endif() +# Ensure BLAS_LIBRARIES and LAPACK_LIBRARIES are set +if(NOT BLAS_LIBRARIES) + set(BLAS_LIBRARIES ${BLAS_openblas_LIBRARY}) +endif() +if(NOT LAPACK_LIBRARIES) + set(LAPACK_LIBRARIES ${LAPACK_openblas_LIBRARY}) +endif() + FetchContent_Declare( xtl SYSTEM @@ -189,6 +197,7 @@ FetchContent_Declare( FetchContent_MakeAvailable(cadical) # --- libabc (patched for new CMake) --- +set(READLINE_FOUND FALSE CACHE BOOL "Disable readline in libabc") FetchContent_Declare( libabc SYSTEM @@ -278,7 +287,6 @@ target_link_libraries_system( target_link_libraries( ${QSYN_LIB_NAME} PRIVATE - lapack # OpenMP::OpenMP_CXX ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}) @@ -305,6 +313,13 @@ target_compile_options( target_compile_options( ${CMAKE_PROJECT_NAME} PRIVATE -Wno-missing-field-initializers) +# GCC-specific: disable -Wmaybe-uninitialized (has false positives with templates) +check_cxx_compiler_flag(-Wno-maybe-uninitialized COMPILER_SUPPORTS_WNO_MAYBE_UNINITIALIZED) +if(COMPILER_SUPPORTS_WNO_MAYBE_UNINITIALIZED) + target_compile_options( + ${CMAKE_PROJECT_NAME} PRIVATE -Wno-maybe-uninitialized) +endif() + # GCC 12+ is too strict about restrict warnings in std::string operations # Only apply to GCC, as Clang doesn't support this flag check_cxx_compiler_flag(-Wno-restrict COMPILER_SUPPORTS_WNO_RESTRICT) @@ -337,7 +352,6 @@ target_link_libraries_system( target_link_libraries( ${CMAKE_PROJECT_NAME} PRIVATE - lapack # OpenMP::OpenMP_CXX ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}) @@ -383,6 +397,14 @@ target_compile_options( PRIVATE -Wno-missing-field-initializers) +# GCC-specific: disable -Wmaybe-uninitialized (has false positives with templates) +if(COMPILER_SUPPORTS_WNO_MAYBE_UNINITIALIZED) + target_compile_options( + ${UNIT_TEST_NAME} + PRIVATE + -Wno-maybe-uninitialized) +endif() + # GCC 12+ is too strict about restrict warnings in std::string operations # Only apply to GCC, as Clang doesn't support this flag if(COMPILER_SUPPORTS_WNO_RESTRICT) diff --git a/src/duostra/duostra_def.hpp b/src/duostra/duostra_def.hpp index feb38a9e..1c8bf72a 100644 --- a/src/duostra/duostra_def.hpp +++ b/src/duostra/duostra_def.hpp @@ -8,6 +8,7 @@ #pragma once +#include #include #include #include