author | Wuzzy <Wuzzy2@mail.ru> |
Thu, 10 Oct 2019 00:28:55 +0200 | |
changeset 15455 | 1ee2736de636 |
parent 15312 | 5b2dec63f4cf |
permissions | -rw-r--r-- |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
1 |
|
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
2 |
if(APPLE) |
15312
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
3 |
#minimum for macOS. sorry! |
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
4 |
cmake_minimum_required(VERSION 3.9.0) |
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
5 |
|
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
6 |
#set c++11 standard for QT requirements |
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
7 |
set(CMAKE_CXX_STANDARD 11) |
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
8 |
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
9 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") |
9517
217eacb69395
fail early when an incompatible cmake version is found
koda
parents:
9339
diff
changeset
|
10 |
|
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
11 |
set(CMAKE_FIND_FRAMEWORK "FIRST") |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
12 |
|
9268 | 13 |
#what system are we building for |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
14 |
set(minimum_macosx_version $ENV{MACOSX_DEPLOYMENT_TARGET}) |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
15 |
|
9268 | 16 |
#detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
17 |
find_program(sw_vers sw_vers) |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
18 |
if(sw_vers) |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
19 |
execute_process(COMMAND ${sw_vers} "-productVersion" |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
20 |
OUTPUT_VARIABLE current_macosx_version |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
21 |
OUTPUT_STRIP_TRAILING_WHITESPACE) |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
22 |
string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version}) |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
23 |
else() |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
24 |
if(NOT minimum_macosx_version) |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
25 |
message(FATAL_ERROR "sw_vers not found! Need explicit MACOSX_DEPLOYMENT_TARGET variable set") |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
26 |
else() |
9151 | 27 |
message("*** sw_vers not found! Fallback to MACOSX_DEPLOYMENT_TARGET variable ***") |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
28 |
set(current_macosx_version ${minimum_macosx_version}) |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
29 |
endif() |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
30 |
endif() |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
31 |
|
9268 | 32 |
#if nothing is set, we deploy only for the current system |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
33 |
if(NOT minimum_macosx_version) |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
34 |
set(minimum_macosx_version ${current_macosx_version}) |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
35 |
endif() |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
36 |
|
15312
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
37 |
#minimum OSX version is 10.8. Earlier versions cannot compile some dependencies anymore |
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
38 |
#(like ffmpeg/libav) |
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
39 |
if(minimum_macosx_version VERSION_LESS "10.8") |
5b2dec63f4cf
Fix compiling on MacOS X by requiring c++11 standard. Building now requires MacOS X 10.8+ and CMake 3.9+
raptor <buckyballreaction@gmail.com>
parents:
11362
diff
changeset
|
40 |
message(FATAL_ERROR "Hedgewars is unsupported on your platform and requires Mac OS X 10.8+") |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
41 |
endif() |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
42 |
|
9271 | 43 |
#parse this system variable and adjust only the powerpc syntax to be compatible with -P |
44 |
if(CMAKE_OSX_ARCHITECTURES) |
|
45 |
string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}") |
|
46 |
string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}") |
|
47 |
string(REGEX MATCH "[xX]86_64+" x86_64_build "${CMAKE_OSX_ARCHITECTURES}") |
|
48 |
if(x86_64_build) |
|
49 |
add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64) |
|
50 |
elseif(i386_build) |
|
51 |
add_flag_prepend(CMAKE_Pascal_FLAGS -Pi386) |
|
52 |
elseif(powerpc_build) |
|
53 |
add_flag_prepend(CMAKE_Pascal_FLAGS -Ppowerpc) |
|
54 |
else() |
|
55 |
message(FATAL_ERROR "Unknown architecture present in CMAKE_OSX_ARCHITECTURES (${CMAKE_OSX_ARCHITECTURES})") |
|
56 |
endif() |
|
57 |
list(LENGTH CMAKE_OSX_ARCHITECTURES num_of_archs) |
|
58 |
if(num_of_archs GREATER 1) |
|
9889 | 59 |
message("*** Only one architecture in CMAKE_OSX_ARCHITECTURES is supported, picking the first one ***") |
9271 | 60 |
endif() |
61 |
elseif(CMAKE_SIZEOF_VOID_P MATCHES "8") |
|
62 |
#if that variable is not set check if we are on x86_64 and if so force it, else use default |
|
63 |
add_flag_prepend(CMAKE_Pascal_FLAGS -Px86_64) |
|
64 |
endif() |
|
65 |
||
9268 | 66 |
#CMAKE_OSX_SYSROOT is set at the system version we are supposed to build on |
67 |
#we need to provide the correct one when host and target differ |
|
9940 | 68 |
if(NOT CMAKE_OSX_SYSROOT AND |
69 |
NOT ${minimum_macosx_version} VERSION_EQUAL ${current_macosx_version}) |
|
9887
6add6157b58e
improve OSX SDK selection when build and deploy target don't match
koda
parents:
9860
diff
changeset
|
70 |
find_program(xcrun xcrun) |
6add6157b58e
improve OSX SDK selection when build and deploy target don't match
koda
parents:
9860
diff
changeset
|
71 |
if(xcrun) |
6add6157b58e
improve OSX SDK selection when build and deploy target don't match
koda
parents:
9860
diff
changeset
|
72 |
execute_process(COMMAND ${xcrun} "--show-sdk-path" |
6add6157b58e
improve OSX SDK selection when build and deploy target don't match
koda
parents:
9860
diff
changeset
|
73 |
OUTPUT_VARIABLE current_sdk_path |
6add6157b58e
improve OSX SDK selection when build and deploy target don't match
koda
parents:
9860
diff
changeset
|
74 |
OUTPUT_STRIP_TRAILING_WHITESPACE) |
6add6157b58e
improve OSX SDK selection when build and deploy target don't match
koda
parents:
9860
diff
changeset
|
75 |
string(REPLACE "${current_macosx_version}" |
6add6157b58e
improve OSX SDK selection when build and deploy target don't match
koda
parents:
9860
diff
changeset
|
76 |
"${minimum_macosx_version}" |
6add6157b58e
improve OSX SDK selection when build and deploy target don't match
koda
parents:
9860
diff
changeset
|
77 |
CMAKE_OSX_SYSROOT |
6add6157b58e
improve OSX SDK selection when build and deploy target don't match
koda
parents:
9860
diff
changeset
|
78 |
"${current_sdk_path}") |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
79 |
else() |
9887
6add6157b58e
improve OSX SDK selection when build and deploy target don't match
koda
parents:
9860
diff
changeset
|
80 |
message("*** xcrun not found! Build will work on ${current_macosx_version} only ***") |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
81 |
endif() |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
82 |
endif() |
9940 | 83 |
if(CMAKE_OSX_SYSROOT) |
9268 | 84 |
add_flag_append(CMAKE_Pascal_FLAGS "-XR${CMAKE_OSX_SYSROOT}") |
85 |
add_flag_append(CMAKE_Pascal_FLAGS "-k-macosx_version_min -k${minimum_macosx_version}") |
|
9941
d33d4727b39e
explicitly set linker library path for pascal when deploying an older version
koda
parents:
9940
diff
changeset
|
86 |
add_flag_append(CMAKE_Pascal_FLAGS "-k-L${LIBRARY_OUTPUT_PATH} -Fl${LIBRARY_OUTPUT_PATH}") |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
87 |
endif() |
9339
14f5f3a1e2f7
some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents:
9297
diff
changeset
|
88 |
|
14f5f3a1e2f7
some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents:
9297
diff
changeset
|
89 |
#add user framework directory |
14f5f3a1e2f7
some work on cmake_pascal files to better support flags we use, make engine compile as library again
koda
parents:
9297
diff
changeset
|
90 |
add_flag_append(CMAKE_Pascal_FLAGS "-Ff~/Library/Frameworks") |
9705
322fe1736347
fix linking on osx by hardcoding the default library output path
koda
parents:
9673
diff
changeset
|
91 |
|
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
92 |
endif(APPLE) |
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
93 |
|
9210 | 94 |
if(MINGW) |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
95 |
#this flags prevents a few dll hell problems |
9268 | 96 |
add_flag_append(CMAKE_C_FLAGS "-static-libgcc") |
97 |
add_flag_append(CMAKE_CXX_FLAGS "-static-libgcc") |
|
9210 | 98 |
endif(MINGW) |
9150
79c58ff0d4b1
move platform specific and revision info code into separate cmake modules
koda
parents:
diff
changeset
|
99 |
|
9210 | 100 |
if(WIN32) |
9218 | 101 |
if(NOT ${BUILD_SHARED_LIB}) |
9210 | 102 |
message(FATAL_ERROR "Static linking is not supported on Windows") |
103 |
endif() |
|
104 |
endif(WIN32) |
|
9673 | 105 |
|
106 |
if(UNIX) |
|
107 |
add_flag_append(CMAKE_C_FLAGS "-fPIC") |
|
108 |
add_flag_append(CMAKE_CXX_FLAGS "-fPIC") |
|
109 |
endif(UNIX) |