From 104048b27edf281ea0505652551159eef29b96ca Mon Sep 17 00:00:00 2001 From: Ylannl Date: Tue, 22 Oct 2024 15:42:02 +0200 Subject: [PATCH] Add option to provide thirdparty dependencies externally --- CMakeLists.txt | 71 +++++++++++++++---- src/Feature.h | 2 +- src/Primitive.h | 2 +- src/Surface.h | 2 +- src/input.h | 4 +- src/main.cpp | 2 +- src/val3dity.h | 2 +- .../{nlohmann-json => nlohmann}/json.hpp | 0 vcpkg.json | 13 +++- 9 files changed, 75 insertions(+), 23 deletions(-) rename thirdparty/{nlohmann-json => nlohmann}/json.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a148df2a..cc44b5ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,8 @@ endif(COMMAND cmake_policy) cmake_minimum_required (VERSION 3.16) project( val3dity ) +option(VAL3DITY_LIBRARY "Build val3dity as a library instead of an executable." OFF) +option(VAL3DITY_USE_INTERNAL_DEPS "Use the thirdparty dir that ship with val3dity (for pugixml, nlohmann-json, spdlog and tclap). Turn off in case you want to provide these dependencies yourself." ON) add_definitions(-std=c++17) @@ -57,27 +59,66 @@ else() message( SEND_ERROR "val3dity requires the GEOS library" ) endif() -#include_directories( ${GEOS_INCLUDE_DIR} ) -include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty ) +if ( VAL3DITY_USE_INTERNAL_DEPS ) + message(STATUS "Using internal dependencies") -FILE(GLOB_RECURSE THIRDPARTY thirdparty/*.cpp) -add_library(val3dity_thirdparty STATIC ${THIRDPARTY}) + FILE(GLOB_RECURSE THIRDPARTY ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/*.cpp) + add_library(val3dity_thirdparty STATIC ${THIRDPARTY}) + target_include_directories(val3dity_thirdparty PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/pugixml) + set_property(TARGET val3dity_thirdparty PROPERTY POSITION_INDEPENDENT_CODE ON) +else() + message(STATUS "Using external dependencies") + # nlohmann + find_package(nlohmann_json CONFIG REQUIRED) + # spdlog + find_package(spdlog CONFIG REQUIRED) + # pugixml + find_package(pugixml CONFIG REQUIRED) + + # Find TCLAP's include path using find_path (tclap provides no cmake target) + find_path(TCLAP_INCLUDE_DIR "tclap/CmdLine.h") + + if (TCLAP_INCLUDE_DIR) + message(STATUS "Found TCLAP: ${TCLAP_INCLUDE_DIR}") + else() + message(FATAL_ERROR "TCLAP not found. Make sure it is installed via eg. vcpkg.") + endif() +endif() +# Create an object file for the stuff that is shared between library and executable FILE(GLOB SRC_FILES src/*.cpp) +list(REMOVE_ITEM SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) +list(REMOVE_ITEM SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/val3dity.cpp) + +add_library(val3dity_core OBJECT ${SRC_FILES}) + +target_link_libraries(val3dity_core + PUBLIC + CGAL::CGAL + PRIVATE + CGAL::Eigen3_support + GEOS::geos_c +) +if ( VAL3DITY_USE_INTERNAL_DEPS ) + target_link_libraries(val3dity_core PUBLIC val3dity_thirdparty) +else() + target_link_libraries(val3dity_core PUBLIC nlohmann_json::nlohmann_json spdlog::spdlog PRIVATE pugixml::static) +endif() if ( VAL3DITY_LIBRARY ) message(STATUS "Building val3dity library") - list(REMOVE_ITEM SRC_FILES src/main.cpp) - add_library(val3dity STATIC ${SRC_FILES}) - target_include_directories(val3dity PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty) - set_property(TARGET val3dity_thirdparty PROPERTY POSITION_INDEPENDENT_CODE ON) + + add_library(val3dity STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src/val3dity.cpp) + target_include_directories(val3dity PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) + target_link_libraries(val3dity PUBLIC val3dity_core) set_property(TARGET val3dity PROPERTY POSITION_INDEPENDENT_CODE ON) else() message(STATUS "Building val3dity executable") - list(REMOVE_ITEM SRC_FILES src/val3dity.cpp) - add_executable(val3dity ${SRC_FILES}) -endif() - -target_link_libraries(val3dity CGAL::CGAL CGAL::Eigen3_support GEOS::geos_c val3dity_thirdparty Boost::filesystem) - -install(TARGETS val3dity DESTINATION bin) + add_executable(val3dity ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) + target_link_libraries(val3dity PRIVATE val3dity_core Boost::filesystem) + install(TARGETS val3dity DESTINATION bin) + + if ( NOT VAL3DITY_USE_INTERNAL_DEPS ) + target_include_directories(val3dity PRIVATE ${TCLAP_INCLUDE_DIR}) + endif() +endif() \ No newline at end of file diff --git a/src/Feature.h b/src/Feature.h index 695ead00..b5c5f8df 100644 --- a/src/Feature.h +++ b/src/Feature.h @@ -31,7 +31,7 @@ #include "Primitive.h" #include "definitions.h" -#include "nlohmann-json/json.hpp" +#include "nlohmann/json.hpp" #include #include #include diff --git a/src/Primitive.h b/src/Primitive.h index 6ebf1cc3..3958d13c 100644 --- a/src/Primitive.h +++ b/src/Primitive.h @@ -30,7 +30,7 @@ #define Primitive_h #include "definitions.h" -#include "nlohmann-json/json.hpp" +#include "nlohmann/json.hpp" #include #include #include diff --git a/src/Surface.h b/src/Surface.h index 13a15b0c..a4c3940f 100644 --- a/src/Surface.h +++ b/src/Surface.h @@ -30,7 +30,7 @@ #define Surface_h #include "definitions.h" -#include "nlohmann-json/json.hpp" +#include "nlohmann/json.hpp" #include #include #include diff --git a/src/input.h b/src/input.h index 04f956f7..a0470722 100644 --- a/src/input.h +++ b/src/input.h @@ -32,8 +32,8 @@ #include "definitions.h" #include #include -#include "pugixml/pugixml.hpp" -#include "nlohmann-json/json.hpp" +#include "pugixml.hpp" +#include "nlohmann/json.hpp" using json = nlohmann::json; diff --git a/src/main.cpp b/src/main.cpp index ea7fcef9..8f188dcf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,7 @@ #include #include -#include "nlohmann-json/json.hpp" +#include "nlohmann/json.hpp" #include #include #include "spdlog/spdlog.h" diff --git a/src/val3dity.h b/src/val3dity.h index 3e22d563..3f69f7af 100644 --- a/src/val3dity.h +++ b/src/val3dity.h @@ -29,7 +29,7 @@ #include "definitions.h" #include -#include "nlohmann-json/json.hpp" +#include using json = nlohmann::json; diff --git a/thirdparty/nlohmann-json/json.hpp b/thirdparty/nlohmann/json.hpp similarity index 100% rename from thirdparty/nlohmann-json/json.hpp rename to thirdparty/nlohmann/json.hpp diff --git a/vcpkg.json b/vcpkg.json index e7a7a50e..7175bc21 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -11,6 +11,17 @@ "cgal", "geos", "eigen3" - ] + ], + "features" : { + "do_not_use_internal_libs": { + "description": "Do not use dependencies that are shipped with val3dity.", + "dependencies": [ + "spdlog", + "pugixml", + "nlohmann-json", + "tclap" + ] + } + } } \ No newline at end of file