forked from KiCad/kicad-source-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigurePlatform.cmake
105 lines (92 loc) · 5.04 KB
/
ConfigurePlatform.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
if( MSVC )
cmake_policy( SET CMP0091 NEW )
# CMake does not set CMAKE_SYSTEM_PROCESSOR correctly for MSVC
# and it will always return the host instead of the target arch
if("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM64")
set( KICAD_BUILD_ARCH "arm64" )
set( KICAD_BUILD_ARCH_ARM64 1 )
elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM")
set( KICAD_BUILD_ARCH "arm" )
set( KICAD_BUILD_ARCH_ARM 1 )
elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "X86")
set( KICAD_BUILD_ARCH "x86" )
set( KICAD_BUILD_ARCH_X86 1 )
elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "x64")
set( KICAD_BUILD_ARCH "x64" )
set( KICAD_BUILD_ARCH_X64 1 )
else()
message(FATAL_ERROR "Failed to determine the MSVC target architecture: ${MSVC_C_ARCHITECTURE_ID}")
endif()
add_compile_definitions( KICAD_BUILD_ARCH=${KICAD_BUILD_ARCH} )
# CMake does not set CMAKE_SYSTEM_PROCESSOR correctly for MSVC
# and it will always return the host instead of the target arch
if("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "ARM64")
set( KICAD_HOST_ARCH "arm64" )
set( KICAD_HOST_ARCH_ARM64 1 )
elseif("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "ARM")
set( KICAD_HOST_ARCH "arm" )
set( KICAD_HOST_ARCH_ARM 1 )
elseif("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "X86")
set( KICAD_HOST_ARCH "x86" )
set( KICAD_HOST_ARCH_X86 1 )
elseif("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
set( KICAD_HOST_ARCH "x64" )
set( KICAD_HOST_ARCH_X64 1 )
else()
message(FATAL_ERROR "Failed to determine the host architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
else()
if ( NOT CMAKE_SIZEOF_VOID_P EQUAL 8 )
set( KICAD_BUILD_ARCH "x86" )
set( KICAD_BUILD_ARCH_X86 1 )
elseif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set( KICAD_BUILD_ARCH "x64" )
set( KICAD_BUILD_ARCH_X64 1 )
endif()
endif()
if( MSVC )
# This is a workaround borrowed from https://github.com/dotnet/runtime/blob/main/eng/native/configurecompiler.cmake
# CMake currently cannot handle the fact that "armasm" is used in combination with standard MSVC "cl" for ARM targets
# So this is basically a hack (incombination with the MSVCAssemblyHelper.cmake) to make this all work
# This workaround can be removed when https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9326 is finally part of a
# cmake release AND when MSVC ships said cmake release
if(KICAD_BUILD_ARCH_ARM)
message( "Configuring ARM assembler" )
# Explicitly specify the assembler to be used for Arm32 compile
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER)
set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
# Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
# use ml[64].exe as the assembler.
enable_language(ASM)
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "")
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "")
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "")
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "")
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -g <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")
elseif(KICAD_BUILD_ARCH_ARM64)
message( "Configuring ARM64 assembler" )
# Explicitly specify the assembler to be used for Arm64 compile
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)
set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
# Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
# use ml[64].exe as the assembler.
enable_language(ASM)
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "")
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "")
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "")
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "")
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -g <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")
else()
message( "Configuring MASM assembler" )
if(KICAD_BUILD_ARCH_X86)
set( CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /safeseh" )
endif()
enable_language(ASM_MASM)
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "")
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "")
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "")
set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "")
endif()
endif()