Add llvm mingw for pdb generation

It uses visual studio dependencies
This commit is contained in:
Benau 2020-04-11 16:25:58 +08:00
parent 9157fb43f0
commit 359e2ff84f
5 changed files with 93 additions and 20 deletions

View File

@ -3,6 +3,13 @@ cmake_minimum_required(VERSION 2.8.4)
# root CMakeLists for the SuperTuxKart project # root CMakeLists for the SuperTuxKart project
project(SuperTuxKart) project(SuperTuxKart)
set(PROJECT_VERSION "git") set(PROJECT_VERSION "git")
if (MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(LLVM_MINGW TRUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gcodeview")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gcodeview")
endif()
add_definitions( -DSUPERTUXKART_VERSION="${PROJECT_VERSION}" ) add_definitions( -DSUPERTUXKART_VERSION="${PROJECT_VERSION}" )
if(NOT (CMAKE_MAJOR_VERSION VERSION_LESS 3)) if(NOT (CMAKE_MAJOR_VERSION VERSION_LESS 3))
@ -103,7 +110,7 @@ set(STK_INSTALL_DATA_DIR "share/supertuxkart" CACHE
STRING "Install data folder to this directory, absolute or relative to CMAKE_INSTALL_PREFIX") STRING "Install data folder to this directory, absolute or relative to CMAKE_INSTALL_PREFIX")
# Define dependencies path # Define dependencies path
if(MSVC) if (MSVC OR LLVM_MINGW)
set(DEPENDENCIES "dependencies-vs") set(DEPENDENCIES "dependencies-vs")
elseif(MINGW) elseif(MINGW)
set(DEPENDENCIES "dependencies-mingw") set(DEPENDENCIES "dependencies-mingw")
@ -444,6 +451,10 @@ if(MINGW AND CMAKE_BUILD_TYPE MATCHES Release)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--subsystem,windows") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--subsystem,windows")
endif() endif()
if (LLVM_MINGW)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-pdb=supertuxkart.pdb")
endif()
if(WIN32) if(WIN32)
# By default windows.h has macros defined for min and max that screw up everything # By default windows.h has macros defined for min and max that screw up everything
add_definitions(-DNOMINMAX) add_definitions(-DNOMINMAX)
@ -512,13 +523,10 @@ if(APPLE AND NOT IOS)
COMMAND ln -f -s ${PROJECT_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/bin/supertuxkart.app/Contents/Resources) COMMAND ln -f -s ${PROJECT_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/bin/supertuxkart.app/Contents/Resources)
endif() endif()
else() else()
if(MSVC) if (NOT WIN32)
set(PTHREAD_NAMES pthreadVC2) find_library(PTHREAD_LIBRARY NAMES pthread ${PTHREAD_NAMES} PATHS ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib)
elseif(MINGW) mark_as_advanced(PTHREAD_LIBRARY)
set(PTHREAD_NAMES "winpthread-1" "libwinpthread-1" "pthreadGC2")
endif() endif()
find_library(PTHREAD_LIBRARY NAMES pthread ${PTHREAD_NAMES} PATHS ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib)
mark_as_advanced(PTHREAD_LIBRARY)
# Set data dir (absolute or relative to CMAKE_INSTALL_PREFIX) # Set data dir (absolute or relative to CMAKE_INSTALL_PREFIX)
if(NOT STK_INSTALL_DATA_DIR_ABSOLUTE) if(NOT STK_INSTALL_DATA_DIR_ABSOLUTE)
@ -546,7 +554,9 @@ else()
else() else()
add_executable(supertuxkart ${STK_SOURCES} ${STK_RESOURCES} ${STK_HEADERS}) add_executable(supertuxkart ${STK_SOURCES} ${STK_RESOURCES} ${STK_HEADERS})
endif() endif()
target_link_libraries(supertuxkart ${PTHREAD_LIBRARY}) if (NOT WIN32)
target_link_libraries(supertuxkart ${PTHREAD_LIBRARY})
endif()
endif() endif()
# check if linking against libatomic is required # check if linking against libatomic is required
@ -567,7 +577,7 @@ endif()
# CURL and OpenSSL or Nettle # CURL and OpenSSL or Nettle
# 1.0.1d for compatible AES GCM handling # 1.0.1d for compatible AES GCM handling
SET(OPENSSL_MINIMUM_VERSION "1.0.1d") SET(OPENSSL_MINIMUM_VERSION "1.0.1d")
if(MSVC) if (MSVC OR LLVM_MINGW)
set(USE_CRYPTO_OPENSSL ON) set(USE_CRYPTO_OPENSSL ON)
target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/libcurl.lib) target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/libcurl.lib)
target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/libeay32.lib) target_link_libraries(supertuxkart ${PROJECT_SOURCE_DIR}/${DEPENDENCIES}/lib/libeay32.lib)
@ -707,17 +717,28 @@ if(MINGW)
if (NOT CMAKE_BUILD_TYPE MATCHES Debug) if (NOT CMAKE_BUILD_TYPE MATCHES Debug)
target_link_libraries(supertuxkart -mwindows) target_link_libraries(supertuxkart -mwindows)
endif() endif()
find_library(LIBGCC NAMES "libgcc_s_dw2-1.dll" "libgcc_s_sjlj-1.dll" "libgcc_s_seh-1.dll" PATHS ${CMAKE_FIND_ROOT_PATH}) if (LLVM_MINGW)
if(LIBGCC) find_library(LIBCPP NAMES "libc++.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
file(COPY ${LIBGCC} DESTINATION ${CMAKE_BINARY_DIR}/bin/) if (LIBCPP)
endif() file(COPY ${LIBCPP} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
find_library(LIBSTDCPP NAMES "libstdc++-6.dll" PATHS ${CMAKE_FIND_ROOT_PATH}) endif()
if(LIBSTDCPP) find_library(LIBUNWIND NAMES "libunwind.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
file(COPY ${LIBSTDCPP} DESTINATION ${CMAKE_BINARY_DIR}/bin/) if (LIBUNWIND)
endif() file(COPY ${LIBUNWIND} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
find_library(LIBPTHREAD NAMES "winpthread-1.dll" "libwinpthread-1.dll" "pthreadGC2.dll" PATHS ${CMAKE_FIND_ROOT_PATH}) endif()
if(LIBPTHREAD) else()
file(COPY ${LIBPTHREAD} DESTINATION ${CMAKE_BINARY_DIR}/bin/) find_library(LIBGCC NAMES "libgcc_s_dw2-1.dll" "libgcc_s_sjlj-1.dll" "libgcc_s_seh-1.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
if (LIBGCC)
file(COPY ${LIBGCC} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
endif()
find_library(LIBSTDCPP NAMES "libstdc++-6.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
if (LIBSTDCPP)
file(COPY ${LIBSTDCPP} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
endif()
find_library(LIBPTHREAD NAMES "winpthread-1.dll" "libwinpthread-1.dll" "pthreadGC2.dll" PATHS ${CMAKE_FIND_ROOT_PATH})
if(LIBPTHREAD)
file(COPY ${LIBPTHREAD} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
endif()
endif() endif()
endif() endif()
@ -767,3 +788,8 @@ if(MINGW)
install(DIRECTORY ${CMAKE_BINARY_DIR}/bin/ DESTINATION ${STK_INSTALL_BINARY_DIR} install(DIRECTORY ${CMAKE_BINARY_DIR}/bin/ DESTINATION ${STK_INSTALL_BINARY_DIR}
FILES_MATCHING PATTERN "*.dll") FILES_MATCHING PATTERN "*.dll")
endif() endif()
if (LLVM_MINGW)
set(COPY_PDB_CMD cp ${CMAKE_BINARY_DIR}/supertuxkart.pdb ${CMAKE_BINARY_DIR}/bin)
add_custom_command(TARGET supertuxkart POST_BUILD COMMAND ${COPY_PDB_CMD})
endif()

View File

@ -0,0 +1,20 @@
# Usage:
# cmake .. -DLLVM_PREFIX=/path/to/llvm-mingw-prefix -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-llvm-mingw-64bit.cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER ${LLVM_PREFIX}/bin/x86_64-w64-mingw32-clang)
SET(CMAKE_CXX_COMPILER ${LLVM_PREFIX}/bin/x86_64-w64-mingw32-clang++)
SET(CMAKE_RC_COMPILER ${LLVM_PREFIX}/bin/x86_64-w64-mingw32-windres)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH ${LLVM_PREFIX}/generic-w64-mingw32 ${LLVM_PREFIX}/x86_64-w64-mingw32/bin ${PROJECT_SOURCE_DIR}/dependencies-vs-64bit)
# 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 ALWAYS)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View File

@ -0,0 +1,20 @@
# Usage:
# cmake .. -DLLVM_PREFIX=/path/to/llvm-mingw-prefix -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-llvm-mingw.cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER ${LLVM_PREFIX}/bin/i686-w64-mingw32-clang)
SET(CMAKE_CXX_COMPILER ${LLVM_PREFIX}/bin/i686-w64-mingw32-clang++)
SET(CMAKE_RC_COMPILER ${LLVM_PREFIX}/bin/i686-w64-mingw32-windres)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH ${LLVM_PREFIX}/generic-w64-mingw32 ${LLVM_PREFIX}/i686-w64-mingw32/bin ${PROJECT_SOURCE_DIR}/dependencies-vs)
# 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 ALWAYS)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View File

@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 2.6)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
cmake_policy(SET CMP0003 NEW) cmake_policy(SET CMP0003 NEW)
# Fix llvm mingw crashes
if (MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
ADD_DEFINITIONS(-DAS_MAX_PORTABILITY)
endif()
if(NOT (CMAKE_MAJOR_VERSION VERSION_LESS 3)) if(NOT (CMAKE_MAJOR_VERSION VERSION_LESS 3))
cmake_policy(SET CMP0048 OLD) cmake_policy(SET CMP0048 OLD)
endif() endif()

View File

@ -26,7 +26,9 @@
extern "C" extern "C"
{ {
#ifndef InetPtopN
WINSOCK_API_LINKAGE INT WSAAPI inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf); WINSOCK_API_LINKAGE INT WSAAPI inet_pton(INT Family, PCSTR pszAddrString, PVOID pAddrBuf);
#endif
} }
#else #else