summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt19
-rw-r--r--cmake/Coverity.cmake35
-rw-r--r--cmake/GitFunctions.cmake37
3 files changed, 77 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d804e730..15f9a13d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -179,20 +179,9 @@ endif()
ADD_CUSTOM_TARGET(version echo "Version: ${MultiMC_VERSION_STRING}")
#### Check the current Git commit
-execute_process(COMMAND git rev-parse HEAD
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
- RESULT_VARIABLE GIT_COMMIT_CHECK_RESULTVAR
- OUTPUT_VARIABLE GIT_COMMIT_CHECK_OUTVAR
- OUTPUT_STRIP_TRAILING_WHITESPACE
-)
-
-IF(GIT_COMMIT_CHECK_RESULTVAR EQUAL 0)
- SET(MultiMC_GIT_COMMIT "${GIT_COMMIT_CHECK_OUTVAR}")
- MESSAGE(STATUS "Git commit: ${MultiMC_GIT_COMMIT}")
-ELSE()
- SET(MultiMC_GIT_COMMIT "Unknown")
- MESSAGE(STATUS "Failed to check Git commit. ${GIT_COMMIT_CHECK_RESULTVAR}")
-ENDIF()
+include(GitFunctions)
+git_run(COMMAND rev-parse HEAD DEFAULT "Unknown" OUTPUT_VAR MultiMC_GIT_COMMIT)
+message(STATUS "Git commit: ${MultiMC_GIT_COMMIT}")
OPTION(MultiMC_CODE_COVERAGE "Compiles for code coverage" OFF)
IF(MultiMC_CODE_COVERAGE)
@@ -789,6 +778,8 @@ ENDIF()
INCLUDE(CPack)
+include(Coverity)
+
include_directories(${PROJECT_BINARY_DIR}/include)
# Translations
diff --git a/cmake/Coverity.cmake b/cmake/Coverity.cmake
new file mode 100644
index 00000000..899d9852
--- /dev/null
+++ b/cmake/Coverity.cmake
@@ -0,0 +1,35 @@
+if(__COVERITY_CMAKE__)
+ return()
+endif()
+set(__COVERITY_CMAKE__ TRUE)
+
+include(GitFunctions)
+
+git_run(COMMAND config --get user.email DEFAULT "" OUTPUT_VAR GIT_EMAIL)
+git_run(COMMAND describe DEFAULT "" OUTPUT_VAR GIT_VERSION)
+
+set(MultiMC_COVERITY_TOKEN "" CACHE STRING "Coverity access token")
+set(MultiMC_COVERITY_EMAIL "${GIT_EMAIL}" CACHE STRING "Coverity email")
+
+set(MultiMC_COVERITY_TOOLS_DIR "${CMAKE_BINARY_DIR}/coverity_tools" CACHE PATH "Path to the coverity tools")
+
+find_program(CURL_EXECUTABLE NAMES curl PATHS /usr/bin)
+
+if(NOT CURL_EXECUTABLE STREQUAL "" AND NOT MultiMC_COVERITY_TOKEN STREQUAL "" AND NOT MultiMC_COVERITY_EMAIL STREQUAL "")
+ add_custom_target(coverity_configure
+ COMMAND ${MultiMC_COVERITY_TOOLS_DIR}/bin/cov-configure --comptype gcc --compiler ${CMAKE_C_COMPILER}
+ )
+ add_custom_target(coverity_create_tarball
+ COMMAND ${CMAKE_COMMAND} -E echo "Cleaning..." && ${CMAKE_MAKE_PROGRAM} clean
+ COMMAND ${CMAKE_COMMAND} -E echo "Building..." && ${MultiMC_COVERITY_TOOLS_DIR}/bin/cov-build --dir cov-int ${CMAKE_MAKE_PROGRAM} -j3
+ COMMAND ${CMAKE_COMMAND} -E echo "Creating tarball..." && ${CMAKE_COMMAND} -E tar cfz multimc_coverity.tgz cov-int/
+ COMMENT "Creating coverity build..."
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ )
+ add_custom_target(coverity_upload
+ COMMAND ${CURL_EXECUTABLE} --form project=02JanDal/MultiMC5 --form token=${MultiMC_COVERITY_TOKEN} --form email=${MultiMC_COVERITY_EMAIL} --form file=@multimc_coverity.tgz --form version=${MultiMC_GIT_COMMIT} --form description=${GIT_VERSION} http://scan5.coverity.com/cgi-bin/upload.py
+ DEPENDS coverity_create_tarball
+ COMMENT "Uploading to coverity..."
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ )
+endif()
diff --git a/cmake/GitFunctions.cmake b/cmake/GitFunctions.cmake
new file mode 100644
index 00000000..e0868725
--- /dev/null
+++ b/cmake/GitFunctions.cmake
@@ -0,0 +1,37 @@
+if(__GITFUNCTIONS_CMAKE__)
+ return()
+endif()
+set(__GITFUNCTIONS_CMAKE__ TRUE)
+
+find_package(Git QUIET)
+
+include(CMakeParseArguments)
+
+if(GIT_FOUND)
+ function(git_run)
+ set(oneValueArgs OUTPUT_VAR DEFAULT)
+ set(multiValueArgs COMMAND)
+ cmake_parse_arguments(GIT_RUN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ execute_process(COMMAND ${GIT_EXECUTABLE} ${GIT_RUN_COMMAND}
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ RESULT_VARIABLE GIT_RESULTVAR
+ OUTPUT_VARIABLE GIT_OUTVAR
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+
+ if(GIT_RESULTVAR EQUAL 0)
+ set(${GIT_RUN_OUTPUT_VAR} "${GIT_OUTVAR}" PARENT_SCOPE)
+ else()
+ set(${GIT_RUN_OUTPUT_VAR} ${GIT_RUN_DEFAULT})
+ message(STATUS "Failed to run Git: ${GIT_OUTVAR}")
+ endif()
+ endfunction()
+else()
+ function(git_run)
+ set(oneValueArgs OUTPUT_VAR DEFAULT)
+ set(multiValueArgs COMMAND)
+ cmake_parse_arguments(GIT_RUN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+ set(${GIT_RUN_OUTPUT_VAR} ${GIT_RUN_DEFAULT})
+ endfunction(git_run)
+endif()