Skip to content

Commit

Permalink
Apply new cmake-format target.
Browse files Browse the repository at this point in the history
  • Loading branch information
breyerml committed Nov 26, 2024
1 parent 5f35a69 commit f51494a
Show file tree
Hide file tree
Showing 48 changed files with 864 additions and 782 deletions.
495 changes: 260 additions & 235 deletions CMakeLists.txt

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
## Authors: Alexander Van Craen, Marcel Breyer
## Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
## License: This file is part of the PLSSVM project which is released under the MIT license.
## See the LICENSE.md file in the project root for full license information.
# Authors: Alexander Van Craen, Marcel Breyer
# Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
# License: This file is part of the PLSSVM project which is released under the MIT license.
# See the LICENSE.md file in the project root for full license information.
########################################################################################################################

include(CMakeDependentOption)

list(APPEND CMAKE_MESSAGE_INDENT "Bindings: ")

# enable Python langauge bindings
cmake_dependent_option(PLSSVM_ENABLE_PYTHON_BINDINGS "Build langauge bindings for Python." ON "PLSSVM_ENABLE_LANGUAGE_BINDINGS" OFF)
cmake_dependent_option(
PLSSVM_ENABLE_PYTHON_BINDINGS
"Build langauge bindings for Python."
ON
"PLSSVM_ENABLE_LANGUAGE_BINDINGS"
OFF
)
if (PLSSVM_ENABLE_PYTHON_BINDINGS)
add_subdirectory(Python)
endif ()

# explicitly update install targets in parent scope
set(PLSSVM_TARGETS_TO_INSTALL "${PLSSVM_TARGETS_TO_INSTALL}" PARENT_SCOPE)

list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)
54 changes: 29 additions & 25 deletions bindings/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Authors: Alexander Van Craen, Marcel Breyer
## Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
## License: This file is part of the PLSSVM project which is released under the MIT license.
## See the LICENSE.md file in the project root for full license information.
# Authors: Alexander Van Craen, Marcel Breyer
# Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
# License: This file is part of the PLSSVM project which is released under the MIT license.
# See the LICENSE.md file in the project root for full license information.
########################################################################################################################

include(${PROJECT_SOURCE_DIR}/cmake/utility_macros.cmake)
Expand All @@ -10,33 +10,29 @@ message(STATUS "Building Python language bindings for PLSSVM.")

find_package(Python COMPONENTS Interpreter Development)

