Explorar el Código

Fix initial gradle sync.

Yao Wei Tjong 姚伟忠 hace 7 años
padre
commit
d3508fc246

+ 4 - 1
CMake/Modules/CheckCompilerToolchain.cmake

@@ -159,7 +159,10 @@ macro (check_native_compiler_exist)
         if (NOT EXIT_CODE EQUAL 0)
             message (STATUS "Performing Test HAVE_NATIVE_COMPILER - Failed")
             execute_process (COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/generated/CMakeCache.txt)
-            message (FATAL_ERROR "Could not find native compiler toolchain. This is usually caused by wrong PATH env-var value.\n${ERR_VAR}")
+            if (ANDROID)
+                set (NOT_FOUND_MESSAGE "For Android platform, you probably need to install 'Ninja' build tool globally.")
+            endif ()
+            message (FATAL_ERROR "Could not find native compiler toolchain. This is usually caused by wrong PATH env-var value. ${NOT_FOUND_MESSAGE}\n${ERR_VAR}")
         endif ()
         message (STATUS "Performing Test HAVE_NATIVE_COMPILER - Success")
         set (HAVE_NATIVE_COMPILER 1 CACHE INTERNAL "Check native compiler exist")

+ 3 - 2
CMake/Modules/FindUrho3D.cmake

@@ -239,8 +239,9 @@ else ()
                 execute_process (COMMAND lipo -info ${URHO3D_LIBRARIES} COMMAND grep -cq arm RESULT_VARIABLE SKIP_COMPILE_TEST OUTPUT_QUIET ERROR_QUIET)
             endif ()
             set (COMPILER_FLAGS "${COMPILER_32BIT_FLAG} ${CMAKE_REQUIRED_FLAGS}")
-            if (SKIP_COMPILE_TEST OR URHO3D_LIB_TYPE STREQUAL MODULE)
-                # Module library type cannot be test linked so just assume it is a valid Urho3D module for now
+            if (SKIP_COMPILE_TEST
+                OR URHO3D_LIB_TYPE STREQUAL MODULE                  # Module library type cannot be test linked so just assume it is a valid Urho3D module for now
+                OR CMAKE_PROJECT_NAME STREQUAL Urho3D-Launcher)     # Workaround initial IDE "gradle sync" error due to library has not been built yet
                 set (URHO3D_COMPILE_RESULT 1)
             else ()
                 while (NOT URHO3D_COMPILE_RESULT)

+ 9 - 0
Source/Urho3D/CMakeLists.txt

@@ -555,6 +555,15 @@ if (ANDROID AND GRADLE_BUILD_DIR)
     # Copy the library to URHO3D_HOME directory
     set (ABI_LIB_DIR ${GRADLE_BUILD_DIR}/tree/${CMAKE_BUILD_TYPE}/${ANDROID_ABI}/lib)
     file (MAKE_DIRECTORY ${ABI_LIB_DIR})
+    # Workaround execute_process does not support generator expression
+    if (URHO3D_LIB_TYPE STREQUAL STATIC)
+        set (LIB_EXT .a)
+    else ()
+        set (LIB_EXT .so)
+    endif ()
+    # Put a placeholder during Gradle configuration phase so that initial IDE "gradle sync" works cleanly
+    execute_process (COMMAND ${CMAKE_COMMAND} -E touch ${ABI_LIB_DIR}/lib${TARGET_NAME}${LIB_EXT})
+    # Replace the placeholder with the actual target file during Gradle execution phase
     add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${TARGET_NAME}> ${ABI_LIB_DIR}
         COMMENT "Copying Urho3D library to URHO3D_HOME directory")
     add_make_clean_files (${ABI_LIB_DIR}/$<TARGET_FILE_NAME:${TARGET_NAME}>)

+ 1 - 1
android/launcher-app/CMakeLists.txt

@@ -36,7 +36,7 @@ if (COMMAND cmake_policy)
 endif ()
 
 # Set project name
-project (Launcher)
+project (Urho3D-Launcher)
 
 # Set CMake modules search path
 set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../CMake/Modules)

+ 3 - 0
android/launcher-app/build.gradle.kts

@@ -91,6 +91,9 @@ dependencies {
     androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.2")
 }
 
+// Ensure IDE "gradle sync" evaluate the urho3d-lib module first
+evaluationDependsOn(":android:urho3d-lib")
+
 afterEvaluate {
     tasks {
         getByName("clean") {