-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from usnistgov/external_libhdf5
External libhdf5
- Loading branch information
Showing
2 changed files
with
59 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,56 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
include(FetchContent) | ||
|
||
# pre-cache the linker flags | ||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-sNODERAWFS=1 -sUSE_ZLIB=1" CACHE INTERNAL "") | ||
project(H5WASM | ||
DESCRIPTION "High level HDF5 read/write library" | ||
LANGUAGES CXX C | ||
) | ||
|
||
# set the project name | ||
project(H5WASM) | ||
FetchContent_Declare( | ||
libhdf5-wasm | ||
# URL file:///home/brian/dev/libhdf5-wasm/libhdf5-wasm.tar.gz | ||
URL https://github.com/usnistgov/libhdf5-wasm/releases/download/v0.1.1/libhdf5-1_12_1-wasm.tar.gz | ||
URL_HASH SHA256=e9bb11d89c4f26fa79b9cf1dab6159640c7b184ebf00dc97b098cd4f6de49bfe | ||
) | ||
FetchContent_MakeAvailable(libhdf5-wasm) | ||
|
||
option(BUILD_SHARED_LIBS "Build shared libs" OFF) | ||
option(HDF5_BUILD_EXAMPLES "Build Examples" OFF) | ||
option(HDF5_BUILD_TOOLS "Build Tools" OFF) | ||
option(HDF5_BUILD_UTILS "Build Utils" OFF) | ||
option(BUILD_TESTING "Build Tests" OFF) | ||
option(HDF5_BUILD_CPP_LIB "Build CPP libraries" ON) | ||
option(HDF5_ENABLE_Z_LIB_SUPPORT "Enable ZLIB" ON) | ||
add_executable(hdf5_util src/hdf5_util.cc) | ||
target_link_libraries(hdf5_util hdf5-wasm) | ||
|
||
set(CMAKE_INSTALL_PREFIX hdf5) | ||
set(H5_HAVE_GETPWUID OFF) | ||
set(H5_HAVE_SIGNAL OFF) | ||
# Optional flags to set when building your project | ||
set_target_properties(hdf5_util PROPERTIES | ||
LINK_FLAGS "-O3 --bind \ | ||
-lidbfs.js \ | ||
-s ALLOW_TABLE_GROWTH=1 \ | ||
-s ALLOW_MEMORY_GROWTH=1 \ | ||
-s WASM_BIGINT \ | ||
-s ENVIRONMENT=web \ | ||
-s SINGLE_FILE \ | ||
-s EXPORT_ES6=1 \ | ||
-s FORCE_FILESYSTEM=1 \ | ||
-s USE_ZLIB=1 \ | ||
-s EXPORTED_RUNTIME_METHODS=\"['ccall', 'cwrap', 'FS', 'AsciiToString', 'UTF8ToString']\" \ | ||
-s EXPORTED_FUNCTIONS=\"['_H5Fopen', '_H5Fclose', '_H5Fcreate']\"" | ||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/esm | ||
RUNTIME_OUTPUT_NAME hdf5_util | ||
) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/hdf5-hdf5-1_12_1) | ||
add_executable(hdf5_util_node src/hdf5_util.cc) | ||
target_link_libraries(hdf5_util_node hdf5-wasm) | ||
set_target_properties(hdf5_util_node PROPERTIES | ||
LINK_FLAGS "-O3 --bind \ | ||
-s ALLOW_TABLE_GROWTH=1 \ | ||
-s ALLOW_MEMORY_GROWTH=1 \ | ||
-s WASM_BIGINT \ | ||
-s NODERAWFS=1 \ | ||
-s FORCE_FILESYSTEM=1 \ | ||
-s ENVIRONMENT=node \ | ||
-s SINGLE_FILE \ | ||
-s MODULARIZE=1 \ | ||
-s USE_ZLIB=1 \ | ||
-s ASSERTIONS=1 \ | ||
-s EXPORTED_RUNTIME_METHODS=\"['ccall', 'cwrap', 'FS', 'AsciiToString', 'UTF8ToString']\" \ | ||
-s EXPORTED_FUNCTIONS=\"['_H5Fopen', '_H5Fclose', '_H5Fcreate']\"" | ||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/node | ||
RUNTIME_OUTPUT_NAME hdf5_util | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,13 @@ | ||
WASM_BUILD_DIR = wasm_build | ||
WASM_LIB_DIR = $(WASM_BUILD_DIR)/hdf5/lib | ||
WASM_INCLUDE_DIR = $(WASM_BUILD_DIR)/hdf5/include | ||
WASM_LIBS = $(WASM_LIB_DIR)/libhdf5.a $(WASM_LIB_DIR)/libhdf5_hl.a | ||
BUILD_DIR = build | ||
DIST_DIR = dist | ||
|
||
#WASM_LIBS = libhdf5.a | ||
HDF5_VER = hdf5-1_12_1 | ||
HDF5_SRC = hdf5-$(HDF5_VER) | ||
|
||
HDF5_DOWNLOAD_URL = https://github.com/HDFGroup/hdf5/archive/refs/tags/$(HDF5_VER).tar.gz | ||
HDF5_DOWNLOAD_HASH = e6dde173c2d243551922d23a0387a79961205b018502e6a742acb30b61bc2d5f | ||
SRC = src | ||
APP_DIR = dist | ||
APP_WASM = $(APP_DIR)/esm/hdf5_util.js $(APP_DIR)/node/hdf5_util.js | ||
LIBHDF5 = $(APP_DIR)/libhdf5.js $(APP_DIR)/libhdf5_sa.wasm | ||
|
||
app: $(APP_WASM) | ||
all: $(HDF5_SRC) $(APP_WASM) | ||
wasm: $(WASM_LIBS) | ||
wasm_tar: libhdf5_wasm.tgz | ||
|
||
$(HDF5_SRC): | ||
curl -L $(HDF5_DOWNLOAD_URL) -o hdf5_src.tgz; | ||
echo "$(HDF5_DOWNLOAD_HASH) hdf5_src.tgz" | shasum -a 256 --check -; | ||
tar -xzf hdf5_src.tgz; | ||
|
||
C_FLAGS = \ | ||
-Wno-incompatible-pointer-types-discards-qualifiers \ | ||
-Wno-misleading-indentation \ | ||
-Wno-missing-braces \ | ||
-Wno-self-assign \ | ||
-Wno-sometimes-uninitialized \ | ||
-Wno-unknown-warning-option \ | ||
-Wno-unused-but-set-variable \ | ||
-Wno-unused-function \ | ||
-Wno-unused-variable \ | ||
|
||
$(WASM_LIBS): $(HDF5_SRC) | ||
mkdir -p $(WASM_BUILD_DIR); | ||
cd $(WASM_BUILD_DIR) && emcmake cmake ../ | ||
cd $(WASM_BUILD_DIR) && emmake make -j8 install; | ||
|
||
wasm_tar: $(WASM_LIBS) | ||
tar -C $(WASM_BUILD_DIR)/hdf5/ -czf libhdf5_wasm.tgz include lib | ||
|
||
$(LIBHDF5): $(WASM_LIBS) | ||
emcc -O3 $(WASM_LIBS) \ | ||
-o $(APP_DIR)/libhdf5.html \ | ||
-I$(WASM_INCLUDE_DIR)/src \ | ||
-s WASM_BIGINT \ | ||
-s FORCE_FILESYSTEM=1 \ | ||
-s USE_ZLIB=1 \ | ||
-s EXPORT_ALL=1 \ | ||
-s LINKABLE=1 \ | ||
-s INCLUDE_FULL_LIBRARY=1 \ | ||
-s EXTRA_EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap', 'FS']" | ||
|
||
|
||
# -s EXTRA_EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap', 'FS']" | ||
|
||
$(APP_WASM): $(SRC)/hdf5_util.cc $(WASM_LIBS) | ||
all: | ||
mkdir -p dist/esm dist/node; | ||
emcc -O3 $(WASM_LIBS) $(SRC)/hdf5_util.cc -o $(APP_DIR)/esm/hdf5_util.js \ | ||
-I$(WASM_INCLUDE_DIR) \ | ||
--bind \ | ||
-lidbfs.js \ | ||
-s ALLOW_TABLE_GROWTH=1 \ | ||
-s ALLOW_MEMORY_GROWTH=1 \ | ||
-s WASM_BIGINT \ | ||
-s ENVIRONMENT=web \ | ||
-s EXPORT_ES6=1 \ | ||
-s FORCE_FILESYSTEM=1 \ | ||
-s USE_ZLIB=1 \ | ||
-s EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap', 'FS', 'AsciiToString', 'UTF8ToString']" \ | ||
-s EXPORTED_FUNCTIONS="['_H5Fopen', '_H5Fclose', '_H5Fcreate']"; | ||
|
||
emcc -O3 $(WASM_LIBS) $(SRC)/hdf5_util.cc -o $(APP_DIR)/node/hdf5_util.js \ | ||
-I$(WASM_INCLUDE_DIR) \ | ||
--bind \ | ||
-s ALLOW_TABLE_GROWTH=1 \ | ||
-s ALLOW_MEMORY_GROWTH=1 \ | ||
-s WASM_BIGINT \ | ||
-s NODERAWFS=1 \ | ||
-s FORCE_FILESYSTEM=1 \ | ||
-s ENVIRONMENT=node \ | ||
-s MODULARIZE=1 \ | ||
-s USE_ZLIB=1 \ | ||
-s ASSERTIONS=1 \ | ||
-s EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap', 'FS', 'AsciiToString', 'UTF8ToString']" \ | ||
-s EXPORTED_FUNCTIONS="['_H5Fopen', '_H5Fclose', '_H5Fcreate']"; | ||
|
||
mkdir -p $(BUILD_DIR); | ||
cd $(BUILD_DIR) && emcmake cmake ../; | ||
cd $(BUILD_DIR) && emmake make -j8; | ||
|
||
clean: | ||
rm -rf $(WASM_BUILD_DIR); | ||
rm -rf $(APP_DIR)/esm/; | ||
rm -rf $(APP_DIR)/node/; | ||
rm -rf $(BUILD_DIR); | ||
rm -rf $(DIST_DIR)/esm/; | ||
rm -rf $(DIST_DIR)/node/; |