Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Corryvreckan
Corryvreckan
Commits
067dbc78
Commit
067dbc78
authored
Oct 06, 2017
by
Simon Spannagel
Browse files
add cmake tools
parent
864aab92
Changes
4
Hide whitespace changes
Inline
Side-by-side
cmake/clang-cpp-checks.cmake
0 → 100644
View file @
067dbc78
# Additional targets to perform clang-format/clang-tidy
# Get all project files - FIXME: this should also use the list of generated targets
IF
(
NOT CHECK_CXX_SOURCE_FILES
)
MESSAGE
(
FATAL_ERROR
"Variable CHECK_CXX_SOURCE_FILES not defined - set it to the list of files to auto-format"
)
RETURN
()
ENDIF
()
# Adding clang-format check and formatter if found
FIND_PROGRAM
(
CLANG_FORMAT
"clang-format"
)
IF
(
CLANG_FORMAT
)
ADD_CUSTOM_TARGET
(
format
COMMAND
${
CLANG_FORMAT
}
-i
-style=file
${
CHECK_CXX_SOURCE_FILES
}
COMMENT
"Auto formatting of all source files"
)
ADD_CUSTOM_TARGET
(
check-format
COMMAND
${
CLANG_FORMAT
}
-style=file
-output-replacements-xml
${
CHECK_CXX_SOURCE_FILES
}
# print output
| tee
${
CMAKE_BINARY_DIR
}
/check_format_file.txt | grep -c
"replacement "
|
tr -d
"[:cntrl:]"
&& echo
" replacements necessary"
# WARNING: fix to stop with error if there are problems
COMMAND ! grep -c
"replacement "
${
CMAKE_BINARY_DIR
}
/check_format_file.txt > /dev/null
COMMENT
"Checking format compliance"
)
ENDIF
()
# Adding clang-tidy target if executable is found
SET
(
CXX_STD 11
)
IF
(
${
CMAKE_CXX_STANDARD
}
)
SET
(
CXX_STD
${
CMAKE_CXX_STANDARD
}
)
ENDIF
()
FIND_PROGRAM
(
CLANG_TIDY
"clang-tidy"
)
# Enable clang tidy only if using a clang compiler
IF
(
CLANG_TIDY AND CMAKE_CXX_COMPILER_ID STREQUAL
"Clang"
)
# If debug build enabled do automatic clang tidy
IF
(
CMAKE_BUILD_TYPE MATCHES Debug
)
SET
(
CMAKE_CXX_CLANG_TIDY
${
CLANG_TIDY
}
"-header-filter='
${
CMAKE_SOURCE_DIR
}
'"
)
ENDIF
()
# Enable checking and formatting through run-clang-tidy if available
# FIXME Make finding this program more portable
GET_FILENAME_COMPONENT
(
CLANG_DIR
${
CLANG_TIDY
}
DIRECTORY
)
FIND_PROGRAM
(
RUN_CLANG_TIDY NAMES
"run-clang-tidy.py"
"run-clang-tidy-4.0.py"
HINTS /usr/share/clang/
${
CLANG_DIR
}
/../share/clang/ /usr/bin/
)
IF
(
RUN_CLANG_TIDY
)
# Set export commands on
SET
(
CMAKE_EXPORT_COMPILE_COMMANDS ON
)
# Get amount of processors to speed up linting
INCLUDE
(
ProcessorCount
)
ProcessorCount
(
NPROC
)
IF
(
NPROC EQUAL 0
)
SET
(
NPROC 1
)
ENDIF
()
ADD_CUSTOM_TARGET
(
lint COMMAND
${
RUN_CLANG_TIDY
}
-fix -format -header-filter=
${
CMAKE_SOURCE_DIR
}
-j
${
NPROC
}
COMMENT
"Auto fixing problems in all source files"
)
ADD_CUSTOM_TARGET
(
check-lint COMMAND
${
RUN_CLANG_TIDY
}
-header-filter=
${
CMAKE_SOURCE_DIR
}
-j
${
NPROC
}
| tee
${
CMAKE_BINARY_DIR
}
/check_lint_file.txt
# WARNING: fix to stop with error if there are problems
COMMAND ! grep -c
": error: "
${
CMAKE_BINARY_DIR
}
/check_lint_file.txt > /dev/null
COMMENT
"Checking for problems in source files"
)
ENDIF
()
ENDIF
()
cmake/compiler-flag-checks.cmake
0 → 100644
View file @
067dbc78
# Check for supported flags and remove unsupported warnings
INCLUDE
(
CheckCXXCompilerFlag
)
FOREACH
(
FLAG
${
COMPILER_FLAGS
}
)
STRING
(
REPLACE
"-"
"_"
FLAG_WORD
${
FLAG
}
)
STRING
(
REPLACE
"+"
"P"
FLAG_WORD
${
FLAG_WORD
}
)
STRING
(
REPLACE
"="
"E"
FLAG_WORD
${
FLAG_WORD
}
)
CHECK_CXX_COMPILER_FLAG
(
"
${
FLAG
}
"
CXX_FLAG_WORKS_
${
FLAG_WORD
}
)
IF
(
${
CXX_FLAG_WORKS_
${
FLAG_WORD
}}
)
SET
(
CMAKE_CXX_FLAGS
"
${
FLAG
}
${
CMAKE_CXX_FLAGS
}
"
)
ELSE
()
MESSAGE
(
STATUS
"NOT adding
${
FLAG
}
to CXX_FLAGS - unsupported flag"
)
ENDIF
()
ENDFOREACH
()
# Find threading provider and enable it (NOTE: not used yet)
IF
(
THREADS_HAVE_PTHREAD_ARG
)
SET
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-pthread"
)
SET
(
CMAKE_SHARED_LINKER_FLAGS
"
${
CMAKE_SHARED_LINKER_FLAGS
}
-pthread"
)
ELSEIF
(
CMAKE_THREAD_LIBS_INIT
)
SET
(
CMAKE_SHARED_LINKER_FLAGS
"
${
CMAKE_SHARED_LINKER_FLAGS
}
${
CMAKE_THREAD_LIBS_INIT
}
"
)
ENDIF
()
# Set no undefined symbols flag for the linker if supported
IF
((
CMAKE_CXX_COMPILER_ID STREQUAL
"Clang"
)
OR
(
CMAKE_CXX_COMPILER_ID STREQUAL
"GNU"
))
SET
(
CMAKE_SHARED_LINKER_FLAGS
"
${
CMAKE_SHARED_LINKER_FLAGS
}
-Wl,--no-undefined"
)
ENDIF
()
IF
(
CMAKE_CXX_COMPILER_ID STREQUAL
"AppleClang"
)
SET
(
CMAKE_SHARED_LINKER_FLAGS
"
${
CMAKE_SHARED_LINKER_FLAGS
}
-Wl,-undefined,error"
)
ENDIF
()
# Reduce Wstrict-overflow level for some GCC versions due to false positives:
IF
(
CMAKE_CXX_COMPILER_ID STREQUAL
"GNU"
)
IF
(
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0
)
SET
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wstrict-overflow=2"
)
ENDIF
()
ENDIF
()
cmake/config.cmake.h
0 → 100644
View file @
067dbc78
#pragma once
// CMake uses config.cmake.h to generate config.h within the build folder.
#ifndef CORRYVRECKAN_CONFIG_H
#define CORRYVRECKAN_CONFIG_H
#define PACKAGE_NAME "@CMAKE_PROJECT_NAME@"
#define PACKAGE_VERSION "@CORRYVRECKAN_LIB_VERSION@"
#define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION
#endif
cmake/tools.cmake
0 → 100644
View file @
067dbc78
# Retrieve the project version string from git describe
FUNCTION
(
get_version PROJECT_VERSION
)
# Check if this is a source tarball build
IF
(
NOT IS_DIRECTORY
${
CMAKE_SOURCE_DIR
}
/.git
)
SET
(
SOURCE_PACKAGE 1
)
ENDIF
(
NOT IS_DIRECTORY
${
CMAKE_SOURCE_DIR
}
/.git
)
# Set package version
IF
(
NOT SOURCE_PACKAGE
)
# Get the version from last git tag plus number of additional commits:
FIND_PACKAGE
(
Git QUIET
)
IF
(
GIT_FOUND
)
EXEC_PROGRAM
(
git
${
CMAKE_CURRENT_SOURCE_DIR
}
ARGS describe --tags HEAD OUTPUT_VARIABLE
${
PROJECT_VERSION
}
)
STRING
(
REGEX REPLACE
"^release-"
""
${
PROJECT_VERSION
}
${${
PROJECT_VERSION
}}
)
STRING
(
REGEX REPLACE
"([v0-9.]+)-([0-9]+)-([A-Za-z0-9]+)"
"
\\
1+
\\
2^
\\
3"
${
PROJECT_VERSION
}
${${
PROJECT_VERSION
}}
)
EXEC_PROGRAM
(
git ARGS status --porcelain
${
CMAKE_CURRENT_SOURCE_DIR
}
OUTPUT_VARIABLE PROJECT_STATUS
)
IF
(
PROJECT_STATUS STREQUAL
""
)
MESSAGE
(
STATUS
"Git project directory is clean."
)
ELSE
(
PROJECT_STATUS STREQUAL
""
)
MESSAGE
(
STATUS
"Git project directory is dirty:
\n
${
PROJECT_STATUS
}
."
)
ENDIF
(
PROJECT_STATUS STREQUAL
""
)
ELSE
(
GIT_FOUND
)
MESSAGE
(
STATUS
"Git repository present, but could not find git executable."
)
ENDIF
(
GIT_FOUND
)
ELSE
(
NOT SOURCE_PACKAGE
)
# If we don't have git we can not really do anything
MESSAGE
(
STATUS
"Source tarball build - no repository present."
)
ENDIF
(
NOT SOURCE_PACKAGE
)
# Set the project version in the parent scope
SET
(
${
PROJECT_VERSION
}
${${
PROJECT_VERSION
}}
PARENT_SCOPE
)
ENDFUNCTION
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment