Skip to content

Commit

Permalink
Merge pull request #717 from kordejong/gh714
Browse files Browse the repository at this point in the history
Split `lue_py_framework` library
  • Loading branch information
kordejong authored Aug 30, 2024
2 parents 8da4905 + 655285a commit 5089238
Show file tree
Hide file tree
Showing 32 changed files with 160 additions and 96 deletions.
7 changes: 4 additions & 3 deletions source/framework/api/c/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ foreach(name ${names})
add_executable(${test_name} ${module_name}.cpp)

target_link_libraries(${test_name}
PUBLIC
lue::framework_api_c
PRIVATE
lue::framework_api_c
lue::framework_test
Boost::unit_test_framework
Boost::headers
)

add_test(NAME ${test_name}
Expand Down Expand Up @@ -46,6 +45,8 @@ foreach(name ${names})
PATH=path_list_prepend:$<TARGET_FILE_DIR:lue::framework_focal_operation>
PATH=path_list_prepend:$<TARGET_FILE_DIR:lue::framework_routing_operation>
PATH=path_list_prepend:$<TARGET_FILE_DIR:lue::framework_zonal_operation>
PATH=path_list_prepend:$<$<PLATFORM_ID:Windows>:$<TARGET_FILE_DIR:hdf5::hdf5>/../bin>
PATH=path_list_prepend:$<$<PLATFORM_ID:Windows>:${HWLOC_ROOT}/bin>
)
endif()
endforeach()
10 changes: 5 additions & 5 deletions source/framework/api/cxx/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ set(names

foreach(name ${names})
set(module_name ${name}_test)
string(REPLACE "/" "_" test_name ${module_name})
set(test_name ${scope}_${test_name})
string(REPLACE "/" "_" test_name ${scope}_${module_name})

add_executable(${test_name} ${module_name}.cpp)

target_link_libraries(${test_name}
PUBLIC
lue::framework_api_cxx
PRIVATE
lue::framework_api_cxx
lue_framework_algorithm_test
# lue::framework_algorithm
# lue::framework_global_operation # unique
lue::framework_test
Boost::unit_test_framework
Boost::headers
)

add_test(NAME ${test_name}
Expand Down Expand Up @@ -56,6 +54,8 @@ foreach(name ${names})
PATH=path_list_prepend:$<TARGET_FILE_DIR:lue::framework_focal_operation>
PATH=path_list_prepend:$<TARGET_FILE_DIR:lue::framework_routing_operation>
PATH=path_list_prepend:$<TARGET_FILE_DIR:lue::framework_zonal_operation>
PATH=path_list_prepend:$<$<PLATFORM_ID:Windows>:$<TARGET_FILE_DIR:hdf5::hdf5>/../bin>
PATH=path_list_prepend:$<$<PLATFORM_ID:Windows>:${HWLOC_ROOT}/bin>
)
endif()
endforeach()
Expand Down
4 changes: 4 additions & 0 deletions source/framework/api/python/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set_property(
ENVIRONMENT
$<$<AND:$<NOT:$<PLATFORM_ID:Windows>>,$<STREQUAL:${HPX_WITH_MALLOC},tcmalloc>>:$<IF:$<PLATFORM_ID:Darwin>,DYLD_INSERT_LIBRARIES,LD_PRELOAD>=${TCMALLOC_LIBRARY}>
)

set_property(
TEST
lue_framework_api_python_test
Expand All @@ -32,7 +33,10 @@ set_property(
PYTHONPATH=path_list_prepend:$<TARGET_FILE_DIR:lue::py>/..
PYTHONPATH=path_list_prepend:$<TARGET_PROPERTY:lue::py_framework,SOURCE_DIR>/test
PYTHONPATH=path_list_prepend:${CMAKE_CURRENT_SOURCE_DIR}
PATH=path_list_prepend:$<$<PLATFORM_ID:Windows>:$<TARGET_FILE_DIR:hdf5::hdf5>/../bin>
PATH=path_list_prepend:$<$<PLATFORM_ID:Windows>:${HWLOC_ROOT}/bin>
)

set_property(
TEST
lue_framework_api_python_test
Expand Down
2 changes: 2 additions & 0 deletions source/framework/image_land/python/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ set_property(
PYTHONPATH=path_list_prepend:$<TARGET_FILE_DIR:lue::py>/..
PYTHONPATH=path_list_prepend:$<TARGET_PROPERTY:lue::py_framework,SOURCE_DIR>/test # lue_unit_test.py
PYTHONPATH=path_list_prepend:${CMAKE_CURRENT_SOURCE_DIR}
PATH=path_list_prepend:$<$<PLATFORM_ID:Windows>:$<TARGET_FILE_DIR:hdf5::hdf5>/../bin>
PATH=path_list_prepend:$<$<PLATFORM_ID:Windows>:${HWLOC_ROOT}/bin>
)
set_property(
TEST
Expand Down
2 changes: 2 additions & 0 deletions source/framework/image_land/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ foreach(name ${names})
PATH=path_list_prepend:$<TARGET_FILE_DIR:lue::framework_routing_operation>
PATH=path_list_prepend:$<TARGET_FILE_DIR:lue::framework_zonal_operation>
PATH=path_list_prepend:$<TARGET_FILE_DIR:lue::image_land>
PATH=path_list_prepend:$<$<PLATFORM_ID:Windows>:$<TARGET_FILE_DIR:hdf5::hdf5>/../bin>
PATH=path_list_prepend:$<$<PLATFORM_ID:Windows>:${HWLOC_ROOT}/bin>
)
endif()
endforeach()
133 changes: 94 additions & 39 deletions source/framework/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,37 @@ file(GENERATE

# A pybind11 SHARED library is a CMake runtime output artifact. Target properties to set/get are
# RUNTIME_OUTPUT_DIRECTORY and RUNTIME_OUTPUT_NAME.
add_library(lue_py_framework SHARED
src/algorithm/accu.cpp
src/algorithm/accu3.cpp
src/algorithm/accu_fraction.cpp
src/algorithm/accu_info.cpp
src/algorithm/accu_info3.cpp
src/algorithm/accu_threshold.cpp
src/algorithm/accu_threshold3.cpp
src/algorithm/all.cpp
src/algorithm/array_partition_id.cpp
src/algorithm/aspect.cpp
src/algorithm/atan2.cpp
src/algorithm/d8_flow_direction.cpp
src/algorithm/downstream.cpp
src/algorithm/downstream_distance.cpp
src/algorithm/inflow_count.cpp
src/algorithm/inflow_count3.cpp
src/algorithm/inter_partition_stream.cpp
src/algorithm/iterate_per_element.cpp
src/algorithm/locality_id.cpp
src/algorithm/normal.cpp
src/algorithm/slope.cpp
src/algorithm/timestamp.cpp
src/algorithm/uniform.cpp
src/algorithm/upstream.cpp
src/algorithm/where.cpp

add_library(lue_py_framework_focal_operation SHARED
src/algorithm/focal_operation.cpp
src/algorithm/focal_operation/aspect.cpp
src/algorithm/focal_operation/focal_diversity.cpp
src/algorithm/focal_operation/focal_high_pass.cpp
src/algorithm/focal_operation/focal_majority.cpp
src/algorithm/focal_operation/focal_maximum.cpp
src/algorithm/focal_operation/focal_mean.cpp
src/algorithm/focal_operation/focal_minimum.cpp
src/algorithm/focal_operation/slope.cpp
src/algorithm/focal_operation/focal_sum.cpp
)

add_library(lue_py_framework_global_operation SHARED
src/algorithm/global_operation.cpp
src/algorithm/global_operation/reclassify.cpp
src/algorithm/global_operation/maximum.cpp
src/algorithm/global_operation/minimum.cpp
src/algorithm/global_operation/sum.cpp
)

add_library(lue_py_framework_local_operation SHARED
src/algorithm/local_operation.cpp
src/algorithm/local_operation/abs.cpp
src/algorithm/local_operation/acos.cpp
src/algorithm/local_operation/add.cpp
src/algorithm/local_operation/all.cpp
src/algorithm/local_operation/asin.cpp
src/algorithm/local_operation/atan.cpp
src/algorithm/local_operation/atan2.cpp
src/algorithm/local_operation/cast.cpp
src/algorithm/local_operation/cell_index.cpp
src/algorithm/local_operation/cos.cpp
Expand All @@ -83,6 +66,7 @@ add_library(lue_py_framework SHARED
src/algorithm/local_operation/floor.cpp
src/algorithm/local_operation/greater_than.cpp
src/algorithm/local_operation/greater_than_equal_to.cpp
src/algorithm/local_operation/iterate_per_element.cpp
src/algorithm/local_operation/less_than.cpp
src/algorithm/local_operation/less_than_equal_to.cpp
src/algorithm/local_operation/log.cpp
Expand All @@ -102,12 +86,32 @@ add_library(lue_py_framework SHARED
src/algorithm/local_operation/tan.cpp
src/algorithm/local_operation/unique_id.cpp
src/algorithm/local_operation/valid.cpp
src/algorithm/local_operation/where.cpp
)

add_library(lue_py_framework_routing_operation SHARED
src/algorithm/routing_operation.cpp
src/algorithm/routing_operation/accu.cpp
src/algorithm/routing_operation/accu3.cpp
src/algorithm/routing_operation/accu_fraction.cpp
src/algorithm/routing_operation/accu_info.cpp
src/algorithm/routing_operation/accu_info3.cpp
src/algorithm/routing_operation/accu_threshold.cpp
src/algorithm/routing_operation/accu_threshold3.cpp
src/algorithm/routing_operation/d8_flow_direction.cpp
src/algorithm/routing_operation/decreasing_order.cpp
src/algorithm/routing_operation/downstream.cpp
src/algorithm/routing_operation/downstream_distance.cpp
src/algorithm/routing_operation/first_n.cpp
src/algorithm/routing_operation/inflow_count.cpp
src/algorithm/routing_operation/inflow_count3.cpp
src/algorithm/routing_operation/inter_partition_stream.cpp
src/algorithm/routing_operation/kinematic_wave.cpp
src/algorithm/routing_operation/upstream.cpp

)

add_library(lue_py_framework_zonal_operation SHARED
src/algorithm/zonal_operation.cpp
src/algorithm/zonal_operation/clump.cpp
src/algorithm/zonal_operation/zonal_area.cpp
Expand All @@ -119,6 +123,33 @@ add_library(lue_py_framework SHARED
src/algorithm/zonal_operation/zonal_normal.cpp
src/algorithm/zonal_operation/zonal_sum.cpp
src/algorithm/zonal_operation/zonal_uniform.cpp
)

foreach(name focal global local routing zonal)
add_library(lue::py_framework_${name}_operation ALIAS lue_py_framework_${name}_operation)

target_compile_definitions(lue_py_framework_${name}_operation
PRIVATE
NPY_NO_DEPRECATED_API=${LUE_NPY_NO_DEPRECATED_API}
)

target_link_libraries(lue_py_framework_${name}_operation
PRIVATE
lue::framework_${name}_operation
pybind11::module
pybind11::thin_lto
pybind11::opt_size
pybind11::windows_extras
Python::Python
)
endforeach()

add_library(lue_py_framework SHARED
src/algorithm/array_partition_id.cpp
src/algorithm/locality_id.cpp
src/algorithm/timestamp.cpp
src/algorithm/normal.cpp
src/algorithm/uniform.cpp

src/core/create_partitioned_array.cpp
src/core/partitioned_array.cpp
Expand Down Expand Up @@ -164,12 +195,6 @@ target_compile_definitions(lue_py_framework
NPY_NO_DEPRECATED_API=${LUE_NPY_NO_DEPRECATED_API}
)

set_target_properties(lue_py_framework
PROPERTIES
VERSION ${LUE_VERSION}
SOVERSION ${LUE_VERSION_MAJOR}
)

target_include_directories(lue_py_framework
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../../data_model/python/include
Expand All @@ -181,11 +206,12 @@ target_include_directories(lue_py_framework

target_link_libraries(lue_py_framework
PRIVATE
lue::framework_focal_operation
lue::framework_global_operation
lue::framework_local_operation
lue::framework_routing_operation
lue::framework_zonal_operation
lue::py_framework_focal_operation
lue::py_framework_global_operation
lue::py_framework_local_operation
lue::py_framework_routing_operation
lue::py_framework_zonal_operation
lue::framework_local_operation # array and scalar use local operations in operators
lue::framework_io
lue::framework_model
pybind11::module
Expand All @@ -195,22 +221,51 @@ target_link_libraries(lue_py_framework
Python::Python
)

set_target_properties(
lue_py_framework_focal_operation
lue_py_framework_global_operation
lue_py_framework_local_operation
lue_py_framework_routing_operation
lue_py_framework_zonal_operation
lue_py_framework
PROPERTIES
VERSION ${LUE_VERSION}
SOVERSION ${LUE_VERSION_MAJOR}
)

# TODO pybind11_strip does not work on macOS, when building using Conda packages
# The resulting binary can't be imported. Results in "killed: 9".
if(NOT MSVC AND NOT APPLE AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
pybind11_strip(lue_py_framework)
pybind11_strip(lue_py_framework_focal_operation)
pybind11_strip(lue_py_framework_global_operation)
pybind11_strip(lue_py_framework_local_operation)
pybind11_strip(lue_py_framework_zonal_operation)
pybind11_strip(lue_py_framework_routing_operation)
endif()

lue_install_runtime_libraries(
TARGETS lue_py_framework
TARGETS
lue_py_framework
lue_py_framework_focal_operation
lue_py_framework_global_operation
lue_py_framework_local_operation
lue_py_framework_zonal_operation
lue_py_framework_routing_operation
)

if(LUE_PYTHON_FROM_CONDA AND NOT DEFINED ENV{CONDA_BUILD})
# If we are using a Python interpreter from a Conda environment then we must expand RPATH
# to include the location of the Python libraries. But if we are building a Conda package,
# we assume Conda takes care of RPATH handling.
set_property(
TARGET lue_py_framework
TARGET
lue_py_framework
lue_py_framework_focal_operation
lue_py_framework_global_operation
lue_py_framework_local_operation
lue_py_framework_zonal_operation
lue_py_framework_routing_operation
APPEND
PROPERTY INSTALL_RPATH
${Python_LIBRARY_DIRS}
Expand Down
6 changes: 5 additions & 1 deletion source/framework/python/src/algorithm/focal_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@

namespace lue::framework {

void bind_aspect(pybind11::module& module);
void bind_focal_diversity(pybind11::module& module);
void bind_focal_high_pass(pybind11::module& module);
void bind_focal_majority(pybind11::module& module);
void bind_focal_maximum(pybind11::module& module);
void bind_focal_mean(pybind11::module& module);
void bind_focal_minimum(pybind11::module& module);
void bind_slope(pybind11::module& module);
void bind_focal_sum(pybind11::module& module);


void bind_focal_operations(pybind11::module& module)
PYBIND11_EXPORT void bind_focal_operations(pybind11::module& module)
{
bind_aspect(module);
bind_focal_diversity(module);
bind_focal_high_pass(module);
bind_focal_majority(module);
bind_focal_maximum(module);
bind_focal_mean(module);
bind_focal_minimum(module);
bind_slope(module);
bind_focal_sum(module);
}

Expand Down
2 changes: 1 addition & 1 deletion source/framework/python/src/algorithm/global_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace lue::framework {
void bind_sum(pybind11::module& module);


void bind_global_operations(pybind11::module& module)
PYBIND11_EXPORT void bind_global_operations(pybind11::module& module)
{
bind_reclassify(module);
bind_maximum(module);
Expand Down
Loading

0 comments on commit 5089238

Please sign in to comment.