diff --git a/CMakeLists.txt b/CMakeLists.txt index d604a9acf..404ff894f 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,34 @@ 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() + +# 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 @@ -173,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 @@ -262,7 +287,6 @@ target_link_libraries_system( target_link_libraries( ${QSYN_LIB_NAME} PRIVATE - lapack # OpenMP::OpenMP_CXX ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}) @@ -289,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) @@ -321,7 +352,6 @@ target_link_libraries_system( target_link_libraries( ${CMAKE_PROJECT_NAME} PRIVATE - lapack # OpenMP::OpenMP_CXX ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}) @@ -367,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 feb38a9e6..1c8bf72ad 100644 --- a/src/duostra/duostra_def.hpp +++ b/src/duostra/duostra_def.hpp @@ -8,6 +8,7 @@ #pragma once +#include #include #include #include