Как я могу кросс-компилировать из Linux для Windows с помощью cmake? - PullRequest
0 голосов
/ 16 декабря 2018

В настоящее время я пытаюсь выполнить кросс-компиляцию для Windows, используя cmake в Linux Subsystem для Windows Ubuntu.Я компилирую форму Linux, потому что хочу иметь возможность поддерживать несколько платформ.

Я не уверен, как заставить это работать, и у меня нет предпочтений компилятора.

См. Следующий код и сборкувывод для моей текущей попытки.

CMakeLists.txt file

cmake_minimum_required(VERSION 3.7)

set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/win.toolchain.cmake)

project(environment.exe)

find_package(SDL2 REQUIRED)
include_directories(environment.exe ${SDL2_INCLUDE_DIRS})

# get executable src files
file(GLOB_RECURSE environment.exe_src ${CMAKE_CURRENT_SOURCE_DIR}/src/environment/*.cpp)

# add environment.exe executable
add_executable(environment.exe ${environment.exe_src})
target_link_libraries(environment.exe ${SDL2_LIBRARIES})

# set output dir
set_target_properties(
    environment.exe
    PROPERTIES
    # ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/suite/lib"
    # LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/suite/lib"
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/environment"
)

win.toolchain.cmake file

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x64)#i686

set(triple x64-pc-win32)

set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})

BASH output

a@DESKTOP-DCHFQSJ:/mnt/e/d/User/Software Projects/windows-software-environment$ ./build.sh
Checking for make installation.
make is installed.
Checking for cmake installation.
cmake is installed.
Checking for mingw-w64 installation.
mingw-w64 is installed.
Checking for g++-mingw-w64 installation.
g++-mingw-w64 is installed.
Checking for libsdl2-dev installation.
libsdl2-dev is installed.
./build.sh: line 30: cd: ./build: No such file or directory
Running cmake on './build'
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "/usr/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp

    Run Build Command:"/usr/bin/make" "cmTC_8a6e7/fast"
    /usr/bin/make -f CMakeFiles/cmTC_8a6e7.dir/build.make CMakeFiles/cmTC_8a6e7.dir/build
    make[1]: Entering directory '/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj
    /usr/bin/clang --target=x64-pc-win32    -o CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj   -c "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp/testCCompiler.c"
    error: unknown target triple 'x64-pc-windows-msvc19.11.0', please use -triple or -arch
    CMakeFiles/cmTC_8a6e7.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj' failed
    make[1]: *** [CMakeFiles/cmTC_8a6e7.dir/testCCompiler.c.obj] Error 1
    make[1]: Leaving directory '/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_8a6e7/fast' failed
    make: *** [cmTC_8a6e7/fast] Error 2




  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:19 (project)


-- Configuring incomplete, errors occurred!
See also "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeOutput.log".
See also "/mnt/e/d/User/Software Projects/windows-software-environment/build/CMakeFiles/CMakeError.log".
...