|
| 1 | +cmake_minimum_required(VERSION 3.11.0) |
| 2 | +project(PDAL) |
| 3 | + |
| 4 | +set(CMAKE_CXX_STANDARD 11) |
| 5 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 6 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 7 | +option(WITH_TESTS "Enable tests" OFF) |
| 8 | +set(CMAKE_BUILD_TYPE "Release") |
| 9 | + |
| 10 | +# Python-finding settings |
| 11 | +set(Python3_FIND_STRATEGY "LOCATION") |
| 12 | +set(Python3_FIND_REGISTRY "LAST") |
| 13 | +set(Python3_FIND_FRAMEWORK "LAST") |
| 14 | +find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED) |
| 15 | + |
| 16 | +# find PDAL. Require 2.1+ |
| 17 | +find_package(PDAL 2.1 REQUIRED) |
| 18 | + |
| 19 | +# Taken and adapted from PDAL's cmake macros.cmake |
| 20 | + |
| 21 | +function(pdal_python_target_compile_settings target) |
| 22 | + set_property(TARGET ${target} PROPERTY CXX_STANDARD 11) |
| 23 | + set_property(TARGET ${target} PROPERTY CXX_STANDARD_REQUIRED TRUE) |
| 24 | + target_compile_definitions(${target} PRIVATE |
| 25 | + -DWIN32_LEAN_AND_MEAN) |
| 26 | + if (MSVC) |
| 27 | + # check for MSVC 8+ |
| 28 | + if (NOT (MSVC_VERSION VERSION_LESS 1400)) |
| 29 | + target_compile_definitions(${target} PRIVATE |
| 30 | + -D_CRT_SECURE_NO_DEPRECATE |
| 31 | + -D_CRT_SECURE_NO_WARNINGS |
| 32 | + -D_CRT_NONSTDC_NO_WARNING |
| 33 | + -D_SCL_SECURE_NO_WARNINGS |
| 34 | + ) |
| 35 | + target_compile_options(${target} PRIVATE |
| 36 | + # Yes, we don't understand GCC pragmas |
| 37 | + /wd4068 |
| 38 | + # Nitro makes use of Exception Specifications, which results in |
| 39 | + # numerous warnings when compiling in MSVC. We will ignore |
| 40 | + # them for now. |
| 41 | + /wd4290 |
| 42 | + /wd4800 |
| 43 | + # Windows warns about integer narrowing like crazy and it's |
| 44 | + # annoying. In most cases the programmer knows what they're |
| 45 | + # doing. A good static analysis tool would be better than |
| 46 | + # turning this warning off. |
| 47 | + /wd4267 |
| 48 | + # Annoying warning about function hiding with virtual |
| 49 | + # inheritance. |
| 50 | + /wd4250 |
| 51 | + # some templates don't return |
| 52 | +# /wd4716 |
| 53 | + # unwind semantics |
| 54 | +# /wd4530 |
| 55 | + # Standard C++-type exception handling. |
| 56 | + /EHsc |
| 57 | + ) |
| 58 | + endif() |
| 59 | + |
| 60 | + endif() |
| 61 | +endfunction() |
| 62 | + |
| 63 | + |
| 64 | +############################################################################### |
| 65 | +# Add a plugin target. |
| 66 | +# _name The plugin name. |
| 67 | +# ARGN : |
| 68 | +# FILES the source files for the plugin |
| 69 | +# LINK_WITH link plugin with libraries |
| 70 | +# INCLUDES header directories |
| 71 | +# |
| 72 | +# The "generate_dimension_hpp" ensures that Dimension.hpp is built before |
| 73 | +# attempting to build anything else in the "library". |
| 74 | +# |
| 75 | +# NOTE: _name is the name of a variable that will hold the plugin name |
| 76 | +# when the macro completes |
| 77 | +macro(PDAL_PYTHON_ADD_PLUGIN _name _type _shortname) |
| 78 | + set(options) |
| 79 | + set(oneValueArgs) |
| 80 | + set(multiValueArgs FILES LINK_WITH INCLUDES SYSTEM_INCLUDES COMPILE_OPTIONS) |
| 81 | + cmake_parse_arguments(PDAL_PYTHON_ADD_PLUGIN "${options}" "${oneValueArgs}" |
| 82 | + "${multiValueArgs}" ${ARGN}) |
| 83 | + if(WIN32) |
| 84 | + set(WINSOCK_LIBRARY ws2_32) |
| 85 | + set(${_name} "libpdal_plugin_${_type}_${_shortname}") |
| 86 | + else() |
| 87 | + set(${_name} "pdal_plugin_${_type}_${_shortname}") |
| 88 | + endif() |
| 89 | + |
| 90 | + |
| 91 | + add_library(${${_name}} SHARED ${PDAL_PYTHON_ADD_PLUGIN_FILES}) |
| 92 | + pdal_python_target_compile_settings(${${_name}}) |
| 93 | + target_include_directories(${${_name}} PRIVATE |
| 94 | + ${PROJECT_BINARY_DIR}/include |
| 95 | + ${PDAL_INCLUDE_DIR} |
| 96 | + ${PDAL_PYTHON_ADD_PLUGIN_INCLUDES} |
| 97 | + ) |
| 98 | + target_link_options(${${_name}} BEFORE PRIVATE ${PDAL_PYTHON_ADD_PLUGIN_COMPILE_OPTIONS}) |
| 99 | + target_compile_definitions(${${_name}} PRIVATE |
| 100 | + PDAL_PYTHON_LIBRARY="${PYTHON_LIBRARY}" PDAL_DLL_EXPORT) |
| 101 | + target_compile_definitions(${${_name}} PRIVATE PDAL_DLL_EXPORT) |
| 102 | + if (PDAL_PYTHON_ADD_PLUGIN_SYSTEM_INCLUDES) |
| 103 | + target_include_directories(${${_name}} SYSTEM PRIVATE |
| 104 | + ${PDAL_PYTHON_ADD_PLUGIN_SYSTEM_INCLUDES}) |
| 105 | + endif() |
| 106 | + target_link_libraries(${${_name}} PRIVATE |
| 107 | + ${PDAL_PYTHON_ADD_PLUGIN_LINK_WITH} |
| 108 | + ${WINSOCK_LIBRARY} |
| 109 | + ) |
| 110 | + |
| 111 | + message(STATUS "PROJECT_NAME: ${PROJECT_NAME}") |
| 112 | + install(TARGETS ${${_name}} LIBRARY DESTINATION "pdal") |
| 113 | + if (APPLE) |
| 114 | + set_target_properties(${${_name}} PROPERTIES |
| 115 | + INSTALL_NAME_DIR "@rpath") |
| 116 | + endif() |
| 117 | +endmacro(PDAL_PYTHON_ADD_PLUGIN) |
| 118 | + |
| 119 | + |
| 120 | +macro(PDAL_PYTHON_ADD_TEST _name) |
| 121 | + set(options) |
| 122 | + set(oneValueArgs) |
| 123 | + set(multiValueArgs FILES LINK_WITH INCLUDES SYSTEM_INCLUDES) |
| 124 | + cmake_parse_arguments(PDAL_PYTHON_ADD_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
| 125 | + if (WIN32) |
| 126 | + set(WINSOCK_LIBRARY ws2_32) |
| 127 | + endif() |
| 128 | + add_executable(${_name} ${PDAL_PYTHON_ADD_TEST_FILES}) |
| 129 | + |
| 130 | + pdal_python_target_compile_settings(${_name}) |
| 131 | + target_include_directories(${_name} PRIVATE |
| 132 | + ${PDAL_PYTHON_ADD_TEST_INCLUDES}) |
| 133 | + if (PDAL_PYTHON_ADD_TEST_SYSTEM_INCLUDES) |
| 134 | + target_include_directories(${_name} SYSTEM PRIVATE |
| 135 | + ${PDAL_PYTHON_ADD_TEST_SYSTEM_INCLUDES}) |
| 136 | + endif() |
| 137 | + set_property(TARGET ${_name} PROPERTY FOLDER "Tests") |
| 138 | + target_link_libraries(${_name} |
| 139 | + PRIVATE |
| 140 | + ${PDAL_PYTHON_ADD_TEST_LINK_WITH} |
| 141 | + gtest |
| 142 | + ${WINSOCK_LIBRARY} |
| 143 | + ) |
| 144 | + target_compile_definitions(${_name} PRIVATE |
| 145 | + PDAL_PYTHON_LIBRARY="${PYTHON_LIBRARY}") |
| 146 | + add_test(NAME ${_name} |
| 147 | + COMMAND |
| 148 | + "${PROJECT_BINARY_DIR}/bin/${_name}" |
| 149 | + WORKING_DIRECTORY |
| 150 | + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/..") |
| 151 | +endmacro(PDAL_PYTHON_ADD_TEST) |
| 152 | + |
| 153 | +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 154 | + # For newer versions of python (3.8+), C extensions don't link against |
| 155 | + # libpython and instead get symbol definitions from the python interpreter |
| 156 | + # executable. PDAL plugins need to link against libpython, but if a plugin |
| 157 | + # is loaded inside a python process, it must resolve symbols from the python |
| 158 | + # executable instead of libpython. Using flat namespace allows that. |
| 159 | + set(PYTHON_LINK_LIBRARY ${PYTHON_LINK_LIBRARY} -Wl,-flat_namespace) |
| 160 | +endif() |
| 161 | + |
| 162 | +PDAL_PYTHON_ADD_PLUGIN(numpy_reader reader numpy |
| 163 | + FILES |
| 164 | + ./pdal/io/NumpyReader.cpp |
| 165 | + ./pdal/io/NumpyReader.hpp |
| 166 | + ./pdal/plang/Invocation.cpp |
| 167 | + ./pdal/plang/Environment.cpp |
| 168 | + ./pdal/plang/Redirector.cpp |
| 169 | + ./pdal/plang/Script.cpp |
| 170 | + LINK_WITH |
| 171 | + ${PDAL_LIBRARIES} |
| 172 | + ${Python3_LIBRARIES} |
| 173 | + ${CMAKE_DL_LIBS} |
| 174 | + SYSTEM_INCLUDES |
| 175 | + ${PDAL_INCLUDE_DIRS} |
| 176 | + ${Python3_INCLUDE_DIRS} |
| 177 | + ${Python3_NumPy_INCLUDE_DIRS} |
| 178 | + COMPILE_OPTIONS |
| 179 | + ${PYTHON_LINK_LIBRARY} |
| 180 | + ) |
| 181 | + |
| 182 | +PDAL_PYTHON_ADD_PLUGIN(python_filter filter python |
| 183 | + FILES |
| 184 | + ./pdal/filters/PythonFilter.cpp |
| 185 | + ./pdal/filters/PythonFilter.hpp |
| 186 | + ./pdal/plang/Invocation.cpp |
| 187 | + ./pdal/plang/Environment.cpp |
| 188 | + ./pdal/plang/Redirector.cpp |
| 189 | + ./pdal/plang/Script.cpp |
| 190 | + LINK_WITH |
| 191 | + ${PDAL_LIBRARIES} |
| 192 | + ${Python3_LIBRARIES} |
| 193 | + ${CMAKE_DL_LIBS} |
| 194 | + SYSTEM_INCLUDES |
| 195 | + ${PDAL_INCLUDE_DIRS} |
| 196 | + ${Python3_INCLUDE_DIRS} |
| 197 | + ${Python3_NumPy_INCLUDE_DIRS} |
| 198 | + COMPILE_OPTIONS |
| 199 | + ${PYTHON_LINK_LIBRARY} |
| 200 | + ) |
| 201 | + |
| 202 | + |
| 203 | +if (WITH_TESTS) |
| 204 | + enable_testing() |
| 205 | + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 206 | + add_subdirectory(pdal/test/gtest) |
| 207 | + enable_testing() |
| 208 | + include_directories(pdal/test/gtest/include .. ${CMAKE_CURRENT_BINARY_DIR}) |
| 209 | + PDAL_PYTHON_ADD_TEST(pdal_io_numpy_test |
| 210 | + FILES |
| 211 | + ./pdal/test/NumpyReaderTest.cpp |
| 212 | + ./pdal/test/Support.cpp |
| 213 | + ./pdal/plang/Invocation.cpp |
| 214 | + ./pdal/plang/Environment.cpp |
| 215 | + ./pdal/plang/Redirector.cpp |
| 216 | + ./pdal/plang/Script.cpp |
| 217 | + LINK_WITH |
| 218 | + ${numpy_reader} |
| 219 | + ${Python3_LIBRARIES} |
| 220 | + ${PDAL_LIBRARIES} |
| 221 | + ${CMAKE_DL_LIBS} |
| 222 | + SYSTEM_INCLUDES |
| 223 | + ${PDAL_INCLUDE_DIRS} |
| 224 | + ${Python3_INCLUDE_DIRS} |
| 225 | + ${Python3_NumPy_INCLUDE_DIRS} |
| 226 | + ) |
| 227 | + PDAL_PYTHON_ADD_TEST(pdal_filters_python_test |
| 228 | + FILES |
| 229 | + ./pdal/test/PythonFilterTest.cpp |
| 230 | + ./pdal/test/Support.cpp |
| 231 | + ./pdal/plang/Invocation.cpp |
| 232 | + ./pdal/plang/Environment.cpp |
| 233 | + ./pdal/plang/Redirector.cpp |
| 234 | + ./pdal/plang/Script.cpp |
| 235 | + LINK_WITH |
| 236 | + ${python_filter} |
| 237 | + ${Python3_LIBRARIES} |
| 238 | + ${PDAL_LIBRARIES} |
| 239 | + ${CMAKE_DL_LIBS} |
| 240 | + SYSTEM_INCLUDES |
| 241 | + ${PDAL_INCLUDE_DIRS} |
| 242 | + ${Python3_INCLUDE_DIRS} |
| 243 | + ${Python3_NumPy_INCLUDE_DIRS} |
| 244 | + ) |
| 245 | +endif (WITH_TESTS) |
0 commit comments