Browse Source

Optional submodules

Rokas Kupstys 8 years ago
parent
commit
2152ba1df4
3 changed files with 37 additions and 34 deletions
  1. 9 17
      Build/CMake/Modules/AtomicDesktop.cmake
  2. 24 16
      Build/CMake/Modules/AtomicGit.cmake
  3. 4 1
      CMakeLists.txt

+ 9 - 17
Build/CMake/Modules/AtomicDesktop.cmake

@@ -1,22 +1,14 @@
 set(ATOMIC_DESKTOP TRUE)
 
 # Check whether the CEF submodule is available
-if (NOT MINGW AND NOT DEFINED ATOMIC_WEBVIEW AND EXISTS ${ATOMIC_SOURCE_DIR}/Submodules/CEF)
-    #Check if CEF got pulled by looking if the foldes is empty
-    file(GLOB CEF_FILES ${ATOMIC_SOURCE_DIR}/Submodules/CEF/*)
-
-    list(LENGTH CEF_FILES CEF_FILES_LEN)
-    if (CEF_FILES_LEN EQUAL 0)
-        message(STATUS "Initialising CEF submodule")
-
-        find_package(Git REQUIRED)
-        if (GIT_FOUND)
-            execute_process(COMMAND git submodule update --init --remote)
-        else ()
-            message(STATUS "Could not find git in your Path. Please install git")
-        endif (GIT_FOUND)
+if (NOT MINGW)
+    if (NOT DEFINED ATOMIC_WEBVIEW)
+        set (ATOMIC_WEBVIEW ON)
+    endif ()
+    if (ATOMIC_WEBVIEW)
+        initialize_submodule(Submodules/CEF ATOMIC_WEBVIEW)
+        if (ATOMIC_WEBVIEW)
+            add_definitions(-DATOMIC_WEBVIEW)
+        endif ()
     endif ()
-    set(ATOMIC_WEBVIEW TRUE)
-    add_definitions(-DATOMIC_WEBVIEW)
 endif ()
-

+ 24 - 16
Build/CMake/Modules/AtomicGit.cmake

@@ -1,18 +1,26 @@
 
-# If submodules aren't initialized, look for git and initialize
-if (NOT EXISTS ${ATOMIC_SOURCE_DIR}/Submodules/CEF/.git OR NOT EXISTS ${ATOMIC_SOURCE_DIR}/Submodules/AtomicExamples/.git)
-    find_package(Git)
-    if (GIT_FOUND)
-        message("\n\nUpdating submodules, please wait...\n\n")
-        execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init
-            WORKING_DIRECTORY ${ATOMIC_SOURCE_DIR}
-            RESULT_VARIABLE ATOMIC_GIT_STATUS)
-        # check return status
-        if (NOT ATOMIC_GIT_STATUS EQUAL 0)
-            message(FATAL_ERROR "BUILD ERROR:\n\nError initializing submodules: git submodule update --init returned ${ATOMIC_GIT_STATUS}\n")
-        endif ()
-    else ()
-        # Git not found
-        message(FATAL_ERROR "BUILD ERROR:\n\Submodules not initialized, please run: git submodule update --init\n")
+macro (initialize_submodule target_dir result_variable)
+    file(GLOB SUBMODULE_FILES ${target_dir}/*)
+    list(LENGTH SUBMODULE_FILES SUBMODULE_FILES_LEN)
+
+    if (SUBMODULE_FILES_LEN LESS 2)
+        message(STATUS "Initialising ${target_dir}")
+        find_package(Git REQUIRED)
+        if (GIT_FOUND)
+            execute_process(
+                COMMAND git submodule update --init --remote "${target_dir}"
+                WORKING_DIRECTORY ${ATOMIC_SOURCE_DIR}
+                RESULT_VARIABLE SUBMODULE_RESULT
+            )
+            if (SUBMODULE_RESULT EQUAL 0)
+                set (${result_variable} ON)
+                message(INFO "Initialized ${target_dir}")
+            else ()
+                set (${result_variable} OFF)
+                message(WARNING "Running git returned an error.")
+            endif ()
+        else ()
+            message(STATUS "Could not find git in your Path. Please install git.")
+        endif (GIT_FOUND)
     endif ()
-endif ()
+endmacro ()

+ 4 - 1
CMakeLists.txt

@@ -67,6 +67,9 @@ if (ATOMIC_DESKTOP AND ATOMIC_DEV_BUILD)
         set(ATOMIC_CPLUSPLUS_EXAMPLES 1)
     endif ()
     if (ATOMIC_CPLUSPLUS_EXAMPLES)
-        add_subdirectory(Submodules/AtomicExamples/FeatureExamples/CPlusPlus)
+        initialize_submodule(${ATOMIC_SOURCE_DIR}/Submodules/AtomicExamples ATOMIC_CPLUSPLUS_EXAMPLES)
+        if (ATOMIC_CPLUSPLUS_EXAMPLES)
+            add_subdirectory(Submodules/AtomicExamples/FeatureExamples/CPlusPlus)
+        endif ()
     endif ()
 endif ()