OSDN Git Service

[BUILD][CMAKE][WIN32] Add support cross-build with CLANG-MinGW-w64.You may use with...
authorKyuma Ohta <whatisthis.sowhat@gmail.com>
Tue, 24 Sep 2019 09:58:32 +0000 (09:58 +0000)
committerKyuma Ohta <whatisthis.sowhat@gmail.com>
Tue, 24 Sep 2019 09:58:32 +0000 (09:58 +0000)
source/build-cmake/buildvars_mingw_cross_win32.dat.tmpl
source/build-cmake/cmake/i686-windows-mingw-clang.cmake [new file with mode: 0644]
source/build-cmake/cmake/toolchain_mingw_cross_linux.cmake
source/build-cmake/cmake/toolchain_win32_cross_linux_llvm.cmake
source/build-cmake/config_build_cross_win32.sh
source/build-cmake/params/archdef_arm32.dat
source/build-cmake/params/archdef_arm64.dat
source/build-cmake/params/archdef_ia32.dat
source/build-cmake/params/archdef_x86_64.dat
source/build-cmake/params/buildvars_mingw_params_llvm.dat

index 8231379..81306bc 100644 (file)
@@ -2,16 +2,21 @@
 ### BY GNU/Linux (and maybe other *nix like OSs) host to MinGW32 target.
 ### Please copy this to buildvars_mingw_cross_win32.dat and edit.
 #
+BUILD_TYPE="Release"
+
 #CMAKE=/usr/bin/cmake
 BUILD_TOOLCHAIN="GCC"
 #BUILD_TOOLCHAIN="LLVM"
 #BUILD_TOOLCHAIN="CUSTOM"
+CROSS_BUILD="Yes"
+
 ##
-#CUSTOM_BASE_PATH="/source code path/source/build-cmake/"
+
 ## If you choose "CUSTOM" as BUILD_TOOLCHAIN, edit and uncomment below.
 #CUSTOM_TOOLCHAIN_PATH=""
-
-BUILD_TYPE="Release"
+# If using custom toolchain, modify and uncomment below.
+#TOOLCHAIN_PREFIX="/path/to/custom/root/"
+#CUSTOM_BASE_PATH="/source code path/source/build-cmake/"
 
 # "No" or "Yes".
 CSP_DEBUG="NO"
@@ -58,5 +63,3 @@ MAKEFLAGS_BASE=""
 # Below sets make with affinity mask.Using excepts CPU CORE #1 and #7.
 #AFFINITY_MAKE="taskset 0xfbe make" 
 
-# If using custom toolchain, modify and uncomment below.
-#TOOLCHAIN_PREFIX="/path/to/custom/root/"
diff --git a/source/build-cmake/cmake/i686-windows-mingw-clang.cmake b/source/build-cmake/cmake/i686-windows-mingw-clang.cmake
new file mode 100644 (file)
index 0000000..dc36554
--- /dev/null
@@ -0,0 +1,28 @@
+# the name of the target operating system
+set(CMAKE_SYSTEM_NAME Windows)
+
+# Choose an appropriate compiler prefix
+set(CMAKE_TOOLCHAIN_PREFIX "i686-w64-mingw32")
+
+
+# which compilers to use for C and C++
+find_program(CMAKE_RC_COMPILER  NAMES ${CMAKE_TOOLCHAIN_PREFIX}-windres)
+find_program(CMAKE_C_COMPILER   NAMES ${CMAKE_TOOLCHAIN_PREFIX}-gcc)
+find_program(CMAKE_CXX_COMPILER NAMES ${CMAKE_TOOLCHAIN_PREFIX}-g++)
+find_program(CMAKE_ASM_COMPILER NAMES ${CMAKE_TOOLCHAIN_PREFIX}-as)
+
+set(CMAKE_C_COMPILER   "clang"   "-target ${CMAKE_TOOLCHAIN_PREFIX} -isystem /usr/${CMAKE_TOOLCHAIN_PREFIX}/include -isystem /usr/local/${CMAKE_TOOLCHAIN_PREFIX}/include")
+set(CMAKE_CXX_COMPILER "clang++" "-target ${CMAKE_TOOLCHAIN_PREFIX} -isystem /usr/${CMAKE_TOOLCHAIN_PREFIX}/include -isystem /usr/local/${CMAKE_TOOLCHAIN_PREFIX}/include")
+
+
+# here is the target environment located
+set(CMAKE_FIND_ROOT_PATH /usr/${CMAKE_TOOLCHAIN_PREFIX} /usr/local/${CMAKE_TOOLCHAIN_PREFIX})
+
+
+# adjust the default behaviour of the FIND_XXX() commands:
+# search headers and libraries in the target environment, search 
+# programs in the host environment
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_CROSS_COMPILING TRUE)
index 23c891d..583a1ba 100644 (file)
@@ -7,10 +7,6 @@ SET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
 SET(CMAKE_RC_COMPILER i686-w64-mingw32-windres)
 SET(CMAKE_AR  i686-w64-mingw32-gcc-ar)
 