## try finding pybind11
# try finding pybind11
set(PLSSVM_pybind11_VERSION v2.13.3)
find_package(pybind11 2.13.3 QUIET)
if (pybind11_FOUND)
message(STATUS "Found package pybind11.")
else ()
message(STATUS "Couldn't find package pybind11. Building version ${PLSSVM_pybind11_VERSION} from source.")
# fetch pybind11 library for creating Python bindings
FetchContent_Declare(pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG ${PLSSVM_pybind11_VERSION}
GIT_SHALLOW TRUE
QUIET
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG ${PLSSVM_pybind11_VERSION}
GIT_SHALLOW TRUE
QUIET
)
FetchContent_MakeAvailable(pybind11)
target_include_directories(${PLSSVM_BASE_LIBRARY_NAME} PUBLIC
$<BUILD_INTERFACE:${pybind11_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories(${PLSSVM_BASE_LIBRARY_NAME} PUBLIC $<BUILD_INTERFACE:${pybind11_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
endif ()

# set source files that are always used
set(PLSSVM_PYTHON_BINDINGS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/exceptions/exceptions.cpp

${CMAKE_CURRENT_LIST_DIR}/version/version.cpp

${CMAKE_CURRENT_LIST_DIR}/backend_types.cpp
${CMAKE_CURRENT_LIST_DIR}/classification_types.cpp
${CMAKE_CURRENT_LIST_DIR}/csvm.cpp
Expand All @@ -51,9 +47,7 @@ set(PLSSVM_PYTHON_BINDINGS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/solver_types.cpp
${CMAKE_CURRENT_LIST_DIR}/target_platforms.cpp
${CMAKE_CURRENT_LIST_DIR}/verbosity_levels.cpp

${CMAKE_CURRENT_LIST_DIR}/sklearn.cpp

${CMAKE_CURRENT_LIST_DIR}/main.cpp
)

Expand All @@ -69,12 +63,15 @@ if (TARGET ${PLSSVM_OPENMP_BACKEND_LIBRARY_NAME})
list(APPEND PLSSVM_PYTHON_BINDINGS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/backends/openmp_csvm.cpp)
endif ()
if (TARGET ${PLSSVM_STDPAR_BACKEND_LIBRARY_NAME})

# AdaptiveCpp stdpar only support on the CPU when using our Python bindings
if (PLSSVM_STDPAR_BACKEND STREQUAL "ACPP" AND (DEFINED PLSSVM_NVIDIA_TARGET_ARCHS OR DEFINED PLSSVM_AMD_TARGET_ARCHS OR DEFINED PLSSVM_INTEL_TARGET_ARCHS))
message(FATAL_ERROR "The stdpar implementation using AdaptiveCpp isn't currently supported in the Python bindings when targeting something different than the CPU!")
message(
FATAL_ERROR
"The stdpar implementation using AdaptiveCpp isn't currently supported in the Python bindings when targeting something different than the CPU!"
)
endif ()

list(APPEND PLSSVM_PYTHON_BINDINGS_SOURCES ${CMAKE_CURRENT_LIST_DIR}/backends/stdpar_csvm.cpp)
endif ()
if (TARGET ${PLSSVM_CUDA_BACKEND_LIBRARY_NAME})
Expand All @@ -101,16 +98,23 @@ set(PLSSVM_PYTHON_BINDINGS_LIBRARY_NAME plssvm)
pybind11_add_module(${PLSSVM_PYTHON_BINDINGS_LIBRARY_NAME} ${PLSSVM_PYTHON_BINDINGS_SOURCES})

# set default label type
set(PLSSVM_PYTHON_BINDINGS_POSSIBLE_LABEL_TYPE "bool;char;signed char;unsigned char;short;unsigned short;int;unsigned int;long;unsigned long;long long;unsigned long long;float;double;long double;std::string")
set(PLSSVM_PYTHON_BINDINGS_POSSIBLE_LABEL_TYPE
"bool;char;signed char;unsigned char;short;unsigned short;int;unsigned int;long;unsigned long;long long;unsigned long long;float;double;long double;std::string"
)
set(PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE "std::string" CACHE STRING "The preferred type of the labels for the Python bindings.")
set_property(CACHE PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE PROPERTY STRINGS ${PLSSVM_PYTHON_BINDINGS_POSSIBLE_LABEL_TYPE})
if (NOT "${PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE}" IN_LIST PLSSVM_PYTHON_BINDINGS_POSSIBLE_LABEL_TYPE)
message(FATAL_ERROR "The provided label_type \"${PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE}\" is not one of the allowed values: \"${PLSSVM_PYTHON_BINDINGS_POSSIBLE_LABEL_TYPE}\"")
message(
FATAL_ERROR
"The provided label_type \"${PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE}\" is not one of the allowed values: \"${PLSSVM_PYTHON_BINDINGS_POSSIBLE_LABEL_TYPE}\""
)
endif ()
message(STATUS "The preferred label_type for the Python bindings is \"${PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE}\".")

# add necessary compile definitions for the default real_type and label_type
target_compile_definitions(${PLSSVM_PYTHON_BINDINGS_LIBRARY_NAME} PRIVATE PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE=${PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE})
target_compile_definitions(
${PLSSVM_PYTHON_BINDINGS_LIBRARY_NAME} PRIVATE PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE=${PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE}
)
if (PLSSVM_PYTHON_BINDINGS_PREFERRED_LABEL_TYPE STREQUAL "std::string")
target_compile_definitions(${PLSSVM_PYTHON_BINDINGS_LIBRARY_NAME} PRIVATE PLSSVM_PYTHON_BINDINGS_LABEL_TYPE_IS_STRING)
endif ()
Expand All @@ -125,4 +129,4 @@ target_compile_options(${PLSSVM_BASE_LIBRARY_NAME} PUBLIC $<$<COMPILE_LANG_AND_I
target_compile_options(${PLSSVM_BASE_LIBRARY_NAME} PUBLIC -fPIC)

# append pybind11 bindings library to installed targets
append_local_and_parent(PLSSVM_TARGETS_TO_INSTALL ${PLSSVM_PYTHON_BINDINGS_LIBRARY_NAME})
append_local_and_parent(PLSSVM_TARGETS_TO_INSTALL ${PLSSVM_PYTHON_BINDINGS_LIBRARY_NAME})
57 changes: 26 additions & 31 deletions cmake/add_coverage_build_type.cmake
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
## Authors: Alexander Van Craen, Marcel Breyer
## Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
## License: This file is part of the PLSSVM project which is released under the MIT license.
## See the LICENSE.md file in the project root for full license information.
# Authors: Alexander Van Craen, Marcel Breyer
# Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
# License: This file is part of the PLSSVM project which is released under the MIT license.
# See the LICENSE.md file in the project root for full license information.
########################################################################################################################

## add new coverage build type
SET(CMAKE_CXX_FLAGS_COVERAGE
"${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C++ compiler during coverage builds."
FORCE)
SET(CMAKE_C_FLAGS_COVERAGE
"${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C compiler during coverage builds."
FORCE)
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov"
CACHE STRING "Flags used for linking binaries during coverage builds."
FORCE)
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov"
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
FORCE)
MARK_AS_ADVANCED(
CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE)
# add new coverage build type
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage" CACHE STRING "Flags used by the C++ compiler during coverage builds."
FORCE
)
set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage" CACHE STRING "Flags used by the C compiler during coverage builds." FORCE)
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov"
CACHE STRING "Flags used for linking binaries during coverage builds." FORCE
)
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov"
CACHE STRING "Flags used by the shared libraries linker during coverage builds." FORCE
)
mark_as_advanced(CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE CMAKE_EXE_LINKER_FLAGS_COVERAGE CMAKE_SHARED_LINKER_FLAGS_COVERAGE)

# update the documentation string of CMAKE_BUILD_TYPE for GUIs
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage."
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "RelWithDebInfo" "MinSizeRel" "Coverage")
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage." FORCE)
set_property(
CACHE CMAKE_BUILD_TYPE
PROPERTY STRINGS
"Debug"
"Release"
"RelWithDebInfo"
"MinSizeRel"
"Coverage"
)
12 changes: 6 additions & 6 deletions cmake/assemble_summary_string.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Authors: Alexander Van Craen, Marcel Breyer
## Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
## License: This file is part of the PLSSVM project which is released under the MIT license.
## See the LICENSE.md file in the project root for full license information.
# Authors: Alexander Van Craen, Marcel Breyer
# Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
# License: This file is part of the PLSSVM project which is released under the MIT license.
# See the LICENSE.md file in the project root for full license information.
########################################################################################################################

