-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
114 lines (87 loc) · 4.33 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
cmake_minimum_required(VERSION 3.1)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake )
SET(PROJECT_NAME "dvidutils")
project(dvidutils)
include(CheckCXXCompilerFlag)
#-------------------------------------------------------------------------------------------------------------------
# check for c++ 14 support
#-------------------------------------------------------------------------------------------------------------------
# FIXME c++14 checks are broken???
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
CHECK_CXX_COMPILER_FLAG("-std=c++14" HAS_CPP14_FLAG)
#CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_CPP11_FLAG)
if (HAS_CPP14_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
else()
message(FATAL_ERROR "Unsupported compiler -- multi-array requires C++14 support!")
endif()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
# See:
# https://github.com/llvm/llvm-project/issues/91504
# https://github.com/exasmr/openmc/commit/62bb754ed4a2d21624bc9d67992fc58710593358#diff-1712b235e02bd4a3ad866fe26447a6dc5c1b449faeea513f449d244d46d03cf5R42
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-relaxed-template-template-args")
endif()
#-------------------------------------------------------------------------------------------------------------------
# include include files
#-------------------------------------------------------------------------------------------------------------------
#file(GLOB_RECURSE headers include/*.hxx)
include_directories(src)
# Support deduplication in draco encoding.
add_definitions("-DDRACO_ATTRIBUTE_DEDUPLICATION_SUPPORTED=1")
#-------------------------------------------------------------------------------------------------------------------
# Setup python bindings
#-------------------------------------------------------------------------------------------------------------------
set(CMAKE_PREFIX_PATH $ENV{CONDA_PREFIX} CACHE PATH "")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/share/cmake/pybind11")
find_package(pybind11 CONFIG REQUIRED)
include_directories("${CMAKE_PREFIX_PATH}/include")
link_directories("${CMAKE_PREFIX_PATH}/lib")
# numpy
set(PYBIND11_CPP_STANDARD -std=c++14)
find_package(NumPy REQUIRED)
include_directories(${NUMPY_INCLUDE_DIRS})
# boost
FIND_PACKAGE(Boost REQUIRED)
include_directories(AFTER ${Boost_INCLUDE_DIR})
#-------------------------------------------------------------------------------------------------------------------
# Add the package
#-------------------------------------------------------------------------------------------------------------------
set(DVIDUTILS_BUILD_OUTPUT_DIR "${CMAKE_BINARY_DIR}/$<CONFIG>")
set(DVIDUTILS_PACKAGE "${DVIDUTILS_BUILD_OUTPUT_DIR}/dvidutils")
# Target for the compiled module -- install to <build-dir>/dvidutils/_dvidutils.XXX
# https://github.com/pybind/pybind11/issues/3907#issuecomment-1170561643
pybind11_add_module(_dvidutils MODULE src/main.cpp) # Also locates Python, so we can use e.g. PYTHON_SITE_PACKAGES
set_target_properties(_dvidutils PROPERTIES PREFIX "")
# Link to draco
# NOTE: By default, draco doesn't build shared libs, but our conda recipe for it does.
# If we ever switch to conda-forge's package for draco, we'll have to change this to the static libs.
if (APPLE)
target_link_libraries(_dvidutils PRIVATE libdraco.dylib libdracoenc.dylib libdracodec.dylib)
else()
target_link_libraries(_dvidutils PRIVATE libdraco.so libdracoenc.so libdracodec.so)
endif()
set_target_properties(_dvidutils PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${DVIDUTILS_PACKAGE}")
# Target to copy the python sources to the build output
add_custom_target(dvidutils
ALL
COMMAND mkdir -p "${DVIDUTILS_PACKAGE}"
COMMAND cp -R "${CMAKE_SOURCE_DIR}/dvidutils/*" "${DVIDUTILS_PACKAGE}/"
)
add_dependencies(dvidutils _dvidutils)
#
# Tests
#
find_program(PYTEST_EXECUTABLE pytest)
add_custom_target(pytests
COMMAND "PYTHONPATH=${DVIDUTILS_BUILD_OUTPUT_DIR}" "${PYTEST_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/tests"
)
add_dependencies(pytests dvidutils)
#
# INSTALL
#
# python sources were already copied into the build output,
# so just copy the entire build output to the install dir
install(DIRECTORY "${DVIDUTILS_PACKAGE}" DESTINATION "${PYTHON_SITE_PACKAGES}")