-#SET(CMAKE_C_COMPILER i686-w64-mingw32-clang)
-#SET(CMAKE_CXX_COMPILER i686-w64-mingw32-clang++)
-#SET(CMAKE_RC_COMPILER i686-w64-mingw32-windres)
-#SET(CMAKE_AR  i686-w64-mingw32-gcc-ar)
 
 #set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
 #set(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++")
index 58cc5bc..ac53d76 100644 (file)
@@ -1,45 +1,70 @@
 # the name of the target operating system
 SET(CMAKE_SYSTEM_NAME Windows)
+SET(CSP_CROSS_BUILD 1)
+
+# Choose an appropriate compiler prefix
+set(CMAKE_TOOLCHAIN_PREFIX "i686-w64-mingw32")
 
 # which compilers to use for C and C++
 SET(CMAKE_SYSTEM_NAME Windows)
+
 SET(CMAKE_C_COMPILER i686-w64-mingw32-clang)
 SET(CMAKE_CXX_COMPILER i686-w64-mingw32-clang++)
 SET(CMAKE_RC_COMPILER i686-w64-mingw32-windres)
-SET(CMAKE_AR  llvm-ar)
-SET(CMAKE_LD  llvm-link)
-SET(CMAKE_LINKSE  /usr/bin/i686-w64-mingw32-ld)
-SET(CMAKE_NM  llvm-nm)
+SET(CMAKE_AR i686-w64-mingw32-ar)
+SET(CMAKE_C_COMPILER_AR  i686-w64-mingw32-ar)
+SET(CMAKE_CXX_COMPILER_AR  i686-w64-mingw32-ar)
+SET(CMAKE_LD  /usr/bin/i686-w64-mingw32-ld)
+#SET(CMAKE_LINKER  /usr/bin/i686-w64-mingw32-ld)
+#SET(CMAKE_EXE_LINKER  /usr/bin/i686-w64-mingw32-ld)
+#SET(CMAKE_SHARED_LINKER  /usr/bin/i686-w64-mingw32-ld)
+SET(CMAKE_NM  i686-w64-mingw32-nm)
+SET(CMAKE_RANLIB  i686-w64-mingw32-ranlib)
+SET(CMAKE_C_COMPILER_RANLIB  i686-w64-mingw32-ranlib)
+SET(CMAKE_CXX_COMPILER_RANLIB  i686-w64-mingw32-ranlib)
+
+#find_program(CMAKE_RC_COMPILER  NAMES ${CMAKE_TOOLCHAIN_PREFIX}-windres)
+#find_program(CMAKE_C_COMPILER   NAMES ${CMAKE_TOOLCHAIN_PREFIX}-clang)
+#find_program(CMAKE_CXX_COMPILER NAMES ${CMAKE_TOOLCHAIN_PREFIX}-clang++)
+#find_program(CMAKE_ASM_COMPILER NAMES ${CMAKE_TOOLCHAIN_PREFIX}-as)
+
+#set(CMAKE_C_COMPILER   "${CMAKE_TOOLCHAIN_PREFIX}-clang"   "-target ${CMAKE_TOOLCHAIN_PREFIX} -isystem /opt/llvm-mingw/${CMAKE_TOOLCHAIN_PREFIX}/include -isystem /usr/local/${CMAKE_TOOLCHAIN_PREFIX}/include")
+#set(CMAKE_CXX_COMPILER "${CMAKE_TOOLCHAIN_PREFIX}-clang++" "-target ${CMAKE_TOOLCHAIN_PREFIX} -isystem /opt/llvm-mingw/${CMAKE_TOOLCHAIN_PREFIX}/include -isystem /usr/local/${CMAKE_TOOLCHAIN_PREFIX}/include")
 
 set(CMAKE_CXX_FLAGS "-target i686-w64-mingw32")
