diff --git a/README.md b/README.md index 5753e606..c249d8ae 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,9 @@ TinyUSDZ is currently in alpha stage. Not usable. * C++11 compiler * [x] gcc 4.8.5(CentOS 7 default) or later * [x] Visual Studio 2017 or later(2015 may OK) + * [x] Can be compiled with standalone MSVC compilers(Build Tools for Visual Studio 2017) * [x] clang 3.8 or later + * [x] llvm-ming(clang) supported ## USDZ file format @@ -67,6 +69,17 @@ $ cmake .. $ make ``` +#### LLVM-MinGW build + +MinGW native and cross-compiling example using llvm-mingw(clang) is provided. +See `scripts/bootstrap-cmake-mingw-win.sh` and `scripts/bootstrap-cmake-llvm-mingw-cross.sh` for details. + +One of benefit to use llvm-mingw is address sanitizer support on Windows app. + +To run app(`.exe`, you'll need `libunwind.dll` and `libc++.dll` on your working directory or search path) + +For Windows native build, we assume `ninja.exe` is installed on your system(You can use it from Meson package) + #### CMake build options * `TINYUSDZ_BUILD_TESTS` : Build tests diff --git a/cmake/llvm-mingw-cross.cmake b/cmake/llvm-mingw-cross.cmake new file mode 100644 index 00000000..f7e1759c --- /dev/null +++ b/cmake/llvm-mingw-cross.cmake @@ -0,0 +1,24 @@ +SET(CMAKE_SYSTEM_NAME Windows) + +IF (DEFINED ENV{LLVM_MINGW_DIR}) + SET(LLVM_MINGW_ROOT "$ENV{LLVM_MINGW_DIR}") +ELSE () + SET(LLVM_MINGW_ROOT "/mnt/data/local/llvm-mingw-20200325-ubuntu-18.04") +ENDIF() + + +SET(CMAKE_C_COMPILER ${LLVM_MINGW_ROOT}/bin/x86_64-w64-mingw32-clang) +SET(CMAKE_CXX_COMPILER ${LLVM_MINGW_ROOT}/bin/x86_64-w64-mingw32-clang++) +SET(CMAKE_RC_COMPILER ${LLVM_MINGW_ROOT}/bin/x86_64-w64-mingw32-windres) + +#SET(CMAKE_C_LINK_EXECUTABLE x86_64-w64-mingw32-gcc) +#SET(CMAKE_CXX_LINK_EXECUTABLE x86_64-w64-mingw32-g++) + +SET(CMAKE_FIND_ROOT_PATH ${LLVM_MINGW_ROOT}/x86_64-w64-mingw32) + +# We may need some advanced thread APIs to compile, so enable 0x601(Win7) if required. +# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x601") + +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/llvm-mingw-win64.cmake b/cmake/llvm-mingw-win64.cmake new file mode 100644 index 00000000..439b5240 --- /dev/null +++ b/cmake/llvm-mingw-win64.cmake @@ -0,0 +1,20 @@ +SET(CMAKE_SYSTEM_NAME Windows) + +IF (DEFINED ENV{LLVM_MINGW_DIR}) + SET(LLVM_MINGW_ROOT "$ENV{LLVM_MINGW_DIR}") +ELSE () + SET(LLVM_MINGW_ROOT "C:/ProgramData/llvm-mingw") +ENDIF() + +SET(CMAKE_C_COMPILER ${LLVM_MINGW_ROOT}/bin/x86_64-w64-mingw32-clang.exe) +SET(CMAKE_CXX_COMPILER ${LLVM_MINGW_ROOT}/bin/x86_64-w64-mingw32-clang++.exe) +SET(CMAKE_RC_COMPILER ${LLVM_MINGW_ROOT}/bin/x86_64-w64-mingw32-windres.exe) + +SET(CMAKE_FIND_ROOT_PATH ${LLVM_MINGW_ROOT}/x86_64-w64-mingw32) + +# We may need some advanced thread APIs to compile tinyusz. use 0x601(Win7) if required +# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x601") + +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/mingw64-cross.cmake b/cmake/mingw64-cross.cmake new file mode 100644 index 00000000..479cdd4d --- /dev/null +++ b/cmake/mingw64-cross.cmake @@ -0,0 +1,20 @@ +SET(CMAKE_SYSTEM_NAME Windows) + +IF (DEFINED ENV{MINGW_GCC_DIR}) + SET(MINGW_GCC_ROOT "$ENV{MINGW_GCC_DIR}") +ELSE () + # Assume mingw cross compiler is installed in your system + SET(MINGW_GCC_ROOT "/usr") +ENDIF() + +# win32 may fail to compile with C++11 threads. + +SET(CMAKE_C_COMPILER ${MINGW_GCC_ROOT}/bin/x86_64-w64-mingw32-gcc-posix) +SET(CMAKE_CXX_COMPILER ${MINGW_GCC_ROOT}/bin/x86_64-w64-mingw32-g++-posix) +SET(CMAKE_RC_COMPILER ${MINGW_GCC_ROOT}/bin/x86_64-w64-mingw32-windres) + +SET(CMAKE_FIND_ROOT_PATH ${MINGW_GCC_ROOT}/x86_64-w64-mingw32) + +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/scripts/bootstrap-cmake-llvm-mingw-cross.sh b/scripts/bootstrap-cmake-llvm-mingw-cross.sh new file mode 100755 index 00000000..d9a7c873 --- /dev/null +++ b/scripts/bootstrap-cmake-llvm-mingw-cross.sh @@ -0,0 +1,19 @@ +# llvm-mingw cross compile +# Assume Ninja is installed on your system +curdir=`pwd` + +# Set path to llvm-mingw in env var. +export LLVM_MINGW_DIR=/mnt/data/local/llvm-mingw-20200325-ubuntu-18.04/ + +builddir=${curdir}/build-llvm-mingw + +rm -rf ${builddir} +mkdir ${builddir} + +cd ${builddir} && cmake \ + -DCMAKE_TOOLCHAIN_FILE=${curdir}/cmake/llvm-mingw-cross.cmake \ + -G "Ninja" \ + -DCMAKE_VERBOSE_MAKEFILE=1 \ + .. + +cd ${curdir} diff --git a/scripts/bootstrap-cmake-mingw-win.sh b/scripts/bootstrap-cmake-llvm-mingw-win.sh old mode 100644 new mode 100755 similarity index 51% rename from scripts/bootstrap-cmake-mingw-win.sh rename to scripts/bootstrap-cmake-llvm-mingw-win.sh index 144ae138..6c68818f --- a/scripts/bootstrap-cmake-mingw-win.sh +++ b/scripts/bootstrap-cmake-llvm-mingw-win.sh @@ -2,15 +2,17 @@ # Assume Ninja is installed on your system curdir=`pwd` -builddir=${curdir}/build +# Set path to llvm-mingw in env var. +set LLVM_MINGW_DIR=/d/local/llvm-mingw-20200325-ubuntu-18.04/ + +builddir=${curdir}/build-llvm-mingw rm -rf ${builddir} mkdir ${builddir} -# Change the path to llvm-mingw to fit into your system. cd ${builddir} && cmake \ + -DCMAKE_TOOLCHAIN_FILE=${curdir}/cmake/llvm-mingw-win64.cmake \ -G "Ninja" \ - -DCMAKE_CXX_COMPILER=/d/local/llvm-mingw/bin/x86_64-w64-mingw32-g++.exe \ -DCMAKE_VERBOSE_MAKEFILE=1 \ .. diff --git a/scripts/bootstrap-cmake-mingw-gcc-cross.sh b/scripts/bootstrap-cmake-mingw-gcc-cross.sh new file mode 100755 index 00000000..8e4b0078 --- /dev/null +++ b/scripts/bootstrap-cmake-mingw-gcc-cross.sh @@ -0,0 +1,17 @@ +# mingw gcc cross compile +curdir=`pwd` + +# Set path to mingw in env var(if required). +export MINGW_GCC_DIR=/usr + +builddir=${curdir}/build-mingw + +rm -rf ${builddir} +mkdir ${builddir} + +cd ${builddir} && cmake \ + -DCMAKE_TOOLCHAIN_FILE=${curdir}/cmake/mingw64-cross.cmake \ + -DCMAKE_VERBOSE_MAKEFILE=1 \ + .. + +cd ${curdir}