63 lines
2.0 KiB
CMake
63 lines
2.0 KiB
CMake
cmake_minimum_required(VERSION 3.30.0)
|
|
project(SVMClassifier VERSION 0.1.0 LANGUAGES C CXX)
|
|
|
|
project(SVMClassifier
|
|
VERSION 1.0.0
|
|
DESCRIPTION "SVM Classifer using libsvm and liblinear"
|
|
HOMEPAGE_URL "https://gitea.rmontanana.es/rmontanana/SVMClassifier"
|
|
LANGUAGES CXX
|
|
)
|
|
|
|
# Global CMake variables
|
|
# ----------------------
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast")
|
|
set(CMAKE_CXX_FLAGS_DEBUG " ${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0 -g")
|
|
|
|
# Testing is disabled by default
|
|
option(BUILD_TESTING "Build tests" OFF)
|
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -O0")
|
|
else()
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -O2")
|
|
endif()
|
|
|
|
find_package(Torch CONFIG REQUIRED)
|
|
find_package(nlohmann_json CONFIG REQUIRED)
|
|
|
|
# if testing is enabled then load catch2
|
|
if (BUILD_TESTING)
|
|
enable_testing()
|
|
include(CTest)
|
|
find_package(Catch2 REQUIRED)
|
|
target_link_libraries(SVMClassifier PRIVATE Catch2::Catch2)
|
|
add_executable(SVMClassifierTests tests.cpp)
|
|
target_link_libraries(SVMClassifierTests PRIVATE Catch2::Catch2)
|
|
add_test(NAME SVMClassifierTests COMMAND SVMClassifierTests)
|
|
endif()
|
|
|
|
add_executable(SVMClassifier
|
|
src/SVMDataConverter.cpp
|
|
src/SVMClassifier.cpp
|
|
libsvm-3.36/svm.cpp
|
|
main.cpp)
|
|
|
|
target_include_directories(SVMClassifier PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
${TORCH_INCLUDE_DIRS}
|
|
liblinear-2.49/
|
|
libsvm-3.36/
|
|
)
|
|
find_library(LIBLINEAR_LIBRARY NAMES liblinear.so.6 PATHS /home/rmontanana/Code/SVMClassifier/liblinear-2.49)
|
|
link_directories(/home/rmontanana/Code/SVMClassifier/liblinear-2.49)
|
|
target_link_libraries(SVMClassifier PRIVATE
|
|
${TORCH_LIBRARIES}
|
|
${LIBLINEAR_LIBRARY}
|
|
nlohmann_json::nlohmann_json
|
|
) |