+set(CMAKE_C_FLAGS "-target i686-w64-mingw32")
+#set(CMAKE_CXX_FLAGS "-target i686-w64-mingw32")
 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc -nostdinc++")
 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/lib/clang/3.9.0/include")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/i686-w64-mingw32/include/../../../usr/lib/gcc/i686-w64-mingw32/8.2-win32/include/c++")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/i686-w64-mingw32/include/../../../usr/lib/gcc/i686-w64-mingw32/8.2-win32/include/c++/i686-w64-mingw32")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/i686-w64-mingw32/include")
+#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/i686-w64-mingw32/include/../../../usr/lib/gcc/i686-w64-mingw32/8.2-win32/include/c++")
+#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/i686-w64-mingw32/include/../../../usr/lib/gcc/i686-w64-mingw32/8.2-win32/include/c++/i686-w64-mingw32")
+#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/i686-w64-mingw32/include")
 
-set(CMAKE_EXE_LINKER_FLAGS "-L/usr/lib/gcc/i686-w64-mingw32/8.2-win32 -target i686-w64-mingw32 ")
+set(CMAKE_EXE_LINKER_FLAGS "-L/usr/i686-w64-mingw32/lib -target i686-w64-mingw32 ")
+set(CMAKE_SHARED_LINKER_FLAGS "-L/usr/i686-w64-mingw32/lib -target i686-w64-mingw32 ")
 #set(CMAKE_EXE_LINKER_FLAGS "")
 
 set(LIBAV_ROOT_DIR "/usr/local/i586-mingw-msvc/ffmpeg-4.1")
 
 
 # here is the target environment located
+# here is the target environment located
+set(CMAKE_FIND_ROOT_PATH /usr/${CMAKE_TOOLCHAIN_PREFIX} /opt/llvm-mingw/${CMAKE_TOOLCHAIN_PREFIX})
+
 set(USE_SDL2 ON)
 if(USE_SDL2)
-   SET(CMAKE_FIND_ROOT_PATH  /usr/i686-w64-mingw32 
+   SET(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} /usr/i686-w64-mingw32 
                           /usr/local/i586-mingw-msvc
                           /usr/local/i586-mingw-msvc/SDL/i686-w64-mingw32
                          /usr/local/i586-mingw-msvc/5.12/mingw_82x
                          )
 else()
