Skip to content

Commit

Permalink
Merge pull request #188 from tudelft3d/fix/linking-spdlog
Browse files Browse the repository at this point in the history
Add option to provide thirdparty dependencies externally
  • Loading branch information
hugoledoux authored Oct 28, 2024
2 parents db77bc6 + e29a4a5 commit 94b5bf7
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 25 deletions.
71 changes: 56 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion demo_lib/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include "val3dity.h"
#include "nlohmann-json/json.hpp"
#include "nlohmann/json.hpp"

#include <iostream>
#include <fstream>
Expand Down
4 changes: 3 additions & 1 deletion demo_lib/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The API reads `const char*` for XML data ([IndoorGML](http://indoorgml.net/) inp

```cpp
#include "val3dity.h"
#include "nlohmann-json/json.hpp"
#include "nlohmann/json.hpp"

#include <fstream>

Expand Down Expand Up @@ -58,6 +58,8 @@ int main(int argc, char *argv[])
1. `make`
1. `./myprogram`
You can also use the option `VAL3DITY_USE_INTERNAL_DEPS=false` if you do not want to use the dependencies bundled with val3dity, see the `./thirdparty/` folder (nlohmann JSON, spdlog, pugixml, tclap).
## Parameters
Expand Down
2 changes: 1 addition & 1 deletion src/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include "Primitive.h"
#include "definitions.h"
#include "nlohmann-json/json.hpp"
#include "nlohmann/json.hpp"
#include <vector>
#include <set>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/Primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define Primitive_h

#include "definitions.h"
#include "nlohmann-json/json.hpp"
#include "nlohmann/json.hpp"
#include <map>
#include <vector>
#include <set>
Expand Down
2 changes: 1 addition & 1 deletion src/Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define Surface_h

#include "definitions.h"
#include "nlohmann-json/json.hpp"
#include "nlohmann/json.hpp"
#include <string>
#include <vector>
#include <set>
Expand Down
4 changes: 2 additions & 2 deletions src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#include "definitions.h"
#include <fstream>
#include <string>
#include "pugixml/pugixml.hpp"
#include "nlohmann-json/json.hpp"
#include "pugixml.hpp"
#include "nlohmann/json.hpp"

using json = nlohmann::json;

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#include <tclap/CmdLine.h>
#include <time.h>
#include "nlohmann-json/json.hpp"
#include "nlohmann/json.hpp"
#include <boost/filesystem.hpp>
#include <iostream>
#include "spdlog/spdlog.h"
Expand Down
2 changes: 1 addition & 1 deletion src/val3dity.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "definitions.h"
#include <iostream>

#include "nlohmann-json/json.hpp"
#include <nlohmann/json.hpp>

using json = nlohmann::json;

Expand Down
File renamed without changes.
13 changes: 12 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
"cgal",
"geos",
"eigen3"
]
],
"features" : {
"thirdparty": {
"description": "The thirdparty dependencies that are also shipped with val3dity itself.",
"dependencies": [
"spdlog",
"pugixml",
"nlohmann-json",
"tclap"
]
}
}

}

0 comments on commit 94b5bf7

Please sign in to comment.