Skip to content

Commit

Permalink
Get it building on Windows (#283)
Browse files Browse the repository at this point in the history
Fixed build, primarily by having C++ API be statically linked.

---------

Co-authored-by: Justin Eskesen <[email protected]>
  • Loading branch information
aliddell and jeskesen authored Aug 6, 2024
1 parent e0b7827 commit 33f8fa1
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 22 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- main
- multi-language-api

env:
BUILD_TYPE: Release
Expand Down Expand Up @@ -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: |
Expand Down
9 changes: 7 additions & 2 deletions api/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,10 +33,15 @@ target_link_libraries(${tgt} PRIVATE
set_target_properties(${tgt} PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>: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()
24 changes: 24 additions & 0 deletions api/cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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$<$<CONFIG:Debug>: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 ()
27 changes: 27 additions & 0 deletions api/cpp/examples/simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <acquire-zarr/acquire-zarr.hh>
#include <iostream>

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;
}
1 change: 1 addition & 0 deletions api/cpp/include/acquire-zarr/acquire-zarr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ACQUIRE_ZARR_HH

#include <memory>
#include <string>
#include <vector>


Expand Down
18 changes: 18 additions & 0 deletions api/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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$<$<CONFIG:Debug>:Debug>"
)

install(TARGETS acquire_zarr LIBRARY DESTINATION acquire_zarr)
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(3rdParty)

if (NOT TARGET acquire-core-logger)
Expand Down Expand Up @@ -85,4 +84,9 @@ set_target_properties(${tgt} PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)

set_target_properties(${tgt}-obj PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
POSITION_INDEPENDENT_CODE ON
)

install(TARGETS ${tgt} LIBRARY DESTINATION lib)
13 changes: 1 addition & 12 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
}

0 comments on commit 33f8fa1

Please sign in to comment.