Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow building against system libs instead of bundled dependencies #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ endif()
set(DIP_SHARED_LIBRARY ON CACHE BOOL "Build a shared library (off for static library)")
set(BUILD_SHARED_LIBS ${DIP_SHARED_LIBRARY})

# build bundled dependencies or use find_package?
set(DIP_BUILD_BUNDLED_DEPENDENCIES ON CACHE BOOL "Build the bundled dependencies or use find_package otherwise")

# Installation path
set(CMAKE_INSTALL_PREFIX "${CMAKE_BUILD_TYPE}" CACHE PATH "Installation directory")
set(DOCUMENTATION_OUTPUT share/doc/DIPlib)
Expand Down
4 changes: 2 additions & 2 deletions dependencies/libics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ endif(UNIX)
#endif()

# DIPlib-specific zlib
if(TARGET zlibstatic)
target_link_libraries(libics PRIVATE zlibstatic)
if(TARGET ZLIB::ZLIB)
target_link_libraries(libics PRIVATE ZLIB::ZLIB)
target_compile_definitions(libics PUBLIC -DICS_ZLIB)
endif()

Expand Down
6 changes: 3 additions & 3 deletions dependencies/libtiff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ set(MDI_SUPPORT TRUE)

# ZLIB
set(ZLIB_SUPPORT FALSE)
if(TARGET zlibstatic)
if(TARGET ZLIB::ZLIB)
set(ZLIB_SUPPORT TRUE)
endif()
set(ZIP_SUPPORT ${ZLIB_SUPPORT})
Expand Down Expand Up @@ -468,10 +468,10 @@ if(M_LIBRARY)
list(APPEND TIFF_LIBRARY_DEPS ${M_LIBRARY})
endif()
if(ZLIB_SUPPORT)
list(APPEND TIFF_LIBRARY_DEPS zlibstatic)
list(APPEND TIFF_LIBRARY_DEPS ZLIB::ZLIB)
endif()
if(JPEG_SUPPORT)
list(APPEND TIFF_LIBRARY_DEPS jpeg)
list(APPEND TIFF_LIBRARY_DEPS JPEG::JPEG)
endif()
if(JPEG12_LIBRARIES)
list(APPEND TIFF_LIBRARY_DEPS ${JPEG12_LIBRARIES})
Expand Down
6 changes: 5 additions & 1 deletion pydip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
set(PYBIND11_PYTHON_VERSION ${PYTHON_VERSION}) # Avoid a warning message
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/pybind11" "${PROJECT_BINARY_DIR}/pybind11" EXCLUDE_FROM_ALL)
if(DIP_BUILD_BUNDLED_DEPENDENCIES)
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/pybind11" "${PROJECT_BINARY_DIR}/pybind11" EXCLUDE_FROM_ALL)
else()
find_package(pybind11 REQUIRED)
endif()

