From a9b4631a8f966512d689e64b3b0266e356099d54 Mon Sep 17 00:00:00 2001 From: Shreeraj Jadhav Date: Tue, 16 Jul 2024 12:26:06 -0400 Subject: [PATCH] docs: update docs and add scripts for native build Update documentation and add shell scripts in dev-utils/ folder for cloning source code and building natively. Add special flags and details for working around MSVC windows quirks. --- dev-utils/itk-wasm-native-build.sh | 68 +++++++++++++++++++++++++ dev-utils/itk-wasm-native-get-source.sh | 43 ++++++++++++++++ docs/development/hacking_itk_wasm.md | 54 ++++++++++++++++++-- 3 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 dev-utils/itk-wasm-native-build.sh create mode 100644 dev-utils/itk-wasm-native-get-source.sh diff --git a/dev-utils/itk-wasm-native-build.sh b/dev-utils/itk-wasm-native-build.sh new file mode 100644 index 000000000..23738b453 --- /dev/null +++ b/dev-utils/itk-wasm-native-build.sh @@ -0,0 +1,68 @@ +#!/bin/bash +if [$OSTYPE == "cygwin"] || [$OSTYPE == "msys"] || [$OSTYPE =="win32"]; then + echo "Windows platform detected ... adding \"/Zc:__cplusplus /DNOMINMAX\" to \$CXXFLAGS" + export CXXFLAGS="/Zc:__cplusplus /DNOMINMAX" +fi +#if [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" =="win32" ]]; then + +cmake -BITK-build -SITK \ + -DBUILD_TESTING=OFF \ + -DCMAKE_CXX_STANDARD:STRING=17 \ + -DCMAKE_BUILD_TYPE:STRING=Debug \ + -DCMAKE_CONFIGURATION_TYPES:STRING=Debug \ + -DBUILD_EXAMPLES:BOOL=OFF \ + -DBUILD_TESTING:BOOL=OFF \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_STATIC_LIBS=ON \ + -DDCMTK_LINK_STATIC=ON \ + -DITK_LEGACY_REMOVE:BOOL=ON \ + -DITK_BUILD_DEFAULT_MODULES:BOOL=ON \ + -DITKGroup_IO:BOOL=ON \ + -DH5_HAVE_GETPWUID:BOOL=OFF \ + -DModule_ITKIOMINC:BOOL=ON \ + -DModule_MGHIO:BOOL=ON \ + -DModule_IOMeshSWC:BOOL=ON \ + -DModule_IOScanco:BOOL=ON \ + -DModule_IOFDF:BOOL=ON \ + -DModule_ITKDCMTK:BOOL=ON \ + -DModule_ITKImageFunction:BOOL=ON \ + -DModule_MinimalPathExtraction:BOOL=ON \ + -DModule_MorphologicalContourInterpolation:BOOL=ON \ + -DModule_SmoothingRecursiveYvvGaussianFilter:BOOL=ON \ + -DModule_Cuberille:BOOL=ON \ + -DModule_TotalVariation:BOOL=ON \ + -DModule_IOMeshSTL:BOOL=ON \ + -DModule_GenericLabelInterpolator:BOOL=ON \ + -DModule_MeshToPolyData=ON \ + -DDO_NOT_BUILD_ITK_TEST_DRIVER:BOOL=ON \ + -DOPJ_USE_THREAD:BOOL=OFF \ + -DDCMTK_WITH_THREADS:BOOL=OFF \ + -DDCMTK_BUILD_APPS:BOOL=OFF \ + -DNO_FLOAT_EXCEPTIONS:BOOL=ON \ + -DITK_MSVC_STATIC_RUNTIME_LIBRARY=ON + +cmake --build ITK-build --config Debug -j16 + +cmake -BITK-Wasm-build \ + -SITK-Wasm \ + -DBUILD_TESTING=ON \ + -DCMAKE_CXX_STANDARD:STRING=20 \ + -DCMAKE_BUILD_TYPE:STRING=Debug \ + -DCMAKE_CONFIGURATION_TYPES:STRING=Debug \ + -DBUILD_SHARED_LIBS=OFF \ + -DITK_DIR=$PWD/ITK-build + +cmake --build ITK-Wasm-build --config Debug -j16 + +cmake -Bpackages-dicom \ + -SITK-Wasm/packages/dicom \ + -DBUILD_TESTING=ON \ + -DCMAKE_CXX_STANDARD:STRING=20 \ + -DCMAKE_BUILD_TYPE:STRING=Debug \ + -DCMAKE_CONFIGURATION_TYPES:STRING=Debug \ + -DITK_DIR=$PWD/ITK-build + +cmake --build packages-dicom --config Debug -j16 + +ctest --test-dir ITK-Wasm-build -C Debug + diff --git a/dev-utils/itk-wasm-native-get-source.sh b/dev-utils/itk-wasm-native-get-source.sh new file mode 100644 index 000000000..c29053f57 --- /dev/null +++ b/dev-utils/itk-wasm-native-get-source.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# workdir +work_dir="~/itk-wasm-native" + +# main +itk_repository="https://github.com/KitwareMedical/ITK.git" +itk_branch="itkwasm-main-mutable" +dcmtk_repository="https://github.com/InsightSoftwareConsortium/DCMTK.git" +dcmtk_tag="fe7cff5de40b67ae0490d476ddf17689c06bcaf4" +wasm_repository="https://github.com/InsightSoftwareConsortium/ITK-Wasm" +wasm_branch="main" + +# dev-override +#itk_repository="https://github.com/jadh4v/ITK.git" +#itk_branch="itkwasm-2024-06-06" +#wasm_repository="https://github.com/jadh4v/ITK-Wasm" +#wasm_branch="dicom-seg" + +echo "itk_repository = $itk_repository" +echo "itk_branch = $itk_branch" +echo "wasm_repository = $wasm_repository" +echo "wasm_branch = $wasm_branch" + +mkdir $work_dir + +cd $work_dir + +git clone $itk_repository --branch=$itk_branch + +git clone $wasm_repository --branch=$wasm_branch + +#dcmtk_repository="https://github.com/jadh4v/DCMTK.git" +#dcmtk_tag="62ebb7bb6e9ffb5311ff0f7baaa935b9b85296ec" +#echo "dcmtk_repository = $dcmtk_repository" +#echo "dcmtk_tag = $dcmtk_tag" + +#sed -i -e '/^set(DCMTK_GIT_REPOSITORY/c\set(DCMTK_GIT_REPOSITORY "'$dcmtk_repository'")' \ +# ITK/Modules/ThirdParty/DCMTK/DCMTKGitTag.cmake + +#sed -i -e '/^set(DCMTK_GIT_TAG/c\set(DCMTK_GIT_TAG "'$dcmtk_tag'")' \ +# ITK/Modules/ThirdParty/DCMTK/DCMTKGitTag.cmake + diff --git a/docs/development/hacking_itk_wasm.md b/docs/development/hacking_itk_wasm.md index 99a9bd171..b0e9cf46a 100644 --- a/docs/development/hacking_itk_wasm.md +++ b/docs/development/hacking_itk_wasm.md @@ -36,21 +36,65 @@ ITK-Wasm's [C++ core](../introduction/parts.md#cxx-core) can be developed with n 2. Build the `WebAssemblyInterface` module from this module against ITK 3. Run the tests +We recommend using the scripts provided in [dev-utils](../../dev-utils/) folder +to [grab the source code](../../dev-utils/itk-wasm-native-get-source.sh) and run [native build commands](../../dev-utils/itk-wasm-native-build.sh). +Note that you will need to include certain CXX compiler flags for the native windows build as shown in the script. +The build script also demonstrates how to native build sub-packages such as @itk-wasm/dicom with additional ITK dependencies turned on. + From a command line, these steps in brief are: ```sh +# For Windows build (with mingw-bash or git-bash terminal) +export CXXFLAGS="/Zc:__cplusplus /DNOMINMAX" + # Build ITK -git clone https://github.com/InsightSoftwareConsortium/ITK -cmake -BITK-build -SITK -DBUILD_TESTING=OFF -DModule_MeshToPolyData=ON -cmake --build ITK-build +git clone https://github.com/InsightSoftwareConsortium/ITK --branch=itkwasm-main-mutable +# cmake -BITK-build -SITK -DBUILD_TESTING=OFF -DModule_MeshToPolyData=ON -DITK_MSVC_STATIC_RUNTIME_LIBRARY=ON +cmake -BITK-build -SITK \ + -DBUILD_TESTING=OFF \ + -DCMAKE_CXX_STANDARD:STRING=17 \ + -DCMAKE_BUILD_TYPE:STRING=Debug \ + -DCMAKE_CONFIGURATION_TYPES:STRING=Debug \ + -DBUILD_EXAMPLES:BOOL=OFF \ + -DBUILD_TESTING:BOOL=OFF \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_STATIC_LIBS=ON \ + -DDCMTK_LINK_STATIC=ON \ + -DITK_LEGACY_REMOVE:BOOL=ON \ + -DITK_BUILD_DEFAULT_MODULES:BOOL=ON \ + -DModule_MeshToPolyData=ON \ + -DDO_NOT_BUILD_ITK_TEST_DRIVER:BOOL=ON \ + -DOPJ_USE_THREAD:BOOL=OFF \ + -DDCMTK_WITH_THREADS:BOOL=OFF \ + -DDCMTK_BUILD_APPS:BOOL=OFF \ + -DNO_FLOAT_EXCEPTIONS:BOOL=ON \ + -DITK_MSVC_STATIC_RUNTIME_LIBRARY=ON +cmake --build ITK-build --config Debug -j16 # Build the WebAssemblyInterface module from this module against ITK git clone https://github.com/InsightSoftwareConsortium/ITK-Wasm -cmake -Bitk-wasm-build -Sitk-wasm -DBUILD_TESTING=ON -DITK_DIR=$PWD/ITK-build -cmake --build itk-wasm-build +cmake -BITK-Wasm-build \ + -SITK-Wasm \ + -DBUILD_TESTING=ON \ + -DCMAKE_CXX_STANDARD:STRING=20 \ + -DCMAKE_BUILD_TYPE:STRING=Debug \ + -DCMAKE_CONFIGURATION_TYPES:STRING=Debug \ + -DBUILD_SHARED_LIBS=OFF \ + -DITK_DIR=$PWD/ITK-build +cmake --build ITK-Wasm-build --config Debug -j16 # Run the tests ctest --test-dir itk-wasm-build + +cmake -Bpackages-dicom \ + -SITK-Wasm/packages/dicom \ + -DBUILD_TESTING=ON \ + -DCMAKE_CXX_STANDARD:STRING=20 \ + -DCMAKE_BUILD_TYPE:STRING=Debug \ + -DCMAKE_CONFIGURATION_TYPES:STRING=Debug \ + -DITK_DIR=$PWD/ITK-build + +cmake --build packages-dicom --config Debug -j16 ``` For additional guidance on C++ development, see the [ITK Software Guide].