Compile tests but fail linking
This commit is contained in:
54
external/CMakeLists.txt
vendored
54
external/CMakeLists.txt
vendored
@@ -1,4 +1,4 @@
|
||||
# External dependencies CMakeLists.txt - Fixed version with OBJECT libraries
|
||||
# External dependencies CMakeLists.txt - Fixed version with proper BLAS handling
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
@@ -23,7 +23,7 @@ FetchContent_Declare(
|
||||
)
|
||||
FetchContent_MakeAvailable(liblinear)
|
||||
|
||||
# Build libsvm as OBJECT library to avoid export issues
|
||||
# Build libsvm as OBJECT library
|
||||
if(EXISTS "${libsvm_SOURCE_DIR}/svm.cpp")
|
||||
set(LIBSVM_SOURCES "${libsvm_SOURCE_DIR}/svm.cpp")
|
||||
|
||||
@@ -31,7 +31,7 @@ if(EXISTS "${libsvm_SOURCE_DIR}/svm.cpp")
|
||||
|
||||
# Set properties for the object library
|
||||
target_include_directories(libsvm_objects
|
||||
PRIVATE
|
||||
PUBLIC
|
||||
${libsvm_SOURCE_DIR}
|
||||
)
|
||||
|
||||
@@ -49,8 +49,9 @@ else()
|
||||
set(LIBSVM_INCLUDE_DIR "" PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
# Build liblinear as OBJECT library
|
||||
# Build liblinear with BLAS as a static library
|
||||
set(LIBLINEAR_SOURCES)
|
||||
set(BLAS_SOURCES)
|
||||
|
||||
# Check for main liblinear source files
|
||||
if(EXISTS "${liblinear_SOURCE_DIR}/linear.cpp")
|
||||
@@ -64,7 +65,7 @@ elseif(EXISTS "${liblinear_SOURCE_DIR}/newton.cpp")
|
||||
list(APPEND LIBLINEAR_SOURCES "${liblinear_SOURCE_DIR}/newton.cpp")
|
||||
endif()
|
||||
|
||||
# Check for BLAS files in blas directory - Fixed to ensure they're included
|
||||
# Check for BLAS files in blas directory
|
||||
if(EXISTS "${liblinear_SOURCE_DIR}/blas")
|
||||
# Explicitly add the required BLAS source files
|
||||
set(BLAS_FILES
|
||||
@@ -77,7 +78,7 @@ if(EXISTS "${liblinear_SOURCE_DIR}/blas")
|
||||
# Check which BLAS files actually exist and add them
|
||||
foreach(blas_file ${BLAS_FILES})
|
||||
if(EXISTS ${blas_file})
|
||||
list(APPEND LIBLINEAR_SOURCES ${blas_file})
|
||||
list(APPEND BLAS_SOURCES ${blas_file})
|
||||
message(STATUS "Adding BLAS file: ${blas_file}")
|
||||
endif()
|
||||
endforeach()
|
||||
@@ -85,20 +86,40 @@ else()
|
||||
message(WARNING "BLAS directory not found in liblinear source")
|
||||
endif()
|
||||
|
||||
# Create liblinear object library if we have source files
|
||||
# Create liblinear with BLAS
|
||||
if(LIBLINEAR_SOURCES)
|
||||
# First create BLAS library if we have BLAS sources
|
||||
if(BLAS_SOURCES)
|
||||
add_library(blas_functions STATIC ${BLAS_SOURCES})
|
||||
target_include_directories(blas_functions
|
||||
PUBLIC ${liblinear_SOURCE_DIR}/blas
|
||||
)
|
||||
|
||||
# Set C language for BLAS
|
||||
set_target_properties(blas_functions PROPERTIES
|
||||
LINKER_LANGUAGE C
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
|
||||
# Ensure symbols are exported
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(blas_functions PRIVATE -fvisibility=default)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Create liblinear object library
|
||||
add_library(liblinear_objects OBJECT ${LIBLINEAR_SOURCES})
|
||||
|
||||
# Set properties for the object library
|
||||
target_include_directories(liblinear_objects
|
||||
PRIVATE
|
||||
PUBLIC
|
||||
${liblinear_SOURCE_DIR}
|
||||
)
|
||||
|
||||
# Add blas directory if it exists
|
||||
if(EXISTS "${liblinear_SOURCE_DIR}/blas")
|
||||
target_include_directories(liblinear_objects
|
||||
PRIVATE ${liblinear_SOURCE_DIR}/blas
|
||||
PUBLIC ${liblinear_SOURCE_DIR}/blas
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -116,7 +137,15 @@ if(LIBLINEAR_SOURCES)
|
||||
set(LIBLINEAR_BLAS_INCLUDE_DIR ${liblinear_SOURCE_DIR}/blas PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
# Export BLAS library target to parent scope if it exists
|
||||
if(TARGET blas_functions)
|
||||
set(LIBLINEAR_BLAS_TARGET blas_functions PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
message(STATUS "liblinear built with sources: ${LIBLINEAR_SOURCES}")
|
||||
if(BLAS_SOURCES)
|
||||
message(STATUS "BLAS functions built as separate static library")
|
||||
endif()
|
||||
else()
|
||||
# Create minimal liblinear implementation as object library
|
||||
message(WARNING "liblinear source files not found, creating minimal implementation")
|
||||
@@ -165,7 +194,7 @@ else()
|
||||
)
|
||||
|
||||
add_library(liblinear_objects OBJECT "${MINIMAL_LIBLINEAR_DIR}/linear.cpp")
|
||||
target_include_directories(liblinear_objects PRIVATE ${MINIMAL_LIBLINEAR_DIR})
|
||||
target_include_directories(liblinear_objects PUBLIC ${MINIMAL_LIBLINEAR_DIR})
|
||||
target_compile_features(liblinear_objects PRIVATE cxx_std_17)
|
||||
|
||||
set(LIBLINEAR_INCLUDE_DIR ${MINIMAL_LIBLINEAR_DIR} PARENT_SCOPE)
|
||||
@@ -175,4 +204,7 @@ endif()
|
||||
message(STATUS "External libraries configured:")
|
||||
message(STATUS " - libsvm: ${libsvm_SOURCE_DIR}")
|
||||
message(STATUS " - liblinear: ${liblinear_SOURCE_DIR}")
|
||||
message(STATUS " - Using OBJECT libraries to avoid export issues")
|
||||
if(TARGET blas_functions)
|
||||
message(STATUS " - BLAS functions built as separate static library")
|
||||
endif()
|
||||
message(STATUS " - Using combination of OBJECT and STATIC libraries")
|
||||
|
Reference in New Issue
Block a user