function(assemble_summary_string out_var)
function (assemble_summary_string out_var)
set(PLSSVM_SUMMARY_STRING_ASSEMBLE "")
if (DEFINED PLSSVM_CPU_TARGET_ARCHS)
# add cpu platform
Expand All @@ -29,4 +29,4 @@ function(assemble_summary_string out_var)
# remove last comma
string(REGEX REPLACE ",$" "" PLSSVM_SUMMARY_STRING_ASSEMBLE "${PLSSVM_SUMMARY_STRING_ASSEMBLE}")
set(${out_var} "${PLSSVM_SUMMARY_STRING_ASSEMBLE}" PARENT_SCOPE)
endfunction()
endfunction ()
26 changes: 11 additions & 15 deletions cmake/check_python_libs.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
## Authors: Alexander Van Craen, Marcel Breyer
## Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
## License: This file is part of the PLSSVM project which is released under the MIT license.
## See the LICENSE.md file in the project root for full license information.
# Authors: Alexander Van Craen, Marcel Breyer
# Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
# License: This file is part of the PLSSVM project which is released under the MIT license.
# See the LICENSE.md file in the project root for full license information.
########################################################################################################################

function(check_python_libs required_libraries error_string)
function (check_python_libs required_libraries error_string)
foreach (PLSSVM_PYTHON_LIB ${required_libraries})
# search for Python package
execute_process(
COMMAND ${Python3_EXECUTABLE} -c "import ${PLSSVM_PYTHON_LIB}"
RESULT_VARIABLE PLSSVM_PYTHON_LIB_EXIT_CODE
OUTPUT_QUIET)

execute_process(COMMAND ${Python3_EXECUTABLE} -c "import ${PLSSVM_PYTHON_LIB}" RESULT_VARIABLE PLSSVM_PYTHON_LIB_EXIT_CODE OUTPUT_QUIET)

