Skip to content

Commit b7b85ff

Browse files
authored
Cherry pick some fixes from v3 (#3134)
* Remove include_directories for Apple platform (#3131) * Improve cmake scripts (#3133)
1 parent bb6ac32 commit b7b85ff

7 files changed

Lines changed: 45 additions & 40 deletions

File tree

1k/dm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.23)
33

44
project(dm)
55

6-
find_program(PWSH_PROG NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
6+
find_program(PWSH_EXECUTABLE NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
77

88
message(STATUS "CMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
99
message(STATUS "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
@@ -36,7 +36,7 @@ elseif(APPLE)
3636
endif()
3737

3838
if(NOT ${CMAKE_C_COMPILER} MATCHES ".*cl\.exe" OR "${MSVC_VERSION}" GREATER_EQUAL 1928)
39-
execute_process(COMMAND ${PWSH_PROG} "${CMAKE_CURRENT_SOURCE_DIR}/dm.ps1" "${CMAKE_C_COMPILER}" "${CMAKE_C_FLAGS} ${cross_flags}")
39+
execute_process(COMMAND ${PWSH_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/dm.ps1" "${CMAKE_C_COMPILER}" "${CMAKE_C_FLAGS} ${cross_flags}")
4040
endif()
4141

4242
add_library(dm dm.c)

1k/fetch.cmake

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
cmake_minimum_required(VERSION 3.23...4.0)
88

99
# ## 1kdist url
10-
find_program(PWSH_PROG NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
11-
find_program(GIT_PROG NAMES git NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
10+
find_program(PWSH_EXECUTABLE NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
11+
find_program(GIT_EXECUTABLE NAMES git NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
1212

1313
function(_1kfetch_init)
1414
if(NOT _1kfetch_cache_dir)
@@ -21,12 +21,12 @@ function(_1kfetch_init)
2121
set(_1kfetch_manifest "${_1kfetch_manifest}" CACHE STRING "" FORCE)
2222
endif()
2323

24-
if(NOT EXISTS ${PWSH_PROG}) # try again
25-
unset(PWSH_PROG CACHE)
26-
find_program(PWSH_PROG NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
24+
if(NOT EXISTS ${PWSH_EXECUTABLE}) # try again
25+
unset(PWSH_EXECUTABLE CACHE)
26+
find_program(PWSH_EXECUTABLE NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
2727
endif()
2828

29-
execute_process(COMMAND ${PWSH_PROG} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/resolv-url.ps1
29+
execute_process(COMMAND ${PWSH_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/resolv-url.ps1
3030
-name "1kdist"
3131
-manifest ${_1kfetch_manifest}
3232
OUTPUT_VARIABLE _1kdist_url
@@ -121,7 +121,7 @@ function(_1kfetch uri)
121121
list(APPEND _fetch_args -pull_branch)
122122
endif()
123123

124-
execute_process(COMMAND ${PWSH_PROG} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/fetch.ps1
124+
execute_process(COMMAND ${PWSH_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/fetch.ps1
125125
${_fetch_args}
126126
RESULT_VARIABLE _errorcode
127127
)
@@ -159,15 +159,15 @@ function(_1kfetch_fast uri)
159159
string(PREPEND _url "https://github.com/")
160160

161161
if(NOT EXISTS "${_sentry_file}")
162-
execute_process(COMMAND ${GIT_PROG} clone --progress ${_url} "${_pkg_store}" RESULT_VARIABLE _errorcode)
162+
execute_process(COMMAND ${GIT_EXECUTABLE} clone --progress ${_url} "${_pkg_store}" RESULT_VARIABLE _errorcode)
163163
file(WRITE "${_sentry_file}" "ver: ${_version}")
164164
endif()
165165

166166
if(EXISTS "${_sentry_file}")
167-
execute_process(COMMAND ${GIT_PROG} -C ${_pkg_store} checkout ${_version} RESULT_VARIABLE _errorcode)
167+
execute_process(COMMAND ${GIT_EXECUTABLE} -C ${_pkg_store} checkout ${_version} RESULT_VARIABLE _errorcode)
168168

169169
if(_errorcode)
170-
execute_process(COMMAND ${GIT_PROG} -C ${_pkg_store} checkout v${_version} RESULT_VARIABLE _errorcode)
170+
execute_process(COMMAND ${GIT_EXECUTABLE} -C ${_pkg_store} checkout v${_version} RESULT_VARIABLE _errorcode)
171171
endif()
172172
else()
173173
message(FATAL_ERROR "fetch repo ${uri} fail, try again")
@@ -214,7 +214,7 @@ endfunction()
214214
function(_1klink src dest)
215215
file(TO_NATIVE_PATH "${src}" _srcDir)
216216
file(TO_NATIVE_PATH "${dest}" _dstDir)
217-
execute_process(COMMAND ${PWSH_PROG} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/fsync.ps1 -s "${_srcDir}" -d "${_dstDir}" -l 1)
217+
execute_process(COMMAND ${PWSH_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/fsync.ps1 -s "${_srcDir}" -d "${_dstDir}" -l 1)
218218
endfunction()
219219

220220
function(_1kparse_option OPTION)
@@ -268,7 +268,7 @@ macro(_1kperf_end tag)
268268
message(STATUS "[${_fetch_end_msec}ms][1kperf] end of ${tag}, cost: ${_fetch_cost_msec}ms")
269269
endmacro()
270270

271-
if(PWSH_PROG)
271+
if(PWSH_EXECUTABLE)
272272
_1kfetch_init()
273273
else()
274274
message(AUTHOR_WARNING "fetch.cmake: PowerShell is missing, the fetch functions not work, please install from https://github.com/PowerShell/PowerShell/releases")

1k/ios.cmake

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,14 @@ else()
128128
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
129129
endif()
130130

131-
# Set find path mode properly for cross-compiling
132-
# refer to: https://discourse.cmake.org/t/find-package-stops-working-when-cmake-system-name-ios/4609/6
133-
# BUT: CMAKE_FIND_ROOT_PATH is preferred for additional search directories when cross-compiling
134-
# set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH CACHE STRING "")
135-
# set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH CACHE STRING "")
136-
# set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH CACHE STRING "")
137-
138-
# by default, we want find host program only when cross-compiling
139-
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE STRING "")
131+
# Configure find path mode for cross-compiling:
132+
# - Use host tools only when cross-compiling (find_program).
133+
# - Restrict package, library, and path lookups to CMAKE_FIND_ROOT_PATH when cross-compiling.
134+
# Reference: https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html
135+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER CACHE STRING "" FORCE)
136+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY CACHE STRING "" FORCE)
137+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY CACHE STRING "" FORCE)
138+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY CACHE STRING "" FORCE)
140139

141140
# Sets CMAKE_SYSTEM_PROCESSOR properly
142141
if(ARCHS MATCHES "((arm64|arm64e|x86_64)(^|;|, )?)+")

3rdparty/CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ if(AX_ENABLE_AUDIO)
282282
set(OBOE_SOURCE "${oboe_SOURCE_DIR}" CACHE STRING "Source directory for Oboe." FORCE)
283283
endif()
284284

285-
list(APPEND alsoft_opts "ALSOFT_RTKIT OFF"
285+
list(APPEND alsoft_opts
286+
"ALSOFT_RTKIT OFF"
286287
"ALSOFT_BACKEND_PIPEWIRE OFF"
287288
"ALSOFT_BACKEND_PULSEAUDIO OFF"
288289
"ALSOFT_BACKEND_ALSA OFF"
@@ -292,10 +293,17 @@ if(AX_ENABLE_AUDIO)
292293
"ALSOFT_BACKEND_JACK OFF"
293294
"ALSOFT_BACKEND_PORTAUDIO OFF"
294295
"ALSOFT_BACKEND_SDL2 OFF"
295-
)
296-
set(ALSOFT_RTKIT OFF CACHE BOOL "Enable RTKit support" FORCE)
296+
)
297297
elseif(WINDOWS)
298-
list(APPEND alsoft_opts "ALSOFT_BACKEND_WASAPI ON" "ALSOFT_BACKEND_WAVE OFF" "ALSOFT_BACKEND_DSOUND OFF" "ALSOFT_BACKEND_WINMM OFF")
298+
list(APPEND alsoft_opts
299+
"ALSOFT_RTKIT OFF"
300+
"ALSOFT_BACKEND_WASAPI ON"
301+
"ALSOFT_BACKEND_WAVE OFF"
302+
"ALSOFT_BACKEND_DSOUND OFF"
303+
"ALSOFT_BACKEND_WINMM OFF"
304+
)
305+
elseif(APPLE)
306+
list(APPEND alsoft_opts "ALSOFT_RTKIT OFF")
299307
endif()
300308

301309
if(WINRT)

cmake/Modules/AXBuildHelpers.cmake

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
include(CMakeParseArguments)
2+
find_program(PWSH_EXECUTABLE NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
23

3-
find_program(PWSH_PROG NAMES pwsh powershell NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
4-
5-
if(NOT PWSH_PROG)
4+
if(NOT PWSH_EXECUTABLE)
65
message("powershell not found.")
76
message(FATAL_ERROR "Please install it https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell, and run CMake again.")
87
endif()
@@ -37,7 +36,7 @@ function(ax_sync_target_res ax_target)
3736
# get_filename_component(link_folder ${opt_LINK_TO} DIRECTORY)
3837
get_filename_component(link_folder_abs ${opt_LINK_TO} ABSOLUTE)
3938
add_custom_command(TARGET ${sync_target_name} POST_BUILD
40-
COMMAND ${PWSH_PROG} ARGS ${_AX_ROOT}/1k/fsync.ps1
39+
COMMAND ${PWSH_EXECUTABLE} ARGS ${_AX_ROOT}/1k/fsync.ps1
4140
-s ${cc_folder} -d ${link_folder_abs} -l ${opt_SYM_LINK}
4241
)
4342
endforeach()
@@ -78,18 +77,18 @@ function(ax_sync_lua_scripts ax_target src_dir dst_dir)
7877

7978
if(MSVC)
8079
add_custom_command(TARGET ${luacompile_target} POST_BUILD
81-
COMMAND ${PWSH_PROG} ARGS ${_AX_ROOT}/1k/fsync.ps1
80+
COMMAND ${PWSH_EXECUTABLE} ARGS ${_AX_ROOT}/1k/fsync.ps1
8281
-s ${src_dir} -d ${dst_dir}
8382
)
8483
else()
8584
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
8685
add_custom_command(TARGET ${luacompile_target} POST_BUILD
87-
COMMAND ${PWSH_PROG} ARGS ${_AX_ROOT}/1k/fsync.ps1
86+
COMMAND ${PWSH_EXECUTABLE} ARGS ${_AX_ROOT}/1k/fsync.ps1
8887
-s ${src_dir} -d ${dst_dir}
8988
)
9089
else()
9190
add_custom_command(TARGET ${luacompile_target} POST_BUILD
92-
COMMAND ${PWSH_PROG} ARGS ${_AX_ROOT}/1k/fsync.ps1
91+
COMMAND ${PWSH_EXECUTABLE} ARGS ${_AX_ROOT}/1k/fsync.ps1
9392
-s ${src_dir} -d ${dst_dir}
9493
)
9594
endif()

cmake/Modules/AXConfigDepend.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ macro(ax_depend)
2626
elseif(ANDROID)
2727
list(APPEND PLATFORM_SPECIFIC_LIBS GLESv2 EGL log android OpenSLES)
2828
elseif(APPLE)
29-
include_directories(/System/Library/Frameworks)
3029
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
3130
find_library(FOUNDATION_LIBRARY Foundation)
3231
find_library(QUARTZCORE_LIBRARY QuartzCore)

core/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,19 @@ if(WASM)
152152
endif()
153153

154154
# axmolver.h
155-
find_program(GIT_PROG NAMES git)
155+
find_program(GIT_EXECUTABLE NAMES git)
156156

157-
if(AX_UPDATE_BUILD_VERSION AND GIT_PROG AND EXISTS "${_AX_ROOT}/.git")
157+
if(AX_UPDATE_BUILD_VERSION AND GIT_EXECUTABLE AND EXISTS "${_AX_ROOT}/.git")
158158
# Get the current working branch and its latest abbreviated commit hash
159-
execute_process(COMMAND ${GIT_PROG} -C "${_AX_ROOT}" rev-list --count HEAD
159+
execute_process(COMMAND ${GIT_EXECUTABLE} -C "${_AX_ROOT}" rev-list --count HEAD
160160
TIMEOUT 5
161161
OUTPUT_VARIABLE AX_BUILD_NUM
162162
OUTPUT_STRIP_TRAILING_WHITESPACE)
163-
execute_process(COMMAND ${GIT_PROG} -C "${_AX_ROOT}" branch --show-current
163+
execute_process(COMMAND ${GIT_EXECUTABLE} -C "${_AX_ROOT}" branch --show-current
164164
TIMEOUT 5
165165
OUTPUT_VARIABLE AX_GIT_BRANCH
166166
OUTPUT_STRIP_TRAILING_WHITESPACE)
167-
execute_process(COMMAND ${GIT_PROG} -C "${_AX_ROOT}" rev-parse --short=7 HEAD
167+
execute_process(COMMAND ${GIT_EXECUTABLE} -C "${_AX_ROOT}" rev-parse --short=7 HEAD
168168
TIMEOUT 5
169169
OUTPUT_VARIABLE AX_GIT_COMMIT_HASH
170170
OUTPUT_STRIP_TRAILING_WHITESPACE)

0 commit comments

Comments
 (0)