Fine tune LuaJIT target arch detection logic.

This commit is contained in:
Yao Wei Tjong 姚伟忠 2014-12-17 12:17:14 +08:00
parent 0af8a30650
commit 67e415acc8
6 changed files with 71 additions and 50 deletions

View File

@ -64,7 +64,7 @@ if (NOT MSVC AND NOT DEFINED URHO3D_DEFAULT_64BIT) # Only do this once in the i
endif ()
endif ()
if (ANDROID OR RPI)
# This build option is not available on Android and Raspberry-Pi platforms as its value is preset by the toolchain being used in the build
# This build option is not available on Android and Raspberry-Pi platforms as its value is preset by the chosen toolchain in the build tree
set (URHO3D_64BIT ${URHO3D_DEFAULT_64BIT})
else ()
option (URHO3D_64BIT "Enable 64-bit build" ${URHO3D_DEFAULT_64BIT})

View File

@ -41,7 +41,7 @@ A number of build options can be defined explicitly when invoking the above cmak
|RPI |0|Configure project using Raspberry Pi cross-compiler toolchain (cmake_generic.sh only)|
|WIN32 |0|Configure project using MinGW cross-compiler toolchain (cmake_generic.sh only)|
|IOS |0|Configure project for targeting iOS platform (cmake_generic.sh and cmake-gui only); use cmake_ios.sh as shortcut|
|URHO3D_64BIT |*|Enable 64bit build, on MSVC default to 0, on other compilers the default is set based on the installed toolchain on host system|
|URHO3D_64BIT |*|Enable 64bit build, on MSVC default to 0, on other compilers the default is set based on the 64-bit capability of the chosen toolchain on host system|
|URHO3D_ANGELSCRIPT |1|Enable AngelScript scripting support|
|URHO3D_LUA |0|Enable Lua scripting support|
|URHO3D_LUAJIT |0|Enable Lua scripting support using LuaJIT (check LuaJIT's CMakeLists.txt for more options)|

View File

@ -61,9 +61,9 @@ task :cmake do
ARGV.each { |option|
task option.to_sym do ; end; Rake::Task[option].clear # No-op hack
case option
when 'cmake'
when 'cmake', 'generic'
# do nothing
when 'clean', 'codeblocks', 'eclipse', 'generic', 'macosx'
when 'clean', 'codeblocks', 'eclipse', 'macosx'
script = "cmake_#{option}.sh" unless script == 'cmake_clean.sh'
when 'android', 'ios', 'mingw', 'rpi'
platform = option
@ -78,24 +78,39 @@ task :cmake do
system "./#{script} #{prefix_path}/#{platform}-Build #{build_options}" or abort
end
# Usage: rake make [prefix_path=..] [num_jobs=8] (only intended to be used by lazy man =), e.g. rake make android, rake make android doc
# Usage: rake make [prefix_path=..] [numjobs=8] (only intended to be used by lazy man =), e.g. rake make android, rake make android doc
desc 'Invoke make command in the build tree location predetermined based on the target platform'
task :make do
prefix_path = ENV['prefix_path'] || '..'
build_options = '-j' + (ENV['num_jobs'] || '8')
numjobs = '-j' + (ENV['numjobs'] || '8')
platform = 'native'
cmake_build_options = ''
build_options = ''
ARGV.each { |option|
task option.to_sym do ; end; Rake::Task[option].clear # No-op hack
case option
when 'make'
when 'codeblocks', 'eclipse', 'generic', 'macosx', 'make'
# do nothing
when 'android', 'ios', 'mingw', 'rpi'
platform = option
when 'clean_first'
cmake_build_options = "#{cmake_build_options} --clean-first"
else
build_options = "#{build_options} #{option}" unless /(?:prefix_path|num_jobs)=.*/ =~ option
if /(?:config|target)=.*/ =~ option
cmake_build_options = "#{cmake_build_options} --#{option.gsub(/=/, ' ')}"
elsif /(?:prefix_path|numjobs)=.*/ !~ option
build_options = "#{build_options} #{/=/ =~ option ? '-' + option.gsub(/=/, ' ') : option}"
end
end
}
system "cd #{prefix_path}/#{platform}-Build && make #{build_options}" or abort
if Dir.glob("#{prefix_path}/#{platform}-Build/*.xcodeproj").empty?
build_options = "#{numjobs}#{build_options}"
filter = ''
else
build_options.gsub!(/ ([^=]+)=(\w+)/, ' -\1 \2')
filter = '|xcpretty'
end
system "cd #{prefix_path}/#{platform}-Build && cmake --build . #{cmake_build_options} -- #{build_options} #{filter}" or abort
end
# Usage: rake android [parameter='--es pickedLibrary Urho3DPlayer'] [intent=.SampleLauncher] [package=com.github.urho3d] [success_indicator='Initialized engine'] [payload='sleep 30'] [api=19] [abi=armeabi-v7a] [avd=test_#{api}_#{abi}] [retries=10] [retry_interval=10]

View File

@ -207,11 +207,9 @@ else ()
set (LJVM_BOUT lj_vm.s)
enable_language (ASM)
if (TARGET_LJARCH STREQUAL x64)
if (URHO3D_64BIT)
set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m64")
else ()
set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32")
endif ()
set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m64")
else ()
set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32")
endif ()
if (APPLE)
set (LJVM_MODE machasm)

View File

@ -20,50 +20,58 @@
# THE SOFTWARE.
#
# Macro for finding a substring
macro (find_string find_regex input_string output_string)
if (NOT DEFINED ${output_string})
message (STATUS "Finding value for LuaJIT:${output_string}")
string (REGEX MATCH ${find_regex} matched ${input_string})
# Macro for finding a substring in TARGET_TESTARCH variable
macro (find_string find_regex output_var)
if (NOT DEFINED ${output_var})
message (STATUS "Finding value for LuaJIT:${output_var}")
string (REGEX MATCH ${find_regex} matched "${TARGET_TESTARCH}") # Search input as a string
if (matched)
string (REGEX MATCH "\\(.*\\)" captured ${find_regex})
if (captured)
string (REGEX REPLACE ${find_regex} \\1 matched ${matched})
endif ()
set (${output_string} ${matched} CACHE INTERNAL "LUAJIT INTERNAL - ${output_string}")
message (STATUS "Finding value for LuaJIT:${output_string} - found (${matched})")
# Special case handling to cater for URHO3D_64BIT build option
if (${output_var} STREQUAL TARGET_LJARCH)
string (TOLOWER ${matched} matched)
if (matched STREQUAL x64 AND NOT URHO3D_64BIT)
set (matched x86)
endif ()
elseif (${output_var} STREQUAL ARCH_BITS)
if (matched EQUAL 64 AND NOT URHO3D_64BIT)
set (matched 32)
endif ()
endif ()
set (${output_var} ${matched} CACHE INTERNAL "LUAJIT INTERNAL - ${output_var}")
message (STATUS "Finding value for LuaJIT:${output_var} - found (${matched})")
else ()
set (${output_string} 0 CACHE INTERNAL "LUAJIT INTERNAL - ${output_string}")
set (${output_var} 0 CACHE INTERNAL "LUAJIT INTERNAL - ${output_var}")
message (STATUS "Finding value for LuaJIT:${output_var} - not found")
endif ()
endif ()
endmacro ()
# Makefile: Architecture detection
find_string ("LJ_TARGET_(X64|X86|ARM|PPC|PPCSPE|MIPS) 1" "${TARGET_TESTARCH}" TARGET_LJARCH)
if (TARGET_LJARCH)
string (TOLOWER ${TARGET_LJARCH} TARGET_LJARCH)
set (TARGET_LJARCH ${TARGET_LJARCH} CACHE INTERNAL "LUAJIT INTERNAL - TARGET_LJARCH")
if (TARGET_LJARCH STREQUAL x64 AND NOT URHO3D_64BIT)
set (TARGET_LJARCH x86)
endif ()
else ()
find_string ("LJ_TARGET_(X64|X86|ARM|PPC|PPCSPE|MIPS) 1" TARGET_LJARCH)
if (NOT TARGET_LJARCH)
message (FATAL_ERROR "Unsupported target architecture")
endif ()
if (TARGET_LJARCH STREQUAL mips)
find_string ("MIPSEL (1)" "${TARGET_TESTARCH}" MIPSEL)
find_string ("MIPSEL (1)" MIPSEL)
if (MIPSEL)
set (TARGET_ARCH ${TARGET_ARCH} -D__MIPSEL__=1)
endif ()
endif ()
find_string ("LJ_TARGET_PS3 (1)" "${TARGET_TESTARCH}" PS3)
find_string ("LJ_TARGET_PS3 (1)" PS3)
if (PS3)
set (TARGET_SYS PS3)
set (TARGET_ARCH ${TARGET_ARCH} -D__CELLOS_LV2__)
add_definitions (-DLUAJIT_USE_SYSMALLOC)
endif ()
find_string ("LJ_NO_UNWIND (1)" "${TARGET_TESTARCH}" NO_UNWIND)
find_string ("LJ_NO_UNWIND (1)" NO_UNWIND)
if (NO_UNWIND)
set (TARGET_ARCH ${TARGET_ARCH} -DLUAJIT_NO_UNWIND)
endif ()
@ -96,13 +104,9 @@ set (DASM_DIR ${BAKED_CMAKE_SOURCE_DIR}/Source/ThirdParty/LuaJIT/dynasm)
set (DASM_ARCH ${TARGET_LJARCH})
# Below regex is a workaround for "LJ_ARCH_BITS (.*?)\\n" as CMake does not understand non-greedy quantifier
find_string ("LJ_ARCH_BITS ([^\\n]*)" "${TARGET_TESTARCH}" ARCH_BITS)
find_string ("LJ_ARCH_BITS ([^\\n]*)" ARCH_BITS)
if (ARCH_BITS EQUAL 64)
if (URHO3D_64BIT)
set (DASM_AFLAGS ${DASM_AFLAGS} -D P64)
else ()
set (ARCH_BITS 32)
endif ()
set (DASM_AFLAGS ${DASM_AFLAGS} -D P64)
endif ()
if (TARGET_SYS)
if (MSVC)
@ -113,35 +117,35 @@ if (TARGET_SYS)
endif ()
endif ()
find_string ("LJ_HASJIT (1)" "${TARGET_TESTARCH}" HASJIT)
find_string ("LJ_HASJIT (1)" HASJIT)
if (HASJIT)
set (DASM_AFLAGS ${DASM_AFLAGS} -D JIT)
endif ()
find_string ("LJ_HASFFI (1)" "${TARGET_TESTARCH}" HASFFI)
find_string ("LJ_HASFFI (1)" HASFFI)
if (HASFFI)
set (DASM_AFLAGS ${DASM_AFLAGS} -D FFI)
endif ()
find_string ("LJ_DUALNUM (1)" "${TARGET_TESTARCH}" DUALNUM)
find_string ("LJ_DUALNUM (1)" DUALNUM)
if (DUALNUM)
set (DASM_AFLAGS ${DASM_AFLAGS} -D DUALNUM)
endif ()
find_string ("LJ_ARCH_HASFPU (1)" "${TARGET_TESTARCH}" ARCH_HASFPU)
find_string ("LJ_ARCH_HASFPU (1)" ARCH_HASFPU)
if (ARCH_HASFPU)
set (DASM_AFLAGS ${DASM_AFLAGS} -D FPU)
endif ()
set (TARGET_ARCH ${TARGET_ARCH} -DLJ_ARCH_HASFPU=${ARCH_HASFPU})
find_string ("LJ_ABI_SOFTFP (1)" "${TARGET_TESTARCH}" ABI_SOFTFP)
find_string ("LJ_ABI_SOFTFP (1)" ABI_SOFTFP)
if (NOT ABI_SOFTFP)
set (DASM_AFLAGS ${DASM_AFLAGS} -D HFABI)
endif ()
set (TARGET_ARCH ${TARGET_ARCH} -DLJ_ABI_SOFTFP=${ABI_SOFTFP})
# Below regex is a workaround for "LJ_ARCH_VERSION (.*?)\\n" as CMake does not understand non-greedy quantifier
find_string ("LJ_ARCH_VERSION ([^\\n]*)" "${TARGET_TESTARCH}" ARCH_VERSION)
find_string ("LJ_ARCH_VERSION ([^\\n]*)" ARCH_VERSION)
if (ARCH_VERSION)
set (DASM_AFLAGS ${DASM_AFLAGS} -D VER=${ARCH_VERSION})
else ()
@ -153,7 +157,7 @@ if (TARGET_SYS STREQUAL Windows)
endif ()
if (TARGET_LJARCH STREQUAL x86)
find_string ("__SSE2__ (1)" "${TARGET_TESTARCH}" SSE2)
find_string ("__SSE2__ (1)" SSE2)
if (SSE2)
set (DASM_AFLAGS ${DASM_AFLAGS} -D SSE)
endif ()
@ -164,15 +168,15 @@ elseif (TARGET_LJARCH STREQUAL arm)
set (DASM_AFLAGS ${DASM_AFLAGS} -D IOS)
endif ()
elseif (TARGET_LJARCH STREQUAL ppc)
find_string ("LJ_ARCH_SQRT (1)" "${TARGET_TESTARCH}" ARCH_SQRT)
find_string ("LJ_ARCH_SQRT (1)" ARCH_SQRT)
if (ARCH_SQRT)
set (DASM_AFLAGS ${DASM_AFLAGS} -D SQRT)
endif ()
find_string ("LJ_ARCH_ROUND (1)" "${TARGET_TESTARCH}" ARCH_ROUND)
find_string ("LJ_ARCH_ROUND (1)" ARCH_ROUND)
if (ARCH_ROUND)
set (DASM_AFLAGS ${DASM_AFLAGS} -D ROUND)
endif ()
find_string ("LJ_ARCH_PPC64 (1)" "${TARGET_TESTARCH}" ARCH_PPC64)
find_string ("LJ_ARCH_PPC64 (1)" ARCH_PPC64)
if (ARCH_PPC64)
set (DASM_AFLAGS ${DASM_AFLAGS} -D GPR64)
endif ()

View File

@ -41,7 +41,11 @@ endif ()
# Symlink/copy helper shell scripts or batch files to invoke Urho3DPlayer
if (NOT IOS AND NOT ANDROID)
if (APPLE)
# For some reason CMake is late to create this output directory when on Apple
file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Bin)
endif ()
foreach (FILE Editor NinjaSnowWar)
create_symlink (${CMAKE_SOURCE_DIR}/Bin/${FILE}${SCRIPT_EXT} ${CMAKE_BINARY_DIR}/Bin/${FILE}${SCRIPT_EXT} FALLBACK_TO_COPY)
endforeach ()
endif ()
endif ()