diff --git a/CMakeLists.txt b/CMakeLists.txt index bcfd78a..531bf30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,11 @@ project(polyhedralGravity) set(CMAKE_CXX_STANDARD 17) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -# Best Combo: HOST CPP, DEVICE OMP +include(CMakeDependentOption) + +##################################### +# PARALLELIZATION OPTIONS AND LOGGING +##################################### # Parallelization on the HOST set(PARALLELIZATION_HOST "CPP" CACHE STRING "Host parallelization chosen by the user (CPP= Serial, OMP = OpenMP, TBB = Intel Threading Building Blocks") @@ -15,52 +19,54 @@ set(PARALLELIZATION_DEVICE "CPP" CACHE STRING "Device parallelization chosen by (CPP= Serial, OMP = OpenMP, TBB = Intel Threading Building Blocks") set_property(CACHE PARALLELIZATION_DEVICE PROPERTY STRINGS CPP, OMP, TBB) +# Enforce to use an already installed tbb library instead of compiling from source +option(USE_LOCAL_TBB "Uses the local tbb installation rather than on using the automatically fetched version from +GitHub via CMake (Default: OFF)" OFF) + # Set the Logging Level set(LOGGING_LEVEL "2" CACHE STRING "Set the Logging level, default (INFO=2), available options: TRACE=0, DEBUG=1, INFO=2, WARN=3, ERROR=4, CRITICAL=5, OFF=6") set_property(CACHE LOGGING_LEVEL PROPERTY STRINGS 0, 1, 2, 3, 4, 5, 6) +add_compile_definitions(SPDLOG_ACTIVE_LEVEL=${LOGGING_LEVEL}) -# Enforce to use an already installed tbb library instead of compiling from source -option(USE_LOCAL_TBB "Uses the local tbb installation rather than on using the automatically fetched version from -GitHub via CMake (Default: OFF)" OFF) +################################### +# What actually to build? - Options +################################### +# Build docs option(BUILD_POLYHEDRAL_GRAVITY_DOCS "Builds the documentation (Default: OFF)" OFF) +message(STATUS "BUILD_POLYHEDRAL_GRAVITY_DOCS = ${BUILD_POLYHEDRAL_GRAVITY_DOCS}") +# Build C++ executable +option(BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE "Builds the C++ executable (Default: ON)" ON) +message(STATUS "BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE = ${BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE}") +# Build library (default ON), if the executable or tests are built this forced to ON +cmake_dependent_option(BUILD_POLYHEDRAL_GRAVITY_LIBRARY "Builds the library (Default: ON)" ON + "NOT BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE AND NOT BUILD_POLYHEDRAL_GRAVITY_TESTS" ON) +message(STATUS "BUILD_POLYHEDRAL_GRAVITY_LIBRARY = ${BUILD_POLYHEDRAL_GRAVITY_LIBRARY}") +# Option to build the python interface +option(BUILD_POLYHEDRAL_PYTHON_INTERFACE "Set this to on if the python interface should be built (Default: ON)" ON) +message(STATUS "BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE = ${BUILD_POLYHEDRAL_PYTHON_INTERFACE}") +# Option to build tests or not +option(BUILD_POLYHEDRAL_GRAVITY_TESTS "Set to on if the tests should be built (Default: ON)" ON) +message(STATUS "BUILD_POLYHEDRAL_GRAVITY_TESTS = ${BUILD_POLYHEDRAL_GRAVITY_TESTS}") -add_compile_definitions(SPDLOG_ACTIVE_LEVEL=${LOGGING_LEVEL}) +####################################################### +# Including dependencies needed across multiple targets +####################################################### # Appends the the module path to contain additional CMake modules for this project # and include everything necessary list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +# Include dependecies include(thrust) include(spdlog) include(tetgen) -include(yaml) include(xsimd) -# Main file, containing the gravity model's driver -set(mainFile ${PROJECT_SOURCE_DIR}/src/main.cpp) - -# Including the actual Polyhedral source files -file(GLOB_RECURSE SRC - "${PROJECT_SOURCE_DIR}/src/polyhedralGravity/*.h" - "${PROJECT_SOURCE_DIR}/src/polyhedralGravity/*.cpp") - -add_library(${PROJECT_NAME}_lib OBJECT ${SRC}) - -# Adds the include Path PROJECT_SOURCE_DIR/src to the target polyhedralGravity -target_include_directories(${PROJECT_NAME}_lib PUBLIC - "${PROJECT_SOURCE_DIR}/src" - ) - -# Link libaries -target_link_libraries(${PROJECT_NAME}_lib - spdlog::spdlog - tetgen - yaml-cpp - xsimd - ) - +############################### +# Thrust Parallelization Set-Up +############################### # Get a version of tbb from the github repository, simplifies compilation for the user since tbb does not need to be # preinstalled but rather gets automatically set up via CMake # Nevertheless, there is still the option to enforce to use a local installation if one exists @@ -73,39 +79,79 @@ endif () thrust_create_target(Thrust HOST ${PARALLELIZATION_HOST} DEVICE ${PARALLELIZATION_DEVICE}) message(STATUS "Set Parallelization: HOST ${PARALLELIZATION_HOST} DEVICE ${PARALLELIZATION_DEVICE}") -# Adds the include Path PROJECT_SOURCE_DIR/src to the target polyhedralGravity -target_include_directories(${PROJECT_NAME}_lib PUBLIC - "${PROJECT_SOURCE_DIR}/src" - ) - -# Link libraries needed in all targets -target_link_libraries(${PROJECT_NAME}_lib - spdlog::spdlog - yaml-cpp - tetgen - xsimd - Thrust - ) - # This definitions will set the main eval(..) routine to be executed on the DEVICE if the users has given # an option parallelize on the Device if(NOT PARALLELIZATION_DEVICE STREQUAL "CPP") add_compile_definitions(DEVICE) endif() -# Building the standalone Executable -add_executable(${PROJECT_NAME} ${mainFile}) +################################ +# Building the Polyhedral Libray +################################ +if (BUILD_POLYHEDRAL_GRAVITY_LIBRARY) + # YAML is only required for the library target, but not for e.g. the Python interface + include(yaml) + + # Including the actual Polyhedral source files + file(GLOB_RECURSE SRC + "${PROJECT_SOURCE_DIR}/src/polyhedralGravity/*.h" + "${PROJECT_SOURCE_DIR}/src/polyhedralGravity/*.cpp") + + add_library(${PROJECT_NAME}_lib OBJECT ${SRC}) + + # Adds the include Path PROJECT_SOURCE_DIR/src to the target polyhedralGravity + target_include_directories(${PROJECT_NAME}_lib PUBLIC + "${PROJECT_SOURCE_DIR}/src" + ) + + # Link libaries + target_link_libraries(${PROJECT_NAME}_lib + spdlog::spdlog + tetgen + yaml-cpp + xsimd + ) + + # Adds the include Path PROJECT_SOURCE_DIR/src to the target polyhedralGravity + target_include_directories(${PROJECT_NAME}_lib PUBLIC + "${PROJECT_SOURCE_DIR}/src" + ) + + # Link libraries needed in all targets + target_link_libraries(${PROJECT_NAME}_lib + spdlog::spdlog + yaml-cpp + tetgen + xsimd + Thrust + ) + +endif() + +##################################### +# Building the Polyhedral Executable +##################################### +if (BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE) + # Main file, containing the gravity model's driver + set(mainFile ${PROJECT_SOURCE_DIR}/src/main.cpp) -# Link executable with library -target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_NAME}_lib) + # Building the standalone Executable + add_executable(${PROJECT_NAME} ${mainFile}) + + # Link executable with library + target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_NAME}_lib) +endif() +############################## +# Building the Polyhedral Docs +############################## if (BUILD_POLYHEDRAL_GRAVITY_DOCS) add_subdirectory(${PROJECT_SOURCE_DIR}/docs) endif () -# Option to build tests or not -option(BUILD_POLYHEDRAL_GRAVITY_TESTS "Set to on if the tests should be built (Default: ON)" ON) -# Only build the tests if they are enabled +############################### +# Building the Polyhedral Tests +############################### if (BUILD_POLYHEDRAL_GRAVITY_TESTS) message(STATUS "Building the Polyhedral Gravity Tests") # Enables CTest, must be in the top-level CMakeList.txt, otherwise it won't work @@ -115,10 +161,10 @@ if (BUILD_POLYHEDRAL_GRAVITY_TESTS) add_subdirectory(${PROJECT_SOURCE_DIR}/test) endif () -# Option to build the python interface -option(BUILD_POLYHEDRAL_PYTHON_INTERFACE "Set this to on if the python interface should be built (Default: ON)" ON) -# Build the polyhedral gravity python interface -if(BUILD_POLYHEDRAL_PYTHON_INTERFACE) +########################################## +# Building the Polyhedral Python Interface +########################################## +if(BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE) message(STATUS "Building the Polyhedral Gravity Python Interface") add_subdirectory(${PROJECT_SOURCE_DIR}/python-binding) endif() \ No newline at end of file diff --git a/python-binding/CMakeLists.txt b/python-binding/CMakeLists.txt index 5abd312..0ed7cf9 100644 --- a/python-binding/CMakeLists.txt +++ b/python-binding/CMakeLists.txt @@ -4,9 +4,24 @@ include(pybind11) # Stores the file of the python interface in a variable set(pythonInterface ${CMAKE_CURRENT_SOURCE_DIR}/python-interface.cpp) -pybind11_add_module(polyhedral_gravity ${pythonInterface}) +file(GLOB_RECURSE PYTHON_INTERFACE_SRC + "${PROJECT_SOURCE_DIR}/src/polyhedralGravity/*.h" + "${PROJECT_SOURCE_DIR}/src/polyhedralGravity/*.cpp") -target_link_libraries(polyhedral_gravity PUBLIC ${PROJECT_NAME}_lib) +list(FILTER PYTHON_INTERFACE_SRC EXCLUDE REGEX ".*YAML.*") + +pybind11_add_module(polyhedral_gravity ${pythonInterface} ${PYTHON_INTERFACE_SRC}) + +target_include_directories(polyhedral_gravity PUBLIC + "${PROJECT_SOURCE_DIR}/src" + ) + +target_link_libraries(polyhedral_gravity PUBLIC + spdlog::spdlog + tetgen + xsimd + Thrust + ) # Checks if MinGW is used, in this case, the .dll of the the standard library need to be linked statically to the # Python interface since otherwise they won't be found diff --git a/setup.py b/setup.py index c157d88..795f469 100644 --- a/setup.py +++ b/setup.py @@ -28,8 +28,12 @@ "BUILD_POLYHEDRAL_GRAVITY_DOCS": "OFF", # Not required for the python interface (--> OFF) "BUILD_POLYHEDRAL_GRAVITY_TESTS": "OFF", + # Not required for the python interface (--> OFF) + "BUILD_POLYHEDRAL_GRAVITY_LIBRARY": "OFF", + # Not required for the python interface (--> OFF) + "BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE": "OFF", # Should be of course ON! - "BUILD_POLYHEDRAL_PYTHON_INTERFACE": "ON", + "BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE": "ON", # Build shared libs by default "BUILD_SHARED_LIBS": "ON" } @@ -139,7 +143,7 @@ def build_extension(self, ext): # -------------------------------------------------------------------------------- setup( name="polyhedral_gravity", - version="1.1.5", + version="1.1.6", author="Jonas Schuhmacher", author_email="jonas.schuhmacher@tum.de", description="Package to compute full gravity tensor of a given constant density polyhedron for arbitrary points",