blob: 70a0f094f6c75836f77867a674c9ff3a80faf432 [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
cmake_minimum_required(VERSION 3.16.0)
string(TIMESTAMP DT %Y%m%d UTC)
string(TIMESTAMP HHMM %H%M UTC)
configure_file(version.cfg.in version.cfg @ONLY)
file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/version.cfg BASE_VERSION)
project(DataSketchesPython
VERSION ${BASE_VERSION}
LANGUAGES CXX)
message("Configuring DataSketches Python version ${BASE_VERSION}")
include(GNUInstallDirs)
include(CMakeDependentOption)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_CXX_STANDARD 11)
# enable compiler warnings globally
# derived from https://foonathan.net/blog/2018/10/17/cmake-warnings.html
# and https://arne-mertz.de/2018/07/cmake-properties-options/
if (MSVC)
add_compile_options(/W4)
set(CMAKE_DEBUG_POSTFIX "d")
else()
add_compile_options(-Wall -pedantic -W -Wextra)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0")
add_compile_options(-Wimplicit-fallthrough=3)
endif()
# Code generation options, to ensure shaerd libraries work and are portable
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.18.0")
find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
else()
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
endif()
# only Windows+MSVC seems to have trouble locating pybind11
if (MSVC)
execute_process(COMMAND cmd.exe /c ${CMAKE_CURRENT_SOURCE_DIR}/pybind11Path.cmd "${Python3_EXECUTABLE}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE EXTRA_PACKAGE_PATH)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${EXTRA_PACKAGE_PATH})
endif()
find_package(pybind11 CONFIG REQUIRED)
pybind11_add_module(python MODULE EXCLUDE_FROM_ALL THIN_LTO)
set_target_properties(python PROPERTIES
PREFIX ""
OUTPUT_NAME _datasketches
)
target_include_directories(python
PUBLIC
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
# ensure we make a .so on Mac rather than .dylib
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_target_properties(python PROPERTIES SUFFIX ".so")
endif()
target_sources(python
PRIVATE
src/datasketches.cpp
src/hll_wrapper.cpp
src/kll_wrapper.cpp
src/cpc_wrapper.cpp
src/fi_wrapper.cpp
src/theta_wrapper.cpp
src/tuple_wrapper.cpp
src/vo_wrapper.cpp
src/req_wrapper.cpp
src/quantiles_wrapper.cpp
src/density_wrapper.cpp
src/ks_wrapper.cpp
src/count_wrapper.cpp
src/vector_of_kll.cpp
src/py_serde.cpp
)
cmake_policy(SET CMP0097 NEW)
include(ExternalProject)
ExternalProject_Add(datasketches
GIT_REPOSITORY https://github.com/apache/datasketches-cpp.git
GIT_TAG 4.1.0
GIT_SHALLOW true
GIT_SUBMODULES ""
INSTALL_DIR /tmp/datasketches
CMAKE_ARGS -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/tmp/datasketches
)
ExternalProject_Get_property(datasketches INSTALL_DIR)
set(datasketches_INSTALL_DIR ${INSTALL_DIR})
message("Source dir of datasketches = ${datasketches_INSTALL_DIR}")
target_include_directories(python
PRIVATE ${datasketches_INSTALL_DIR}/include/DataSketches)
add_dependencies(python datasketches)