# emit error if package couldn't be found
if (NOT ${PLSSVM_PYTHON_LIB_EXIT_CODE} EQUAL 0)
message(FATAL_ERROR
"The '${PLSSVM_PYTHON_LIB}' Python3 package is not installed. "
"Please install it using the following command: '${Python3_EXECUTABLE} -m pip install ${PLSSVM_PYTHON_LIB}'\n "
"${error_string}"
message(FATAL_ERROR "The '${PLSSVM_PYTHON_LIB}' Python3 package is not installed. "
"Please install it using the following command: '${Python3_EXECUTABLE} -m pip install ${PLSSVM_PYTHON_LIB}'\n "
"${error_string}"
)
endif ()
endforeach ()
endfunction()
endfunction ()
10 changes: 5 additions & 5 deletions cmake/create_documentation_shortcut.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Authors: Alexander Van Craen, Marcel Breyer
## Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
## License: This file is part of the PLSSVM project which is released under the MIT license.
## See the LICENSE.md file in the project root for full license information.
# Authors: Alexander Van Craen, Marcel Breyer
# Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
# License: This file is part of the PLSSVM project which is released under the MIT license.
# See the LICENSE.md file in the project root for full license information.
########################################################################################################################

file(WRITE documentation.html "<meta http-equiv=\"REFRESH\" content=\"0;URL=html/index.html\">")
file(WRITE documentation.html "<meta http-equiv=\"REFRESH\" content=\"0;URL=html/index.html\">")
10 changes: 5 additions & 5 deletions cmake/delete_coverage_files.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Authors: Alexander Van Craen, Marcel Breyer
## Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
## License: This file is part of the PLSSVM project which is released under the MIT license.
## See the LICENSE.md file in the project root for full license information.
# Authors: Alexander Van Craen, Marcel Breyer
# Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
# License: This file is part of the PLSSVM project which is released under the MIT license.
# See the LICENSE.md file in the project root for full license information.
########################################################################################################################

file(GLOB_RECURSE PLSSVM_COVERAGE_GCDA_FILES ${CMAKE_BINARY_DIR}/*.gcda)
file(REMOVE ${PLSSVM_COVERAGE_GCDA_FILES})
file(GLOB_RECURSE PLSSVM_COVERAGE_GCNO_FILES ${CMAKE_BINARY_DIR}/*.gcno)
file(REMOVE ${PLSSVM_COVERAGE_GCNO_FILES})
file(REMOVE ${PLSSVM_COVERAGE_GCNO_FILES})
35 changes: 17 additions & 18 deletions cmake/discover_tests_with_death_test_filter.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
## Authors: Alexander Van Craen, Marcel Breyer
## Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
## License: This file is part of the PLSSVM project which is released under the MIT license.
## See the LICENSE.md file in the project root for full license information.
# Authors: Alexander Van Craen, Marcel Breyer
# Copyright (C): 2018-today The PLSSVM project - All Rights Reserved
# License: This file is part of the PLSSVM project which is released under the MIT license.
# See the LICENSE.md file in the project root for full license information.
########################################################################################################################

function(discover_tests_with_death_test_filter test_executable_name)
function (discover_tests_with_death_test_filter test_executable_name)
if (PLSSVM_ENABLE_DEATH_TESTS)
# assertions are enabled -> enable Google death tests
gtest_discover_tests(${test_executable_name} PROPERTIES
DISCOVERY_TIMEOUT 600
DISCOVERY_MODE PRE_TEST
WORKING_DIRECTORY $<TARGET_FILE_DIR:${test_executable_name}>)
gtest_discover_tests(
${test_executable_name} PROPERTIES DISCOVERY_TIMEOUT 600 DISCOVERY_MODE PRE_TEST WORKING_DIRECTORY $<TARGET_FILE_DIR:${test_executable_name}>
)
else ()
# assertions are disabled -> disable Google death tests
gtest_discover_tests(${test_executable_name} TEST_FILTER -*DeathTest* PROPERTIES
DISCOVERY_TIMEOUT 600
DISCOVERY_MODE PRE_TEST
WORKING_DIRECTORY $<TARGET_FILE_DIR:${test_executable_name}>)
gtest_discover_tests(
${test_executable_name} TEST_FILTER -*DeathTest* PROPERTIES DISCOVERY_TIMEOUT 600 DISCOVERY_MODE PRE_TEST
WORKING_DIRECTORY $<TARGET_FILE_DIR:${test_executable_name}>
)
endif ()
if (WIN32)
add_custom_command(
TARGET ${test_executable_name}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:${test_executable_name}> $<TARGET_FILE_DIR:${test_executable_name}>
COMMAND_EXPAND_LISTS
TARGET ${test_executable_name}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:${test_executable_name}> $<TARGET_FILE_DIR:${test_executable_name}>
COMMAND_EXPAND_LISTS
)
endif ()
endfunction()
endfunction ()
2 changes: 1 addition & 1 deletion cmake/git_watcher.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,4 @@ endfunction()
# And off we go...
Main()

# cmake-format: on
# cmake-format: on
Loading

0 comments on commit f51494a

Please sign in to comment.