xref: /reactos/toolchain-gcc.cmake (revision 3c5a56ed)
1
2macro(require_program varname execname)
3    find_program(${varname} ${execname})
4    if(NOT ${varname})
5        message(FATAL_ERROR "${execname} not found")
6    endif()
7endmacro()
8
9# pass variables necessary for the toolchain (needed for try_compile)
10set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH)
11
12# Choose the right MinGW toolchain prefix
13if(NOT DEFINED MINGW_TOOLCHAIN_PREFIX)
14    if(ARCH STREQUAL "i386")
15
16        if(CMAKE_HOST_WIN32)
17            set(MINGW_TOOLCHAIN_PREFIX "" CACHE STRING "MinGW Toolchain Prefix")
18        else()
19            set(MINGW_TOOLCHAIN_PREFIX "i686-w64-mingw32-" CACHE STRING "MinGW-W64 Toolchain Prefix")
20        endif()
21
22    elseif(ARCH STREQUAL "amd64")
23        set(MINGW_TOOLCHAIN_PREFIX "x86_64-w64-mingw32-" CACHE STRING "MinGW Toolchain Prefix")
24    elseif(ARCH STREQUAL "arm")
25        set(MINGW_TOOLCHAIN_PREFIX "arm-mingw32ce-" CACHE STRING "MinGW Toolchain Prefix")
26    endif()
27endif()
28
29if(NOT DEFINED MINGW_TOOLCHAIN_SUFFIX)
30    set(MINGW_TOOLCHAIN_SUFFIX "" CACHE STRING "MinGW Toolchain Suffix")
31endif()
32
33# The name of the target operating system
34set(CMAKE_SYSTEM_NAME Windows)
35set(CMAKE_SYSTEM_PROCESSOR i686)
36
37# Which tools to use
38require_program(CMAKE_C_COMPILER ${MINGW_TOOLCHAIN_PREFIX}gcc${MINGW_TOOLCHAIN_SUFFIX})
39require_program(CMAKE_CXX_COMPILER ${MINGW_TOOLCHAIN_PREFIX}g++${MINGW_TOOLCHAIN_SUFFIX})
40require_program(CMAKE_ASM_COMPILER ${MINGW_TOOLCHAIN_PREFIX}gcc${MINGW_TOOLCHAIN_SUFFIX})
41set(CMAKE_ASM_COMPILER_ID "GNU")
42require_program(CMAKE_MC_COMPILER ${MINGW_TOOLCHAIN_PREFIX}windmc)
43require_program(CMAKE_RC_COMPILER ${MINGW_TOOLCHAIN_PREFIX}windres)
44require_program(CMAKE_DLLTOOL ${MINGW_TOOLCHAIN_PREFIX}dlltool)
45#set(CMAKE_AR ${MINGW_TOOLCHAIN_PREFIX}gcc-ar${MINGW_TOOLCHAIN_SUFFIX})
46require_program(CMAKE_OBJCOPY ${MINGW_TOOLCHAIN_PREFIX}objcopy)
47
48set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> crT <TARGET> <LINK_FLAGS> <OBJECTS>")
49set(CMAKE_CXX_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY})
50set(CMAKE_ASM_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY})
51
52# Don't link with anything by default unless we say so
53set(CMAKE_C_STANDARD_LIBRARIES "-lgcc" CACHE STRING "Standard C Libraries")
54
55#MARK_AS_ADVANCED(CLEAR CMAKE_CXX_STANDARD_LIBRARIES)
56set(CMAKE_CXX_STANDARD_LIBRARIES "-lgcc" CACHE STRING "Standard C++ Libraries")
57
58# This allows to have CMake test the compiler without linking
59set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
60
61set(CMAKE_SHARED_LINKER_FLAGS_INIT "-nostdlib -Wl,--enable-auto-image-base,--disable-auto-import")
62set(CMAKE_MODULE_LINKER_FLAGS_INIT "-nostdlib -Wl,--enable-auto-image-base,--disable-auto-import")
63set(CMAKE_EXE_LINKER_FLAGS_INIT "-nostdlib -Wl,--enable-auto-image-base,--disable-auto-import")
64
65set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_CURRENT_LIST_DIR}/overrides-gcc.cmake")
66
67# Get GCC version
68execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
69