Skip to content

Commit

Permalink
Cmake improve git submodule initialization (Mudlet#3171)
Browse files Browse the repository at this point in the history
* Add function to initialize git submodules

* Use function for retrieving git submodules

* Add GPL header
  • Loading branch information
keneanung authored Oct 18, 2019
1 parent b643200 commit f9984eb
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 59 deletions.
88 changes: 29 additions & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,71 +145,41 @@ else()
# and it is not obvious that there is a demand to do this currenly.
endif()

if(NOT EXISTS "${CMAKE_HOME_DIRECTORY}/3rdparty/edbee-lib/CMakeLists.txt")
# The above CMakeList.txt is the top level one - we actually use the one
# another level down in 3rdparty/edbee-lib/edbee-lib/CMakeLists.txt
message(STATUS "git submodule for required edbee-lib editor widget missing from source code, will attempt to get it...")
execute_process(COMMAND git submodule update --init 3rdparty/edbee-lib
TIMEOUT 30
WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
OUTPUT_VARIABLE output_text
ERROR_VARIABLE error_text)
if(output_text OR error_text)
message(STATUS ${output_text} ${error_text})
endif()
endif()

if(NOT EXISTS "${CMAKE_HOME_DIRECTORY}/3rdparty/qtkeychain/CMakeLists.txt")
message(STATUS "git submodule for required QtKeychain missing from source code, will attempt to get it...")
execute_process(COMMAND git submodule update --init 3rdparty/qtkeychain
TIMEOUT 30
WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
OUTPUT_VARIABLE output_text
ERROR_VARIABLE error_text)
if(output_text OR error_text)
message(STATUS ${output_text} ${error_text})
endif()
endif()

if(NOT EXISTS "${CMAKE_HOME_DIRECTORY}/3rdparty/lcf/lcf-scm-1.rockspec")
message(STATUS "git submodule for required lua code formatter source code missing, will attempt to get it...")
execute_process(COMMAND git submodule update --init 3rdparty/lcf
TIMEOUT 30
WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
OUTPUT_VARIABLE output_text
ERROR_VARIABLE error_text)
if(output_text OR error_text)
message(STATUS ${output_text} ${error_text})
endif()
endif()
include(InitGitSubmodule)

git_submodule_init(
CHECK_FILE "3rdparty/edbee-lib/CMakeLists.txt"
SUBMODULE_PATH "3rdparty/edbee-lib"
READABLE_NAME "edbee-lib editor widget"
)

git_submodule_init(
CHECK_FILE "3rdparty/qtkeychain/CMakeLists.txt"
SUBMODULE_PATH "3rdparty/qtkeychain"
READABLE_NAME "QtKeychain"
)

git_submodule_init(
CHECK_FILE "3rdparty/lcf/lcf-scm-1.rockspec"
SUBMODULE_PATH "3rdparty/lcf"
READABLE_NAME "lua code formatter source code"
)

if(USE_UPDATER)
if(NOT EXISTS "${CMAKE_HOME_DIRECTORY}/3rdparty/dblsqd/CMakeLists.txt")
message(STATUS "git submodule for optional but wanted DBLSQD updater missing from source code, will attempt to get it...")
execute_process(COMMAND git submodule update --init 3rdparty/dblsqd
TIMEOUT 30
WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
OUTPUT_VARIABLE output_text
ERROR_VARIABLE error_text)
if(output_text OR error_text)
message(STATUS ${output_text} ${error_text})
endif()
endif()
git_submodule_init(
CHECK_FILE "3rdparty/dblsqd/CMakeLists.txt"
SUBMODULE_PATH "3rdparty/dblsqd"
READABLE_NAME "DBLSQD updater"
)
endif()

if(APPLE)
if(USE_UPDATER)
if(NOT EXISTS "${CMAKE_HOME_DIRECTORY}/3rdparty/sparkle-glue/CMakeLists.txt")
message(STATUS "git submodule for optional but wanted Sparkle glue for updater missing from source code, will attempt to get it...")
execute_process(COMMAND git submodule update --init 3rdparty/sparkle-glue
TIMEOUT 30
WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
OUTPUT_VARIABLE output_text
ERROR_VARIABLE error_text)
if(output_text OR error_text)
message(STATUS ${output_text} ${error_text})
endif()
endif()
git_submodule_init(
CHECK_FILE "3rdparty/sparkle-glue/CMakeLists.txt"
SUBMODULE_PATH "3rdparty/sparkle-glue"
READABLE_NAME "Sparkle glue for updater"
)

if(NOT EXISTS "${CMAKE_HOME_DIRECTORY}/3rdparty/cocoapods/Pods/Sparkle")
message(STATUS "Sparkle CocoaPod is missing, running 'pod install' to get it...")
Expand Down
68 changes: 68 additions & 0 deletions cmake/InitGitSubmodule.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
###########################################################################
# Copyright (C) 2019 Florian Scheel - keneanung@gmail.com #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the #
# Free Software Foundation, Inc., #
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
###########################################################################

###########################################################################
#
# Exports a function to initialize a git
# submodule if it is not there yet.
#
# Usage:
# git_submodule_init(
# CHECK_FILE "path/to/file/to/check"
# SUBMODULE_PATH "path/to/submodule"
# READABLE_NAME "submodule name"
# )
###########################################################################

find_package(Git REQUIRED QUIET)

function(git_submodule_init)

# parse readable arguments
set(OPTIONS "") # not used
set(ONE_VALUE_ARGS CHECK_FILE SUBMODULE_PATH READABLE_NAME)
set(MULTI_VALUE_ARGS "") # not used
cmake_parse_arguments(GIT_SM "${OPTIONS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN})

# check arguments for existence
if(NOT GIT_SM_CHECK_FILE)
message(FATAL_ERROR "Function git_submodule_init(): Required argument 'CHECK_FILE' missing.")
endif()
if(NOT GIT_SM_SUBMODULE_PATH)
message(FATAL_ERROR "Function git_submodule_init(): Required argument 'SUBMODULE_PATH' missing.")
endif()
if(NOT GIT_SM_READABLE_NAME)
message(FATAL_ERROR "Function git_submodule_init(): Required argument 'READABLE_NAME' missing.")
endif()

# actual code
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${GIT_SM_CHECK_FILE}")
message(STATUS "git submodule for ${GIT_SM_READABLE_NAME} missing from source code, will attempt to get it...")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init "${GIT_SM_SUBMODULE_PATH}"
TIMEOUT 30
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE result
OUTPUT_VARIABLE output_text
ERROR_VARIABLE error_text)
if(NOT result EQUAL "0")
message(FATAL_ERROR ${output_text} ${error_text})
endif()
endif()

endfunction(git_submodule_init)

0 comments on commit f9984eb

Please sign in to comment.