-   SET(CMAKE_FIND_ROOT_PATH  /usr/i686-w64-mingw32 
+   SET(CMAKE_FIND_ROOT_PATH  ${CMAKE_FIND_ROOT_PATH} /usr/i686-w64-mingw32 
                           /usr/local/i586-mingw-msvc
                           /usr/local/i586-mingw-msvc/SDL1/
                          /usr/local/i586-mingw-msvc/5.12/mingw_82x
                          )
 endif()
-SET(CSP_CROSS_BUILD 1)
 
 # adjust the default behaviour of the FIND_XXX() commands:
 # search headers and libraries in the target environment, search 
@@ -47,6 +72,7 @@ SET(CSP_CROSS_BUILD 1)
 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+#set(CMAKE_CROSS_COMPILING TRUE)
 
 
 set(SDL2_LIBRARIES
index 426ea07..0294f08 100755 (executable)
@@ -142,18 +142,20 @@ function build_dll() {
             "${CMAKE_FLAGS3}=${MAKEFLAGS_LIB_CC}" \
             "${CMAKE_FLAGS4}" \
             "-DUSE_SDL2=ON" \
-            ${CMAKE_APPENDFLAG} \
             "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_LINKFLAG}" \
+            ${CMAKE_APPENDFLAG} \
             "-DCMAKE_CROSSCOMPILING=true"\
        .. | tee make.log
     
-    ${CMAKE} ${CMAKE_FLAGS1} \
-            "${CMAKE_FLAGS2}=${MAKEFLAGS_LIB_CXX}" \
-            "${CMAKE_FLAGS3}=${MAKEFLAGS_LIB_CC}" \
-            "${CMAKE_FLAGS4}" \
-            "-DUSE_SDL2=ON" \
+#    ${CMAKE} ${CMAKE_FLAGS1} \
+#           "${CMAKE_FLAGS2}=${MAKEFLAGS_LIB_CXX}" \
+#           "${CMAKE_FLAGS3}=${MAKEFLAGS_LIB_CC}" \
+#           "${CMAKE_FLAGS4}" \
+#           "-DUSE_SDL2=ON" \
+#           "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_LINKFLAG}" \
             ${CMAKE_APPENDFLAG} \
-            "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_LINKFLAG}" \
+
+     ${CMAKE} \
             .. | tee -a make.log
     
     make clean
@@ -279,13 +281,7 @@ for SRCDATA in $@ ; do\
             ${CMAKE_APPENDFLAG} \
             .. | tee make.log
 
-    ${CMAKE} ${CMAKE_FLAGS1} \
-            "${CMAKE_FLAGS2}=${MAKEFLAGS_CXX}" \
-            "${CMAKE_FLAGS3}=${MAKEFLAGS_CC}" \
-            "${CMAKE_FLAGS4}" \
-            "-DUSE_SDL2=ON" \
-            "-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_LINKFLAG}" \
-            ${CMAKE_APPENDFLAG} \
+    ${CMAKE} \
             .. | tee -a make.log
 
     make clean
index 49f27a1..4991b95 100644 (file)
@@ -64,3 +64,4 @@ case ${LOCAL_ARCH_TYPE} in
 esac
 
 ARCH_FLAGS="${ARCH_FLAGS} ${APPEND_ARCH_FLAGS}"
+X_ARCH_PREFIX="armv7-"
\ No newline at end of file
index 0d0e049..aaad24f 100644 (file)
@@ -39,3 +39,4 @@ case ${LOCAL_ARCH_TYPE} in
 esac
 
 ARCH_FLAGS="${ARCH_FLAGS} ${APPEND_ARCH_FLAGS}"
+X_ARCH_PREFIX="aarch64-"
\ No newline at end of file
index 4a1193f..1d3afe1 100644 (file)
@@ -64,3 +64,4 @@ case ${LOCAL_ARCH_TYPE} in
 esac
 
 ARCH_FLAGS="${ARCH_FLAGS} ${APPEND_ARCH_FLAGS}"
+X_ARCH_PREFIX="i686-"
\ No newline at end of file
index 0c0c900..f74ccdd 100644 (file)
@@ -127,3 +127,4 @@ case ${LOCAL_ARCH_TYPE} in
 esac
 
 ARCH_FLAGS="${ARCH_FLAGS} ${APPEND_ARCH_FLAGS}"
+X_ARCH_PREFIX="x86_64-"
\ No newline at end of file
index c9e3797..567d908 100644 (file)
@@ -4,18 +4,7 @@
 # Neither for GCC and LLVM/Linux .
 #
 
-if [ -v CC_SUFFIX ] ; then
-   CCMAKE_CC=${CCMAKE_CC}-${CC_SUFFIX}
-   CCMAKE_CXX=${CCMAKE_CXX}-${CC_SUFFIX}
-fi
-if [ -v CC_PREFIX ] ; then
-   CCMAKE_CC=${CC_PREFIX}-${CCMAKE_CC}
-   CCMAKE_CXX=${CC_PREFIX}-${CCMAKE_CXX}
-fi
-if [ -v CC_PATH ] ; then
-   CCMAKE_CC=${CC_PATH}/${CCMAKE_CC}
-   CCMAKE_CXX=${CC_PATH}/${CCMAKE_CXX}
-fi
+MAKEFLAGS_BASE2="${MAKEFLAGS_BASE}"
 
 case ${MAJOR_ARCH} in
    "AMD64" | "amd64" | "x86_64" | "X86_64" )
@@ -29,34 +18,20 @@ case ${MAJOR_ARCH} in
    ;;
 esac
 
-case ${USE_RADICAL_OPTIMIZE} in
+case ${CSP_DEBUG} in
    "Yes" | "yes" | "YES" )
-      MAKEFLAGS_BASE3=" \
-               -O3 \
-               -fvect-cost-model=dynamic -ftree-vectorize \
-               -ftree-loop-distribute-patterns \
-              -ftree-loop-optimize -ftree-loop-if-convert-stores \
-              -fbranch-probabilities -fbranch-target-load-optimize \
-              -fselective-scheduling -fsel-sched-pipelining -fsel-sched-pipelining-outer-loops \
-              -funroll-loops \
-              -fgraphite-identity \
-              -floop-nest-optimize \
-              ${ARCH_FLAGS} \
-              -Wall \
-               ${MAKEFLAGS_BASE} \
-              "
-              ;;
+         MAKEFLAGS_BASE2="-g -ggdb ${MAKEFLAGS_BASE} -DNDEBUG"
+         MAKEFLAGS_LINK_BASE="-g -ggdb ${MAKEFLAGS_BASE}"
+         ;;
    "No" | "no" | "NO" | * )
-      MAKEFLAGS_BASE3=" \
-               -O2 \
-              \
-              -ftree-vectorize \
-              -funroll-loops \
-              ${ARCH_FLAGS} \
-              -Wall \
-               ${MAKEFLAGS_BASE} \
-              "
-              ;;
+         MAKEFLAGS_BASE2="-O3 ${MAKEFLAGS_BASE} -DNDEBUG \
+                                                 -std=c++0x \
+                                                 -Wreserved-user-defined-literal \
+                                                 -D_HAS_EXCEPTIONS \
+                                                 -D__float128=\"long double\"
+                                                 "
+         MAKEFLAGS_LINK_BASE="-s ${MAKEFLAGS_BASE}"
+         ;;
 esac
 
 case ${USE_WHOLE_PROGRAM_OPTIMIZE} in
@@ -67,6 +42,7 @@ case ${USE_WHOLE_PROGRAM_OPTIMIZE} in
       LTO_FLAGS=""
       ;;
 esac
+
 case ${USE_SANITIZER} in
    "Yes" | "yes" | "YES" )
       MAKEFLAGS_BASE3="${MAKEFLAGS_BASE3} \
@@ -113,26 +89,10 @@ case ${COMPRESS_SYMBOLS} in
    ;;
 esac
 
-case ${CSP_DEBUG} in
-   "Yes" | "yes" | "YES" )
-         MAKEFLAGS_BASE2="-g -ggdb ${MAKEFLAGS_BASE} -DNDEBUG"
-         MAKEFLAGS_LINK_BASE="-g -ggdb ${MAKEFLAGS_BASE}"
-         ;;
-   "No" | "no" | "NO" | * )
-         MAKEFLAGS_BASE2="-O3 ${MAKEFLAGS_BASE} -DNDEBUG \
-                                                 -std=c++0x \
-                                                 -Wreserved-user-defined-literal \
-                                                 -D_HAS_EXCEPTIONS \
-                                                 -D__float128=\"long double\"
-                                                 "
-         MAKEFLAGS_LINK_BASE="-s ${MAKEFLAGS_BASE}"
-         ;;
-esac
-
 case ${USE_LTO} in
    "Yes" | "yes" | "YES" )
        MAKEFLAGS_LINK_BASE2="-flto=${LTO_THREADS} ${LTO_FLAGS} ${MAKEFLAGS_BASE2}"
-       MAKEFLAGS_BASE2="-flto -ffat-lto-objects ${MAKEFLAGS_BASE2}"
+       MAKEFLAGS_BASE2="-flto ${MAKEFLAGS_BASE2}"
        ;;
    "No" | "no" | "NO" | * )
        MAKEFLAGS_LINK_BASE2="${MAKEFLAGS_BASE2}"
@@ -148,10 +108,25 @@ case ${USE_OPENMP} in
    ;;
 esac
 
+case ${CROSS_BUILD} in
+    "Yes" | "YES" | "yes" | "1" )
+        X_LDFLAGS=" \
+       -DCMAKE_EXE_LINKER_FLAGS:STRING=-L/usr/${X_ARCH_PREFIX}w64-mingw32/lib \
+       -DCMAKE_SHARED_LINKER_FLAGS:STRING=-L/usr/${X_ARCH_PREFIX}w64-mingw32/lib \
+       -DCMAKE_LINKER:STRING=/usr/bin/${X_ARCH_PREFIX}w64-mingw32-ld \
+        "
+
+       ;;
+     * )
+        X_LDFLAGS=""
+       ;;
+esac
+
 CMAKE_APPENDFLAG="-DUSE_QT5_4_APIS=ON -DUSE_MOVIE_LOADER=ON \
                    -DUSE_MOVIE_SAVER=ON \
-                   -DCMAKE_AR:STRING=llvm-ar \
-                   -DCMAKE_LD:STRING=i686-w64-mingw32-ld \
-                  -DCMAKE_NM:STRING=llvm-nm \
-                  -DCMAKE_RANLIB:STRING=llvm-ranlib \
+                   -DCMAKE_AR:STRING=i686-w64-mingw32-ar \
+                  -DCMAKE_NM:STRING=i686-w64-mingw32-nm \
+                  -DCMAKE_RANLIB:STRING=i686-w64-mingw32-ranlib \
+                  ${X_LDFLAGS} \
                   "
+#                   -DCMAKE_LD:STRING=i686-w64-mingw32-ld \