Skip to content

Commit ca93e35

Browse files
authored
Fix setup and BUILD_SHARED_LIBS for Linux (#2481)
1 parent 739f641 commit ca93e35

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

1k/1kiss.ps1

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ $compatMode = $false
8989
if ($Global:IsWin) {
9090
if (!$OutputEncoding -or $OutputEncoding.CodePage -ne 65001) {
9191
$OutputEncoding = [System.Text.Encoding]::UTF8
92-
try {
92+
try {
9393
[System.Console]::OutputEncoding = $OutputEncoding
9494
}
9595
catch {
@@ -145,10 +145,10 @@ class _1kiss {
145145
}
146146
}
147147
[void] addpath([string]$path) { $this.addpath($path, $false) }
148-
[void] addpath([string]$path, [bool]$append) {
148+
[void] addpath([string]$path, [bool]$append) {
149149
if (!$path -or $env:PATH.Contains($path)) { return }
150-
if (!$append) { $env:PATH = "$path$Global:ENV_PATH_SEP$env:PATH" }
151-
else { $env:PATH = "$env:PATH$Global:ENV_PATH_SEP$path" }
150+
if (!$append) { $env:PATH = "$path$Global:ENV_PATH_SEP$env:PATH" }
151+
else { $env:PATH = "$env:PATH$Global:ENV_PATH_SEP$path" }
152152
}
153153

154154
[void] pause($msg) {
@@ -766,9 +766,9 @@ function download_and_expand($url, $out, $dest) {
766766
}
767767
}
768768

769-
function resolve_path ($path, $prefix = $null) {
770-
if ($1k.isabspath($path)) {
771-
return $path
769+
function resolve_path ($path, $prefix = $null) {
770+
if ($1k.isabspath($path)) {
771+
return $path
772772
}
773773
else {
774774
if (!$prefix) { $prefix = $install_prefix }
@@ -812,7 +812,7 @@ function fetch_pkg($url, $out = $null, $exrep = $null, $prefix = $null) {
812812
else {
813813
$prefix = $install_prefix
814814
}
815-
815+
816816
download_and_expand $url $out $prefix
817817

818818
if ($pfn_rename) { &$pfn_rename }
@@ -835,7 +835,7 @@ function find_vs() {
835835

836836
$required_vs_ver = $manifest['vs']
837837
if (!$required_vs_ver) { $required_vs_ver = '12.0+' }
838-
838+
839839
# refer: https://learn.microsoft.com/en-us/visualstudio/install/workload-and-component-ids?view=vs-2022
840840
$require_comps = @('Microsoft.VisualStudio.Component.VC.Tools.x86.x64', 'Microsoft.VisualStudio.Product.BuildTools')
841841
$vs_installs = ConvertFrom-Json "$(&$VSWHERE_EXE -version $required_vs_ver.TrimEnd('+') -format 'json' -requires $require_comps -requiresAny -prerelease)"
@@ -1035,7 +1035,12 @@ function setup_cmake($skipOS = $false) {
10351035
$cmake_app_contents = Join-Path $cmake_dir 'CMake.app/Contents'
10361036
}
10371037
if (!$1k.isdir($cmake_dir)) {
1038-
fetch_pkg $cmake_url
1038+
if ($IsLinux) {
1039+
fetch_pkg $cmake_url -out $cmake_pkg_path
1040+
}
1041+
else {
1042+
fetch_pkg $cmake_url
1043+
}
10391044
}
10401045

10411046
if ($1k.isdir($cmake_dir)) {
@@ -1072,7 +1077,7 @@ function setup_cmake($skipOS = $false) {
10721077

10731078
$1k.println("Using cmake: $cmake_prog, version: $cmake_ver")
10741079
}
1075-
1080+
10761081
$1k.addpath($cmake_bin)
10771082
return $cmake_prog, $cmake_ver
10781083
}
@@ -1342,9 +1347,9 @@ function setup_android_sdk() {
13421347
# - https://ci.android.com/builds/submitted/12186248/win64/latest/android-ndk-12186248-windows-x86_64.zip
13431348
# - https://ci.android.com/builds/submitted/12186248/linux/latest/android-ndk-12186248-linux-x86_64.zip
13441349
# - https://ci.android.com/builds/submitted/12186248/darwin_mac/latest/android-ndk-12186248-darwin-x86_64.zip
1345-
1350+
13461351
$1k.println("Not found suitable android ndk, installing from ci.android.com ...")
1347-
1352+
13481353
$_artifact = @("android-ndk-${ndk_r23d_rev}-windows-x86_64.zip",
13491354
"android-ndk-${ndk_r23d_rev}-linux-x86_64.zip",
13501355
"android-ndk-${ndk_r23d_rev}-darwin-x86_64.zip").Get($HOST_OS)
@@ -1358,7 +1363,7 @@ function setup_android_sdk() {
13581363
}
13591364
else {
13601365
$1k.println("Not found suitable android ndk, installing ndk-$ndk_ver by sdkmanager ...")
1361-
1366+
13621367
$matchInfos = (exec_prog -prog $sdkmanager_prog -params "--sdk_root=$sdk_root", '--list' | Select-String 'ndk;')
13631368
if ($null -ne $matchInfos -and $matchInfos.Count -gt 0) {
13641369
$ndks = @{}
@@ -1393,7 +1398,7 @@ function setup_android_sdk() {
13931398
}
13941399
}
13951400
}
1396-
1401+
13971402
if ($sdk_comps) {
13981403
$sdk_cmdline_args = '--verbose', "--sdk_root=$sdk_root"
13991404
$sdk_cmdline_args += $sdk_comps
@@ -2055,7 +2060,7 @@ if (!$setupOnly) {
20552060
# apply additional build options
20562061
$BUILD_ALL_OPTIONS += "--parallel", "$($options.j)"
20572062

2058-
2063+
20592064
$1k.println("BUILD_ALL_OPTIONS=$BUILD_ALL_OPTIONS, Count={0}" -f $BUILD_ALL_OPTIONS.Count)
20602065

20612066
# forward non-cmake args to underlaying build toolchain, must at last
@@ -2101,7 +2106,7 @@ if (!$setupOnly) {
21012106
exit $LASTEXITCODE
21022107
}
21032108
}
2104-
2109+
21052110
if ($options.i) {
21062111
$install_args = @($BUILD_DIR, '--config', $optimize_flag)
21072112
cmake --install $install_args | Out-Host

3rdparty/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ include(CheckCCompilerFlag)
4545
include(CheckCSourceCompiles)
4646
include(CheckCXXSourceCompiles)
4747

48+
# Enable -fPIC flag when compiling as shared libs...
49+
if(BUILD_SHARED_LIBS AND UNIX AND NOT ANDROID)
50+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
51+
endif()
52+
4853
# Note: we set default AX_ISA_LEVEL to 2 for sse4.1 for axmol app can runs on large amount devices
4954
# If you want axmol app runs on more old devices, you can specify in cmake cmdline `-DAX_ISA_LEVEL=1`,
5055
# otherwise, host compiler generated instructions will crash on old devices which not support high level
@@ -501,3 +506,8 @@ if (ANDROID)
501506
configure_file(${ANDROID_SHARED_LOAD_FILE_PATH} ${target_folder}/${package_path}/${ANDROID_SHARED_LOAD_FILE_NAME} @ONLY)
502507
endfunction()
503508
endif()
509+
510+
# Disable -fPIC flag for other libs...
511+
if(BUILD_SHARED_LIBS AND UNIX AND NOT ANDROID)
512+
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
513+
endif()

extensions/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
if(BUILD_SHARED_LIBS)
55
cmake_policy(SET CMP0079 NEW)
6+
7+
# Enable -fPIC flag when compiling as shared libs...
8+
if(UNIX AND NOT ANDROID)
9+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
10+
endif()
611
endif()
712

813
function(setup_ax_extension_config target_name)
@@ -127,4 +132,9 @@ if(AX_ENABLE_EXT_JSONDEFAULT)
127132
add_subdirectory(JSONDefault)
128133
endif()
129134

135+
# Disable -fPIC flag for other libs...
136+
if(BUILD_SHARED_LIBS AND UNIX AND NOT ANDROID)
137+
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
138+
endif()
139+
130140
message(STATUS "Enabled ${_AX_CORE_LIB} extensions:${_AX_EXTENSION_LIBS}")

0 commit comments

Comments
 (0)