diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index 000dc8a9..f2964adc 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -7,6 +7,7 @@ on: pull_request: branches: - main + - multi-language-api env: BUILD_TYPE: Release @@ -53,13 +54,15 @@ jobs: ./vcpkg integrate install shell: bash - - name: Install Linux system dependencies - if: runner.os == 'Linux' - run: sudo apt-get install -y autoconf automake autoconf-archive + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" - - name: Install MacOS system dependencies - if: runner.os == 'macOS' - run: NONINTERACTIVE=1 brew install autoconf automake autoconf-archive + - name: Install dependencies + run: | + python -m pip install -U pip + python -m pip install -U pybind11 libpython - name: Configure CMake run: | diff --git a/acquire-common b/acquire-common index 7afe044c..a5bb73d2 160000 --- a/acquire-common +++ b/acquire-common @@ -1 +1 @@ -Subproject commit 7afe044c0bb91c24bf8f397205b42f47ccade05a +Subproject commit a5bb73d21642360a0dd5a395fe0736168df65842 diff --git a/api/cpp/CMakeLists.txt b/api/cpp/CMakeLists.txt index d99e7a4d..83b3e5c3 100644 --- a/api/cpp/CMakeLists.txt +++ b/api/cpp/CMakeLists.txt @@ -3,7 +3,7 @@ project(acquire-zarr-cpp-api) set(tgt acquire-zarr-cpp) set(ACQUIRE_API_INCLUDE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/include/acquire-zarr/acquire-zarr.hh) -add_library(${tgt} SHARED +add_library(${tgt} ${ACQUIRE_API_INCLUDE_FILE} src/acquire-zarr-writer.cpp src/acquire-zarr-writer-impl.hh @@ -33,10 +33,15 @@ target_link_libraries(${tgt} PRIVATE set_target_properties(${tgt} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" PUBLIC_HEADER ${ACQUIRE_API_INCLUDE_FILE} + POSITION_INDEPENDENT_CODE ON ) install(TARGETS ${tgt} LIBRARY DESTINATION api/lib - PUBLIC_HEADER DESTINATION api/include/aqcuire-zarr + PUBLIC_HEADER DESTINATION api/include/acquire-zarr ) +option(ACQUIRE_BUILD_API_CPP_EXAMPLES "Build C++ API examples" OFF) +if(ACQUIRE_BUILD_API_CPP_EXAMPLES) + add_subdirectory(examples) +endif() \ No newline at end of file diff --git a/api/cpp/examples/CMakeLists.txt b/api/cpp/examples/CMakeLists.txt new file mode 100644 index 00000000..79b566bd --- /dev/null +++ b/api/cpp/examples/CMakeLists.txt @@ -0,0 +1,24 @@ +project(acquire-zarr-cpp-api-examples) + +#set(tgt acquire-zarr-cpp) +set(ACQUIRE_API_INCLUDE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/include/acquire-zarr/acquire-zarr.hh) + +set(examples + simple +) + +foreach (name ${examples}) + set(tgt "${name}") + add_executable(${name} ${name}.cpp) + + set_target_properties(${tgt} PROPERTIES + MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" + ) + target_include_directories(${tgt} PRIVATE "${acquire-zarr-cpp-api_SOURCE_DIR}/include") + target_link_libraries(${tgt} + acquire-zarr-cpp + ) + + #add_test(NAME test-${tgt} COMMAND ${tgt}) + #set_tests_properties(test-${tgt} PROPERTIES LABELS "anyplatform;acquire-driver-zarr") +endforeach () diff --git a/api/cpp/examples/simple.cpp b/api/cpp/examples/simple.cpp new file mode 100644 index 00000000..9d630b3b --- /dev/null +++ b/api/cpp/examples/simple.cpp @@ -0,0 +1,27 @@ +#include +#include + +int main() { + // Create a new instance of the AcquireZarr class + AcquireZarrWriter writer; + + writer.set_uri("simple.zarr"); + writer.set_use_v3(false); + writer.set_dimensions({"x","y","t"}); + writer.set_dimension_sizes({64,64,0}); + writer.set_chunk_sizes({64,64,1}); + writer.set_shard_sizes({64,64,1}); + writer.set_enable_multiscale(false); + writer.set_compression_codec(AcquireZarrCompressionCodec::COMPRESSION_NONE); + writer.set_compression_level(0); + writer.set_pixel_scale_x(1.0); + writer.set_pixel_scale_y(1.0); + writer.set_first_frame_id(0); + //writer.setExternalMetadata("{metadata}"); + + writer.start(); + + writer.stop(); + + return 0; +} diff --git a/api/cpp/include/acquire-zarr/acquire-zarr.hh b/api/cpp/include/acquire-zarr/acquire-zarr.hh index fbbbaff6..1f0214af 100644 --- a/api/cpp/include/acquire-zarr/acquire-zarr.hh +++ b/api/cpp/include/acquire-zarr/acquire-zarr.hh @@ -2,6 +2,7 @@ #define ACQUIRE_ZARR_HH #include +#include #include diff --git a/api/python/CMakeLists.txt b/api/python/CMakeLists.txt index 5dc841ed..5fc5c84f 100644 --- a/api/python/CMakeLists.txt +++ b/api/python/CMakeLists.txt @@ -1,6 +1,20 @@ cmake_minimum_required(VERSION 3.5...3.27) project(acquire-zarr-py) +# Find pip-installed pybind11 +execute_process(COMMAND python3 -m pybind11 --cmakedir + RESULT_VARIABLE pybind11_NOT_FOUND + OUTPUT_VARIABLE pybind11_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(pybind11_NOT_FOUND) + message(WARNING "pybind11 not found in the current environment. Please install pybind11 via pip.") +else() + LIST(APPEND CMAKE_MODULE_PATH ${pybind11_DIR}) + cmake_path(CONVERT CMAKE_MODULE_PATH TO_CMAKE_PATH_LIST CMAKE_MODULE_PATH) +endif() + find_package(Python3 REQUIRED COMPONENTS Interpreter Development) find_package(pybind11 REQUIRED) @@ -9,4 +23,8 @@ pybind11_add_module(acquire_zarr acquire-zarr-py-api.cpp) target_include_directories(acquire_zarr PRIVATE ${acquire-zarr-cpp-api_SOURCE_DIR}/include) target_link_libraries(acquire_zarr PRIVATE acquire-zarr-cpp) +set_target_properties(acquire_zarr PROPERTIES + MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" +) + install(TARGETS acquire_zarr LIBRARY DESTINATION acquire_zarr) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e1221ae5..a2a021d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,3 @@ -set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_subdirectory(3rdParty) if (NOT TARGET acquire-core-logger) @@ -85,4 +84,9 @@ set_target_properties(${tgt} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) +set_target_properties(${tgt}-obj PROPERTIES + MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" + POSITION_INDEPENDENT_CODE ON +) + install(TARGETS ${tgt} LIBRARY DESTINATION lib) diff --git a/vcpkg.json b/vcpkg.json index a93bc901..cc46a9e7 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -8,21 +8,10 @@ "name": "nlohmann-json", "version>=": "3.11.3" }, - {"name": "pybind11"}, - { - "name": "python3", - "version>=": "3.0.0" - }, { "name": "curlpp" }, { "name": "inih", "features": ["cpp"] }, { "name": "openssl" }, { "name": "pugixml" }, { "name": "zlib", "platform": "windows" } - ], - "overrides" : [ - { - "name": "python3", - "version": "3.10.7" - } ] -} \ No newline at end of file +}