Skip to content

Commit

Permalink
Force VS2019 as CMake generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackhex committed Jun 21, 2023
1 parent 5178a2e commit 5852757
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .github/scripts/cmake.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake .. -DTorch_DIR="%1"^
-DWITH_CUDA=%2^
-DCMAKE_PREFIX_PATH="%CONDA_PREFIX%"^
-DCMAKE_FIND_FRAMEWORK=NEVER^
-DCMAKE_INSTALL_PREFIX="%CONDA_PREFIX%"
40 changes: 24 additions & 16 deletions .github/scripts/cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fi
TORCH_PATH=$(python -c "import pathlib, torch; print(pathlib.Path(torch.__path__[0]))")
if [[ $OS_TYPE == windows ]]; then
PACKAGING_DIR="${PWD}/packaging"
SCRIPTS_DIR=${PWD}/.github/scripts
export PATH="${TORCH_PATH}/lib:${PATH}"
fi

Expand Down Expand Up @@ -65,19 +66,22 @@ echo '::endgroup::'
echo '::group::Build and install libtorchvision'
pushd cpp_build

# On macOS, CMake is looking for the library (*.dylib) and the header (*.h) separately. By default, it prefers to load
# the header from other packages that install the library. This easily leads to a mismatch if the library installed
# from conda doesn't have the exact same version. Thus, we need to explicitly set CMAKE_FIND_FRAMEWORK=NEVER to force
# it to not load anything from other installed frameworks. Resources:
# https://stackoverflow.com/questions/36523911/osx-homebrew-cmake-libpng-version-mismatch-issue
# https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_FRAMEWORK.html
cmake .. -DTorch_DIR="${Torch_DIR}" -DWITH_CUDA="${WITH_CUDA}" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCMAKE_FIND_FRAMEWORK=NEVER \
-DCMAKE_INSTALL_PREFIX="${CONDA_PREFIX}"
if [[ $OS_TYPE == windows ]]; then
"${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${SCRIPTS_DIR}/cmake.bat" $Torch_DIR $WITH_CUDA
"${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${PACKAGING_DIR}/windows/internal/build_cmake.bat" $JOBS
else
# On macOS, CMake is looking for the library (*.dylib) and the header (*.h) separately. By default, it prefers to load
# the header from other packages that install the library. This easily leads to a mismatch if the library installed
# from conda doesn't have the exact same version. Thus, we need to explicitly set CMAKE_FIND_FRAMEWORK=NEVER to force
# it to not load anything from other installed frameworks. Resources:
# https://stackoverflow.com/questions/36523911/osx-homebrew-cmake-libpng-version-mismatch-issue
# https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_FRAMEWORK.html
cmake .. -DTorch_DIR="${Torch_DIR}" \
-DWITH_CUDA="${WITH_CUDA}" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCMAKE_FIND_FRAMEWORK=NEVER \
-DCMAKE_INSTALL_PREFIX="${CONDA_PREFIX}"

make -j$JOBS
make install
fi
Expand All @@ -88,14 +92,16 @@ echo '::endgroup::'
echo '::group::Build and run project that uses Faster-RCNN'
pushd test/tracing/frcnn/build

cmake .. -DTorch_DIR="${Torch_DIR}" -DWITH_CUDA="${WITH_CUDA}" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCMAKE_FIND_FRAMEWORK=NEVER
if [[ $OS_TYPE == windows ]]; then
"${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${SCRIPTS_DIR}/cmake.bat" $Torch_DIR $WITH_CUDA
"${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${PACKAGING_DIR}/windows/internal/build_frcnn.bat" $JOBS
cd Release
cp ../fasterrcnn_resnet50_fpn.pt .
else
cmake .. -DTorch_DIR="${Torch_DIR}" -DWITH_CUDA="${WITH_CUDA}" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCMAKE_FIND_FRAMEWORK=NEVER

make -j$JOBS
fi

Expand All @@ -107,14 +113,16 @@ echo '::endgroup::'
echo '::group::Build and run C++ example'
pushd examples/cpp/hello_world/build

cmake .. -DTorch_DIR="${Torch_DIR}" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCMAKE_FIND_FRAMEWORK=NEVER
if [[ $OS_TYPE == windows ]]; then
"${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${SCRIPTS_DIR}/cmake.bat" $Torch_DIR $WITH_CUDA
"${PACKAGING_DIR}/windows/internal/vc_env_helper.bat" "${PACKAGING_DIR}/windows/internal/build_cpp_example.bat" $JOBS
cd Release
cp ../resnet18.pt .
else
cmake .. -DTorch_DIR="${Torch_DIR}" \
-DCMAKE_PREFIX_PATH="${CONDA_PREFIX}" \
-DCMAKE_FIND_FRAMEWORK=NEVER

make -j$JOBS
fi

Expand Down

0 comments on commit 5852757

Please sign in to comment.