Commit 828da97d authored by Alexis Girault's avatar Alexis Girault
Browse files

ENH: Add Superbuild and build KWStyle

parent 1c918b9b
#-----------------------------------------------------------------------------
# Define and configure configuration files
#-----------------------------------------------------------------------------
set(kwstyle_configuration_file "Utilities/KWStyle/${PROJECT_NAME}.kws.xml")
set(kwstyle_overwrite_file "Utilities/KWStyle/KWStyleOverwrite.txt")
set(kwstyle_examples_files_list_file "Utilities/KWStyle/${PROJECT_NAME}ExamplesFiles.txt")
configure_file(
${CMAKE_SOURCE_DIR}/${kwstyle_examples_files_list_file}.in
${CMAKE_BINARY_DIR}/${kwstyle_examples_files_list_file}
)
#-----------------------------------------------------------------------------
# Setup git hook for KWStyle executable path
#-----------------------------------------------------------------------------
find_package(Git)
if(GIT_FOUND)
if(EXISTS "${KWSTYLE_EXECUTABLE}")
message(STATUS "KWStyle found: enabling in git hook")
execute_process(COMMAND ${GIT_EXECUTABLE} config kws.path "${KWSTYLE_EXECUTABLE}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(COMMAND ${GIT_EXECUTABLE} config kws.conf "${kwstyle_configuration_file}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(COMMAND ${GIT_EXECUTABLE} config kws.overwriteRulesConf "${kwstyle_overwrite_file}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process( COMMAND ${GIT_EXECUTABLE} config kws.enabled true
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
else()
message(STATUS "KWStyle not found: disabling in git hook")
execute_process(COMMAND ${GIT_EXECUTABLE} config --unset kws.path
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(COMMAND ${GIT_EXECUTABLE} config --unset kws.conf
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(COMMAND ${GIT_EXECUTABLE} config --unset kws.overwriteRulesConf
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
execute_process(COMMAND ${GIT_EXECUTABLE} config kws.enabled false
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
endif()
#-----------------------------------------------------------------------------
# Define formatting options for error messages of build target output
#-----------------------------------------------------------------------------
option(KWSTYLE_USE_VIM_FORMAT
"Set KWStyle to generate errors with a VIM-compatible format."
OFF
)
option(KWSTYLE_USE_GCC_FORMAT
"Set KWStyle to generate errors with a GCC-compatible format."
OFF
)
option(KWSTYLE_USE_MSVC_FORMAT
"Set KWStyle to generate errors with a VisualStudio-compatible format."
${MSVC_IDE} # default to TRUE only with a Visual Studio IDE
)
mark_as_advanced(KWSTYLE_USE_VIM_FORMAT)
mark_as_advanced(KWSTYLE_USE_GCC_FORMAT)
mark_as_advanced(KWSTYLE_USE_MSVC_FORMAT)
#-----------------------------------------------------------------------------
# Define Editor format
#-----------------------------------------------------------------------------
set(kwstyle_editor_format "")
if(KWSTYLE_USE_VIM_FORMAT)
list(APPEND kwstyle_editor_format -vim)
endif()
if(KWSTYLE_USE_GCC_FORMAT)
list(APPEND kwstyle_editor_format -gcc)
endif()
if(KWSTYLE_USE_MSVC_FORMAT)
list(APPEND kwstyle_editor_format -msvc)
endif()
#-----------------------------------------------------------------------------
# Check only one format is set to TRUE
#-----------------------------------------------------------------------------
list(LENGTH kwstyle_editor_format kwstyle_editor_format_length)
if(kwstyle_editor_format_length GREATER 1)
message(FATAL_ERROR "At most, only one of KWSTYLE_USE_*_FORMAT can be set to TRUE.")
endif()
#-----------------------------------------------------------------------------
# Add build target for examples
#-----------------------------------------------------------------------------
add_custom_target(KWStyleCheckExamples
COMMAND ${KWSTYLE_EXECUTABLE}
-xml ${CMAKE_SOURCE_DIR}/${kwstyle_configuration_file}
-o ${CMAKE_SOURCE_DIR}/${kwstyle_overwrite_file}
-D ${CMAKE_BINARY_DIR}/${kwstyle_examples_files_list_file}
-v
${kwstyle_editor_format}
COMMENT
"Examples Style Checker"
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR} # the paths in kwstyle_configuration_file are relative
)
#-----------------------------------------------------------------------------
# Find KWStyle executable
#-----------------------------------------------------------------------------
find_program(
KWSTYLE_EXECUTABLE
NAMES KWStyle
DOC "Path to the KWStyle executable"
)
mark_as_advanced(KWSTYLE_EXECUTABLE)
#-----------------------------------------------------------------------------
# Check KWstyle version
#-----------------------------------------------------------------------------
if(KWSTYLE_EXECUTABLE)
execute_process(
COMMAND ${KWSTYLE_EXECUTABLE} -version
OUTPUT_VARIABLE KWSTYLE_VERSION_STRING
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(KWSTYLE_VERSION_STRING)
# string(REPLACE ..) fails if the input is an empty string
string(REPLACE
"Version: "
""
KWSTYLE_VERSION_STRING
${KWSTYLE_VERSION_STRING}
)
else()
# CMake's find_package_handle_standard_args has a bug where the
# version empty string ("") is always acceptable
set(KWSTYLE_VERSION_STRING "?")
endif()
endif()
#-----------------------------------------------------------------------------
# Find package
#-----------------------------------------------------------------------------
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
KWStyle
REQUIRED_VARS KWSTYLE_EXECUTABLE
VERSION_VAR KWSTYLE_VERSION_STRING
)
include(ExternalProject)
#-----------------------------------------------------------------------------
# Set KWStyle Git info
#-----------------------------------------------------------------------------
set(KWStyle_GIT_REPOSITORY "${git_protocol}://github.com/Kitware/KWStyle.git")
set(KWStyle_GIT_TAG "ef373a1ece313e9d096948e639bfb575f052f581")
#-----------------------------------------------------------------------------
# Set KWStyle directories
#-----------------------------------------------------------------------------
set(KWStyle_SOURCE_DIR ${CMAKE_BINARY_DIR}/Superbuild/KWStyle)
set(KWStyle_DIR ${CMAKE_BINARY_DIR}/Superbuild/KWStyle-build)
set(KWSTYLE_EXECUTABLE ${KWStyle_DIR}/KWStyle)
#-----------------------------------------------------------------------------
# Always build KWStyle on release mode
#-----------------------------------------------------------------------------
set(_build_configuration_arg -DCMAKE_BUILD_TYPE=Release)
#-----------------------------------------------------------------------------
# Download and build KWStyle
#-----------------------------------------------------------------------------
ExternalProject_add(KWStyle
GIT_REPOSITORY ${KWStyle_GIT_REPOSITORY}
GIT_TAG ${KWStyle_GIT_TAG}
UPDATE_COMMAND ""
INSTALL_COMMAND ""
DOWNLOAD_DIR ${KWStyle_SOURCE_DIR}
SOURCE_DIR ${KWStyle_SOURCE_DIR}
BINARY_DIR ${KWStyle_DIR}
INSTALL_DIR ${KWStyle_DIR}
LOG_DOWNLOAD 1
LOG_UPDATE 0
LOG_CONFIGURE 0
LOG_BUILD 0
LOG_TEST 0
LOG_INSTALL 0
CMAKE_GENERATOR ${gen}
CMAKE_ARGS
-DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_COMPILER_ARG1:STRING=${CMAKE_CXX_COMPILER_ARG1}
-DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
-DCMAKE_C_COMPILER_ARG1:STRING=${CMAKE_C_COMPILER_ARG1}
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
${_build_configuration_arg}
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
-DBUILD_TESTING:BOOL=OFF
)
......@@ -7,6 +7,7 @@ project(iMSTK VERSION 0.0.1 LANGUAGES CXX)
#-----------------------------------------------------------------------------
set(CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/CMake
${CMAKE_CURRENT_SOURCE_DIR}/CMake/Superbuild
${CMAKE_MODULE_PATH}
)
set(${PROJECT_NAME}_CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
......@@ -56,6 +57,46 @@ else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
#-----------------------------------------------------------------------------
# Define ThirdParty dependencies
#-----------------------------------------------------------------------------
# KWStyle
option(${PROJECT_NAME}_USE_KWSTYLE "Use KWStyle to check for coding standards violations." ON)
option(USE_SYSTEM_KWSTYLE "Exclude KWStyle from superbuild and use an existing build." OFF)
mark_as_advanced(USE_SYSTEM_KWSTYLE)
#-----------------------------------------------------------------------------
# Git protocol option
#-----------------------------------------------------------------------------
if(NOT GIT_EXECUTABL )
find_package(Git REQUIRED)
endif()
option(${PROJECT_NAME}_USE_GIT_PROTOCOL "If behind a firewall turn this OFF to use http instead." ON)
set(git_protocol "git")
if(NOT ${PROJECT_NAME}_USE_GIT_PROTOCOL)
set(git_protocol "http")
endif()
#-----------------------------------------------------------------------------
# Superbuild
#-----------------------------------------------------------------------------
option(${PROJECT_NAME}_SUPERBUILD "Build ${PROJECT_NAME} and the projects it depends on." ON)
mark_as_advanced(${PROJECT_NAME}_SUPERBUILD)
set(${PROJECT_NAME}_BINARY_INNER_SUBDIR ${PROJECT_NAME}-build)
if(${PROJECT_NAME}_SUPERBUILD)
include(External_KWStyle)
endif()
#-----------------------------------------------------------------------------
# Include ThirdParty dependencies
#-----------------------------------------------------------------------------
# KWStyle
if(${PROJECT_NAME}_USE_KWSTYLE)
include(ConfigKWStyle)
endif()
#--------------------------------------------------------------------------
# Add Source code subdirectories
#--------------------------------------------------------------------------
......
<?xml version="1.0" encoding="iso-8859-1"?>
<Description>
<LineLength>100</LineLength>
<DeclarationOrder>
<public>0</public>
<protected>1</protected>
<private>2</private>
</DeclarationOrder>
<Typedefs>
<regex>[A-Z]</regex>
</Typedefs>
<InternalVariables>
<regex>m_[a-z]</regex>
<alignment>1</alignment>
</InternalVariables>
<Functions>
<regex>[a-z]</regex>
<length>100</length>
</Functions>
<SemicolonSpace>0</SemicolonSpace>
<EndOfFileNewLine>true</EndOfFileNewLine>
<Tabs>true</Tabs>
<Spaces>0</Spaces>
<Indent>
<type>SPACE</type>
<size>4</size>
<noHeader>true</noHeader>
<allowBlockLine>true</allowBlockLine>
</Indent>
<Operator>
<spaceBefore>1</spaceBefore>
<spaceAfter>1</spaceAfter>
</Operator>
<Comments>
<begin>/**</begin>
<middle> *</middle>
<end>*/<end>
<emptyLineBeforeClass>true</emptyLineBeforeClass>
<checkWrongComment>true</checkWrongComment>
<checkMissingComment>true</checkMissingComment>
</Comments>
<Namespace>imstk</Namespace>
<IfNDefDefine>[NameOfClass]_[Extension]</IfNDefDefine>
<EmptyLines>2</EmptyLines>
<Header>Utilities/KWStyle/iMSTKHeader.h,false,false</Header>
<StatementPerLine>1,true</StatementPerLine>
<BadCharacters>true</BadCharacters>
</Description>
/home/virtualfls/Projects/IMSTK/src_refactoring/Examples/*/*.h
/home/virtualfls/Projects/IMSTK/src_refactoring/Examples/*/*.cxx
@CMAKE_SOURCE_DIR@/Examples/*/*.h
@CMAKE_SOURCE_DIR@/Examples/*/*.cxx
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment