forked from verilog-to-routing/vtr-verilog-to-routing
-
Notifications
You must be signed in to change notification settings - Fork 12
/
mingw-linux-cross-compile-to-windows.cmake
61 lines (51 loc) · 2.68 KB
/
mingw-linux-cross-compile-to-windows.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)
option(STATIC_LIBGCC_LIBSTDCPP "Link to libgcc and libstdc++ statically. If not set, requires libgcc and libstdc++ DLLs to be installed on the target machines. Note that static linking libgcc means exceptions will not propagate accross shared library boundaries." OFF)
#Note that if libgcc and libstdcpp are NOT statically linked the appropriate
#DLL's should be installed on the target Windows machine, or distributed with
#the generated executables (e.g. in the same directory as the exectuable).
#
#They are usually installed under:
# /usr/lib/gcc/${COMPILER_PEFIX}/*-win32/libgcc*.dll
# /usr/lib/gcc/${COMPILER_PEFIX}/*-win32/libstdc++*.dll
#
#For example targetting x86_64 with MingW based on gcc 5.3
# /usr/lib/gcc/x86_64-w64-mingw32/5.3-win32/libstdc++*.dll
# /usr/lib/gcc/x86_64-w64-mingw32/5.3-win32/libgcc*.dll
#
# Choose an appropriate compiler prefix
#
# for classical mingw32 (http://www.mingw.org/) set:
# "i586-mingw32msvc"
#
# for 32 or 64 bit mingw-w64 (http://mingw-w64.sourceforge.net/) set:
# "i686-w64-mingw32" or "x86_64-w64-mingw32"
set(COMPILER_PREFIX "x86_64-w64-mingw32" CACHE STRING "Default prefix for MinGW gcc/g++/windres")
set(MINGW_ROOT_PATH /usr/${COMPILER_PREFIX} CACHE STRING "MinGW path to target environment directory (containing include and lib)")
set(MINGW_RC ${COMPILER_PREFIX}-windres CACHE STRING "MinGW RC Compiler")
set(MINGW_CC ${COMPILER_PREFIX}-gcc CACHE STRING "MinGW C Compiler")
set(MINGW_CXX ${COMPILER_PREFIX}-g++ CACHE STRING "MinGW C++ Compiler")
# which compilers to use for C and C++
find_program(CMAKE_RC_COMPILER NAMES ${MINGW_RC})
find_program(CMAKE_C_COMPILER NAMES ${MINGW_CC})
find_program(CMAKE_CXX_COMPILER NAMES ${MINGW_CXX})
#
# Set the target environment location
#
SET(CMAKE_FIND_ROOT_PATH ${MINGW_ROOT_PATH})
# 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)
#The mingw-w64 headers and ABC's pthread.h have conflicting definitions of struct timespec.
#Adding this define suppresses the duplicate definition in ABC's pthread.h
add_definitions(-DHAVE_STRUCT_TIMESPEC=1)
#This forces ABC to use the stdint types (e.g. ptrdiff_t) instead of its platform
#dependant type look-up. This avoids 'unkown platform' compilation errors.
add_definitions(-DABC_USE_STDINT_H=1)
if (STATIC_LIBGCC_LIBSTDCPP)
#Statically link to libgcc and libstdc++ to avoid DLL dependencies
link_libraries(-static-libgcc -static-libstdc++)
endif()