# Find sources
file(GLOB DIP_PYTHON_SRC "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/src/*.h")
Expand Down
58 changes: 45 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ endif()
# that uses DIPlib, hence we define a variable here that removes all of DocTest from the DIPlib sources.
set(DIP_ENABLE_DOCTEST ON CACHE BOOL "Turn off to not include doctest.h in the library headers")
if(DIP_ENABLE_DOCTEST)
target_include_directories(DIP PRIVATE "${PROJECT_SOURCE_DIR}/dependencies/doctest")
if(DIP_BUILD_BUNDLED_DEPENDENCIES)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/dependencies/doctest")
add_library(doctest INTERFACE)
target_include_directories(doctest INTERFACE "${PROJECT_SOURCE_DIR}/dependencies")
add_library(doctest::doctest ALIAS doctest)
else()
find_package(doctest REQUIRED)
endif()
target_link_libraries(DIP PRIVATE doctest::doctest)
target_compile_definitions(DIP PRIVATE
DIP_CONFIG_ENABLE_DOCTEST
DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES
Expand All @@ -95,39 +103,64 @@ endif()
set(HAS_128_INT ${HAS_128_INT} PARENT_SCOPE)

# Eigen
target_include_directories(DIP PRIVATE "${PROJECT_SOURCE_DIR}/dependencies/eigen3")
if(DIP_BUILD_BUNDLED_DEPENDENCIES)
target_include_directories(DIP PRIVATE "${PROJECT_SOURCE_DIR}/dependencies/eigen3")
else()
find_package(Eigen3 REQUIRED)
target_include_directories(DIP PRIVATE ${EIGEN3_INCLUDE_DIR})
endif()
target_compile_definitions(DIP PRIVATE
EIGEN_MPL2_ONLY # This makes sure we only use parts of the Eigen library that use the MPL2 license or more permissive ones.
EIGEN_DONT_PARALLELIZE) # This to prevent Eigen algorithms trying to run in parallel -- we parallelize at a larger scale.

# zlib (for use in libics and libtiff)
set(DIP_ENABLE_ZLIB ON CACHE BOOL "Enable zlib compression in ICS and TIFF (deflate)")
if(DIP_ENABLE_ZLIB)
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/zlib" "${PROJECT_BINARY_DIR}/zlib" EXCLUDE_FROM_ALL)
if(DIP_BUILD_BUNDLED_DEPENDENCIES)
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/zlib" "${PROJECT_BINARY_DIR}/zlib" EXCLUDE_FROM_ALL)
add_library(ZLIB::ZLIB ALIAS zlibstatic)
else()
find_package(ZLIB REQUIRED)
endif()
endif()

# libjpeg (for use in libtiff)
set(DIP_ENABLE_JPEG ON CACHE BOOL "Enable JPEG file support and compression in TIFF")
if(DIP_ENABLE_JPEG)
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/libjpeg" "${PROJECT_BINARY_DIR}/libjpeg" EXCLUDE_FROM_ALL)
target_link_libraries(DIP PRIVATE jpeg)
if(DIP_BUILD_BUNDLED_DEPENDENCIES)
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/libjpeg" "${PROJECT_BINARY_DIR}/libjpeg" EXCLUDE_FROM_ALL)
add_library(JPEG::JPEG ALIAS jpeg)
else()
find_package(JPEG REQUIRED)
endif()
target_link_libraries(DIP PRIVATE JPEG::JPEG)
target_compile_definitions(DIP PRIVATE DIP_CONFIG_HAS_JPEG)
endif()

# libics
set(DIP_ENABLE_ICS ON CACHE BOOL "Enable ICS file support")
if(DIP_ENABLE_ICS)
set(LIBICS_INCLUDE_CPP Off) # TODO: we should start using the C++ interface
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/libics" "${PROJECT_BINARY_DIR}/libics" EXCLUDE_FROM_ALL)
target_link_libraries(DIP PRIVATE libics)
if(DIP_BUILD_BUNDLED_DEPENDENCIES)
set(LIBICS_INCLUDE_CPP Off) # TODO: we should start using the C++ interface
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/libics" "${PROJECT_BINARY_DIR}/libics" EXCLUDE_FROM_ALL)
add_library(ICS::ICS ALIAS libics)
else()
find_package(ICS REQUIRED)
endif()
target_link_libraries(DIP PRIVATE ICS::ICS)
target_compile_definitions(DIP PRIVATE DIP_CONFIG_HAS_ICS)
endif()

# libtiff
set(DIP_ENABLE_TIFF ON CACHE BOOL "Enable TIFF file support")
if(DIP_ENABLE_TIFF)
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/libtiff" "${PROJECT_BINARY_DIR}/libtiff" EXCLUDE_FROM_ALL)
target_link_libraries(DIP PRIVATE tiff)
if(DIP_BUILD_BUNDLED_DEPENDENCIES)
add_subdirectory("${PROJECT_SOURCE_DIR}/dependencies/libtiff" "${PROJECT_BINARY_DIR}/libtiff" EXCLUDE_FROM_ALL)
add_library(TIFF::TIFF ALIAS tiff)
else()
find_package(TIFF REQUIRED)
endif()
target_link_libraries(DIP PRIVATE TIFF::TIFF)
target_compile_definitions(DIP PRIVATE DIP_CONFIG_HAS_TIFF)
endif()

Expand Down Expand Up @@ -157,8 +190,7 @@ install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" DESTINATION include
# DIPlib unit tests
if(DIP_ENABLE_DOCTEST)
add_executable(unit_tests EXCLUDE_FROM_ALL "${CMAKE_CURRENT_LIST_DIR}/library/unit_tests.cpp")
target_include_directories(unit_tests PRIVATE "${PROJECT_SOURCE_DIR}/dependencies/doctest")
target_link_libraries(unit_tests PRIVATE DIP)
target_link_libraries(unit_tests PRIVATE DIP doctest::doctest)
target_compile_definitions(unit_tests PRIVATE
DIP_IMPLEMENT_UNIT_TESTS
DIP_CONFIG_ENABLE_DOCTEST
Expand All @@ -171,7 +203,7 @@ if(DIP_ENABLE_DOCTEST)
set_target_properties(unit_tests PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()
else()
include("${PROJECT_SOURCE_DIR}/dependencies/doctest/doctest_force_link_static_lib_in_target.cmake")
include(doctest_force_link_static_lib_in_target.cmake)
doctest_force_link_static_lib_in_target(unit_tests DIP) # This pulls in all object files from the static DIP library
endif()
add_custom_target(check COMMAND unit_tests)
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/findshift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ FloatArray FindShift(
} // namespace dip

#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/generation.h"

DOCTEST_TEST_CASE("[DIPlib] testing the FindShift function") {
Expand Down
2 changes: 1 addition & 1 deletion src/binary/binary_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void BinaryAreaOpening(


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/statistics.h"

DOCTEST_TEST_CASE("[DIPlib] testing the binary morphological filters") {
Expand Down
2 changes: 1 addition & 1 deletion src/binary/sup_inf_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ IntervalArray ConvexHullInterval2D() {
}

#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/testing.h"

DOCTEST_TEST_CASE("[DIPlib] testing private function RotateBy45Degrees") {
Expand Down
2 changes: 1 addition & 1 deletion src/color/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void ColorSpaceManager::SetWhitePoint( dip::XYZ whitePoint ) {


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/math.h"

DOCTEST_TEST_CASE("[DIPlib] testing the ColorSpaceManager class") {
Expand Down
2 changes: 1 addition & 1 deletion src/detection/hough.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ FloatCoordinateArray FindHoughCircles(
} // namespace dip

#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/linear.h"
#include "diplib/segmentation.h"
#include "diplib/math.h"
Expand Down
2 changes: 1 addition & 1 deletion src/distance/separable_dt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void SeparableDistanceTransform(


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/math.h"
#include "diplib/statistics.h"
#include "diplib/generation.h"
Expand Down
2 changes: 1 addition & 1 deletion src/file_io/ics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ void ImageWriteICS(
} // namespace dip

#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/testing.h"

DOCTEST_TEST_CASE( "[DIPlib] testing ICS file reading and writing" ) {
Expand Down
2 changes: 1 addition & 1 deletion src/file_io/tiff_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void ImageWriteTIFF(
} // namespace dip

#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/testing.h"

DOCTEST_TEST_CASE( "[DIPlib] testing TIFF file reading and writing" ) {
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ void Rotation(


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/generation.h"
#include "diplib/transform.h"
#include "diplib/testing.h"
Expand Down
2 changes: 1 addition & 1 deletion src/histogram/distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void Distribution::SetSampling(


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/random.h"

DOCTEST_TEST_CASE( "[DIPlib] testing dip::Distribution" ) {
Expand Down
2 changes: 1 addition & 1 deletion src/histogram/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ Histogram& Histogram::Smooth( FloatArray sigma ) {


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/random.h"

DOCTEST_TEST_CASE( "[DIPlib] testing dip::Histogram" ) {
Expand Down
2 changes: 1 addition & 1 deletion src/library/copy_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ void ExpandBuffer(


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include <numeric>

DOCTEST_TEST_CASE("[DIPlib] testing the CopyBuffer function") {
Expand Down
2 changes: 1 addition & 1 deletion src/library/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ LowestCommonAncestorSolver::LowestCommonAncestorSolver( Graph const& graph )
} // namespace dip

#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>

DOCTEST_TEST_CASE("[DIPlib] testing dip::Graph") {
dip::Image img( { 4, 5 }, 1, dip::DT_UINT8 );
Expand Down
2 changes: 1 addition & 1 deletion src/library/image_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ void Image::Fill( Image::Sample const& sample ) {


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>

DOCTEST_TEST_CASE( "[DIPlib] testing dip::Image::SwapBytesInSample" ) {
dip::Image img( { 5, 8 }, 3, dip::DT_SINT16 );
Expand Down
2 changes: 1 addition & 1 deletion src/library/image_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ CoordinatesComputer Image::IndexToCoordinatesComputer() const {


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/random.h"

DOCTEST_TEST_CASE( "[DIPlib] testing dip::Image::Forge" ) {
Expand Down
2 changes: 1 addition & 1 deletion src/library/image_indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void DefineROI(


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>

DOCTEST_TEST_CASE("[DIPlib] testing image indexing") {
// Note that this also tests parts of dip::Image::View and dip::Image::Pixel functionality, which is
Expand Down
2 changes: 1 addition & 1 deletion src/library/image_manip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ RangeArray Image::CropWindow( UnsignedArray const& sizes, String const& cropLoca


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>

DOCTEST_TEST_CASE("[DIPlib] testing dip::Image dimension manipulation functions") {
dip::Image src( { 5, 10, 15 }, 3 );
Expand Down
2 changes: 1 addition & 1 deletion src/library/image_views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Image::View::Iterator Image::View::end() const {


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/testing.h"

DOCTEST_TEST_CASE( "[DIPlib] testing dip::Image::Pixel and related classes" ) {
Expand Down
2 changes: 1 addition & 1 deletion src/library/iterators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/generic_iterators.h"

DOCTEST_TEST_CASE("[DIPlib] testing ImageIterator and GenericImageIterator") {
Expand Down
2 changes: 1 addition & 1 deletion src/library/neighborhood.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ NeighborList NeighborList::SelectForward( dip::uint procDim ) const {


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>

DOCTEST_TEST_CASE("[DIPlib] testing the NeighborList class") {
dip::dfloat x = 1.2;
Expand Down
2 changes: 1 addition & 1 deletion src/library/physical_dimensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ dip::String Units::StringRepresentation( bool unicode ) const {


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>

DOCTEST_TEST_CASE("[DIPlib] testing the dip::Units class") {
// Note: further tested at the same time as dip::PhysicalQuantity below
Expand Down
2 changes: 1 addition & 1 deletion src/library/pixel_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ void PixelTable::AddDistanceToOriginAsWeights() {


#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>

DOCTEST_TEST_CASE("[DIPlib] testing the PixelTable class") {
dip::PixelTable pt( "elliptic", dip::FloatArray{ 10.1, 12.7, 5.3 }, 1 );
Expand Down
2 changes: 1 addition & 1 deletion src/library/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

#ifdef DIP_CONFIG_ENABLE_DOCTEST
#include "doctest.h"
#include <doctest/doctest.h>
#include "diplib/library/types.h"

DOCTEST_TEST_CASE("[DIPlib] testing the dip::bin class") {
Expand Down
6 changes: 3 additions & 3 deletions src/library/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#ifdef DIP_CONFIG_DOCTEST_IN_SHARED_LIB

#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
#include "doctest.h"
#include <doctest/doctest.h>

#include "diplib.h"
#include "diplib/linear.h"
Expand All @@ -51,7 +51,7 @@ int main( int argc, const char* const* argv ) {
#else // !DIP_CONFIG_DOCTEST_IN_SHARED_LIB

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include <doctest/doctest.h>

#endif // DIP_CONFIG_DOCTEST_IN_SHARED_LIB

Expand All @@ -61,7 +61,7 @@ int main( int argc, const char* const* argv ) {

#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest.h"
#include <doctest/doctest.h>

#endif // DIP_CONFIG_DOCTEST_IN_SHARED_LIB

Expand Down
Loading