Skip to content

Commit

Permalink
Merge topic 'ExternalModuleMacros'
Browse files Browse the repository at this point in the history
387e9ff ENH: Add ITKModuleExternal.cmake
  • Loading branch information
thewtex authored and kwrobot committed Aug 27, 2015
2 parents cb14ece + 387e9ff commit db4a339
Show file tree
Hide file tree
Showing 15 changed files with 225 additions and 97 deletions.
12 changes: 6 additions & 6 deletions CMake/CppcheckTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function(add_cppcheck_dir _name _dir _include_dirs)

itk_add_test(
NAME
${_name}_cppcheck_test
${_name}CPPCheckTest
COMMAND
"${CPPCHECK_EXECUTABLE}"
${CPPCHECK_TEMPLATE_ARG}
Expand All @@ -130,7 +130,7 @@ function(add_cppcheck_dir _name _dir _include_dirs)
${_dir}
)

set_tests_properties(${_name}_cppcheck_test
set_tests_properties(${_name}CPPCheckTest
PROPERTIES
FAIL_REGULAR_EXPRESSION
"${CPPCHECK_FAIL_REGULAR_EXPRESSION}")
Expand Down Expand Up @@ -213,15 +213,15 @@ function(add_cppcheck_sources _targetname)

itk_add_test(
NAME
${_targetname}_cppcheck_test
${_targetname}CPPCheckTest
COMMAND
"${CPPCHECK_EXECUTABLE}"
${CPPCHECK_TEMPLATE_ARG}
${_cppcheck_args}
${_cppcheck_compile_args}
${_files})

set_tests_properties(${_targetname}_cppcheck_test
set_tests_properties(${_targetname}CPPCheckTest
PROPERTIES
FAIL_REGULAR_EXPRESSION
"${CPPCHECK_FAIL_REGULAR_EXPRESSION}")
Expand Down Expand Up @@ -291,15 +291,15 @@ function(add_cppcheck _name)

itk_add_test(
NAME
${_name}_cppcheck_test
${_name}CPPCheckTest
COMMAND
"${CPPCHECK_EXECUTABLE}"
${CPPCHECK_TEMPLATE_ARG}
${_cppcheck_args}
${_cppcheck_compile_args}
${_files})

set_tests_properties(${_name}_cppcheck_test
set_tests_properties(${_name}CPPCheckTest
PROPERTIES
FAIL_REGULAR_EXPRESSION
"${CPPCHECK_FAIL_REGULAR_EXPRESSION}")
Expand Down
3 changes: 3 additions & 0 deletions CMake/ITKConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ set(ITK_LEGACY_SILENT "@ITK_LEGACY_SILENT@")
# Remove code that will become legacy in future releases completely.
set(ITK_FUTURE_LEGACY_REMOVE "@ITK_FUTURE_LEGACY_REMOVE@")

# ITK's CMake directory with modules ITK uses.
set(ITK_CMAKE_DIR "@ITK_CONFIG_CMAKE_DIR@")

# The location of the UseITK.cmake file.
set(ITK_USE_FILE "@ITK_USE_FILE@")

Expand Down
13 changes: 9 additions & 4 deletions CMake/ITKModuleCPPCheckTest.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#-----------------------------------------------------------------------------
# Enable running cppcheck for each module on its source and test directories.
option(ITK_CPPCHECK_TEST "Run cppcheck for static code analysis" OFF)
mark_as_advanced(ITK_CPPCHECK_TEST)

macro( itk_module_cppcheck_test _name )
if( EXISTS "${${_name}_SOURCE_DIR}/src" )
file( GLOB _cxx_files *.cxx )
file( GLOB _cxx_files "${${_name}_SOURCE_DIR}/src/*.cxx" )
list( LENGTH _cxx_files _num_cxx_files )
# let's make sure there are actually cxx files in the src dir
if( ${_num_cxx_files} GREATER 0 )
add_cppcheck_dir(
${_name}_SRC_DIR # _name
${_name}Sources # _name
"${${_name}_SOURCE_DIR}/src" #_dir
${${_name}_SOURCE_DIR}/include #_include_dirs
VERBOSE
Expand All @@ -16,12 +21,12 @@ macro( itk_module_cppcheck_test _name )
endif()

if( EXISTS "${${_name}_SOURCE_DIR}/test" )
file( GLOB _cxx_files *.cxx )
file( GLOB _cxx_files "${${_name}_SOURCE_DIR}/test/*.cxx" )
list( LENGTH _cxx_files _num_cxx_files )
# let's make sure there are actually cxx files in the src dir
if( ${_num_cxx_files} GREATER 0 )
add_cppcheck_dir(
${_name}_TEST_DIR # _name
${_name}Tests # _name
"${${_name}_SOURCE_DIR}/test" #_dir
${${_name}_SOURCE_DIR}/include #_include_dirs
VERBOSE
Expand Down
14 changes: 8 additions & 6 deletions CMake/ITKModuleDoxygen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ macro( itk_module_doxygen _name )
set( _content "${_content} \\enddot \n" )
set( _content "${_content} */\n" )

configure_file(
"${ITK_SOURCE_DIR}/Utilities/Doxygen/Module.dox.in"
"${ITK_BINARY_DIR}/Utilities/Doxygen/Modules/${_name}.dox"
@ONLY
)
if(ITK_SOURCE_DIR)
configure_file(
"${ITK_SOURCE_DIR}/Utilities/Doxygen/Module.dox.in"
"${ITK_BINARY_DIR}/Utilities/Doxygen/Modules/${_name}.dox"
@ONLY
)
endif()

if(NOT ${_name}_THIRD_PARTY AND EXISTS ${${_name}_SOURCE_DIR}/include)
if(PYTHON_EXECUTABLE)
itk_add_test(NAME ${_name}InDoxygenGroup COMMAND ${PYTHON_EXECUTABLE} "${ITK_SOURCE_DIR}/Utilities/Doxygen/mcdoc.py" check ${_name} ${${_name}_SOURCE_DIR}/include)
itk_add_test(NAME ${_name}InDoxygenGroup COMMAND ${PYTHON_EXECUTABLE} "${ITK_CMAKE_DIR}/../Utilities/Doxygen/mcdoc.py" check ${_name} ${${_name}_SOURCE_DIR}/include)
itk_memcheck_ignore(${_name}InDoxygenGroup)
endif()
endif()
Expand Down
112 changes: 112 additions & 0 deletions CMake/ITKModuleExternal.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# This file ensures the appropriate variables are set up for a project extending
# ITK before including ITKModuleMacros. This is the preferred way to build an
# ITK module outside of the ITK source tree.

if(NOT ITK_FOUND)
message(FATAL_ERROR "ITK must be found before module macros can be used.")
endif()
if(NOT ITK_VERSION VERSION_GREATER "4.8")
message(FATAL_ERROR "Requires ITK 4.9 or later to work.")
endif()
if(NOT EXISTS ${ITK_CMAKE_DIR}/ITKModuleMacros.cmake)
message(FATAL_ERROR "Modules can only be built against an ITK build tree; they cannot be built against an ITK install tree.")
endif()

# Setup build locations.
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
endif()

# ITK installation structure
if(NOT ITK_INSTALL_RUNTIME_DIR)
set(ITK_INSTALL_RUNTIME_DIR bin)
endif()
if(NOT ITK_INSTALL_LIBRARY_DIR)
set(ITK_INSTALL_LIBRARY_DIR lib)
endif()
if(NOT ITK_INSTALL_ARCHIVE_DIR)
set(ITK_INSTALL_ARCHIVE_DIR lib)
endif()
if(NOT ITK_INSTALL_INCLUDE_DIR)
set(ITK_INSTALL_INCLUDE_DIR include/ITK-${ITK_MAJOR_VERSION}.${ITK_MINOR_VERSION})
endif()
if(NOT ITK_INSTALL_DATA_DIR)
set(ITK_INSTALL_DATA_DIR share/ITK-${ITK_MAJOR_VERSION}.${ITK_MINOR_VERSION})
endif()
if(NOT ITK_INSTALL_DOC_DIR)
set(ITK_INSTALL_DOC_DIR share/doc/ITK-${ITK_MAJOR_VERSION}.${ITK_MINOR_VERSION})
endif()
if(NOT ITK_INSTALL_PACKAGE_DIR)
set(ITK_INSTALL_PACKAGE_DIR "lib/cmake/ITK-${ITK_MAJOR_VERSION}.${ITK_MINOR_VERSION}")
endif()
#if(NOT ITK_INSTALL_EXPORT_NAME)
#set(ITK_INSTALL_EXPORT_NAME ITKTargets)
#endif()

# Use ITK's flags.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ITK_REQUIRED_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ITK_REQUIRED_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ITK_REQUIRED_LINK_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ITK_REQUIRED_LINK_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${ITK_REQUIRED_LINK_FLAGS}")

# Add the ITK_MODULES_DIR to the CMAKE_MODULE_PATH and then use the binary
# directory for the project to write out new ones to.
if(ITK_MODULES_DIR)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ITK_MODULES_DIR})
endif()
set(ITK_MODULES_DIR "${CMAKE_BINARY_DIR}/${ITK_INSTALL_PACKAGE_DIR}/Modules")

include(ITKExternalData)
if(EXISTS ${CMAKE_SOURCE_DIR}/test/CMakeLists.txt)
include(CTest)
include(ITKModuleTest)
if(NOT DEFINED ITK_USE_KWSTYLE)
find_package(KWStyle 1.0.1
QUIET
)
option(ITK_USE_KWSTYLE
"Enable the use of KWStyle for checking coding style."
${KWSTYLE_FOUND} # default
)
mark_as_advanced(ITK_USE_KWSTYLE)
endif()
endif()

include(ITKModuleMacros)
include(itk-module.cmake)
set(${itk-module}-targets ${itk-module}Targets)
set(${itk-module}-targets-install "${ITK_INSTALL_PACKAGE_DIR}/${itk-module}Targets.cmake")
set(${itk-module}-targets-build "${CMAKE_BINARY_DIR}/${itk-module}Targets.cmake")
itk_module_impl()

set(ITK_TEST_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Testing/Temporary")
if(EXISTS "${CMAKE_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()

if(ITK_WRAPPING AND EXISTS "${CMAKE_SOURCE_DIR}/wrapping/CMakeLists.txt")
set(EXTERNAL_WRAP_ITK_PROJECT ON)
# Build tree
if(EXISTS "${ITK_CMAKE_DIR}/../Wrapping/CMakeLists.txt")
add_subdirectory("${ITK_CMAKE_DIR}/../Wrapping"
${CMAKE_CURRENT_BINARY_DIR}/Wrapping)
# Install tree
elseif(EXISTS"${ITK_CMAKE_DIR}/Wrapping/CMakeLists.txt")
add_subdirectory("${ITK_CMAKE_DIR}/Wrapping"
${CMAKE_CURRENT_BINARY_DIR}/Wrapping)
else()
message(FATAL_ERROR "Could not find wrapping infrastructure.")
endif()
add_subdirectory(wrapping)
endif()

# Create target to download data from the ITKData group. This must come after
# all tests have been added that reference the group, so we put it last.
ExternalData_Add_Target(ITKData)
6 changes: 3 additions & 3 deletions CMake/ITKModuleHeaderTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ add_custom_target( ITKHeaderTests
COMMENT "Regenerating and building the header tests." )

macro( itk_module_headertest _name )
if( NOT ${_name}_THIRD_PARTY AND
EXISTS ${${_name}_SOURCE_DIR}/include
if( NOT ${_name}_THIRD_PARTY
AND EXISTS ${${_name}_SOURCE_DIR}/include
AND PYTHON_EXECUTABLE
AND NOT (PYTHON_VERSION_STRING VERSION_LESS 2.6)
AND NOT (${_name} STREQUAL ITKTestKernel)
Expand Down Expand Up @@ -77,7 +77,7 @@ macro( itk_module_headertest _name )
get_filename_component( _test_name ${_header_test_src} NAME_WE )
add_custom_command(
OUTPUT ${_header_test_src}
COMMAND ${PYTHON_EXECUTABLE} ${ITK_SOURCE_DIR}/Utilities/Maintenance/BuildHeaderTest.py
COMMAND ${PYTHON_EXECUTABLE} ${ITK_CMAKE_DIR}/../Utilities/Maintenance/BuildHeaderTest.py
${_name}
${${_name}_SOURCE_DIR}
${${_name}_BINARY_DIR}
Expand Down
13 changes: 12 additions & 1 deletion CMake/ITKModuleKWStyleTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@
# Globally the ITK.kws.xml file is used to configure the expected
#style.

if(NOT DEFINED ITK_USE_KWSTYLE)
find_package(KWStyle 1.0.1
QUIET
)
option(ITK_USE_KWSTYLE
"Enable the use of KWStyle for checking coding style."
${KWSTYLE_FOUND} # default
)
mark_as_advanced(ITK_USE_KWSTYLE)
endif()

macro( itk_module_kwstyle_test _name )

macro(itk_module_kwstyle_test _name)

set(_kwstyle_itk_configuration_file "${ITK_SOURCE_DIR}/Utilities/KWStyle/ITK.kws.xml" )

Expand Down
25 changes: 14 additions & 11 deletions CMake/ITKModuleMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ include(${_ITKModuleMacros_DIR}/ITKModuleAPI.cmake)
include(${_ITKModuleMacros_DIR}/ITKModuleDoxygen.cmake)
include(${_ITKModuleMacros_DIR}/ITKModuleHeaderTest.cmake)
include(${_ITKModuleMacros_DIR}/ITKModuleKWStyleTest.cmake)
include(${_ITKModuleMacros_DIR}/CppcheckTargets.cmake)
include(${_ITKModuleMacros_DIR}/ITKModuleCPPCheckTest.cmake)

# With Apple's GGC <=4.2 and LLVM-GCC <=4.2 visibility of template
# don't work. Set the option to off and hide it.
Expand All @@ -14,10 +16,6 @@ if(APPLE AND CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LE
endif()
include(GenerateExportHeader)

if(ITK_CPPCHECK_TEST)
include(${_ITKModuleMacros_DIR}/ITKModuleCPPCheckTest.cmake)
endif()

# itk_module(<name>)
#
# Main function for declaring an ITK module, usually in an itk-module.cmake file
Expand Down Expand Up @@ -160,6 +158,11 @@ macro(itk_module_impl)
list(APPEND ${itk-module}_INCLUDE_DIRS ${${itk-module}_SOURCE_DIR}/include)
install(DIRECTORY include/ DESTINATION ${${itk-module}_INSTALL_INCLUDE_DIR} COMPONENT Development)
endif()
if(NOT ITK_SOURCE_DIR)
# When building a module outside the ITK source tree, find the export
# header.
list(APPEND ${itk-module}_INCLUDE_DIRS ${${itk-module}_BINARY_DIR}/include)
endif()

if(${itk-module}_INCLUDE_DIRS)
include_directories(${${itk-module}_INCLUDE_DIRS})
Expand Down Expand Up @@ -199,11 +202,11 @@ macro(itk_module_impl)


if( ITK_MODULE_${itk-module}_ENABLE_SHARED )

# Need to use relative path to work around CMake ISSUE 12645 fixed
# in CMake 2.8.8, to support older versions
set(_export_header_file "${ITKCommon_BINARY_DIR}/${itk-module}Export.h")
file(RELATIVE_PATH _export_header_file ${CMAKE_CURRENT_BINARY_DIR} ${_export_header_file} )
if(ITK_SOURCE_DIR)
set(_export_header_file "${ITKCommon_BINARY_DIR}/${itk-module}Export.h")
else()
set(_export_header_file "${${itk-module}_BINARY_DIR}/include/${itk-module}Export.h")
endif()

# Generate the export macro header for symbol visibility/Windows DLL declspec
generate_export_header(${itk-module}
Expand All @@ -212,7 +215,7 @@ macro(itk_module_impl)
NO_EXPORT_MACRO_NAME ${itk-module}_HIDDEN
STATIC_DEFINE ITK_STATIC )
install(FILES
${ITKCommon_BINARY_DIR}/${itk-module}Export.h
${_export_header_file}
DESTINATION ${${itk-module}_INSTALL_INCLUDE_DIR}
COMPONENT Development
)
Expand Down Expand Up @@ -262,7 +265,7 @@ macro(itk_module_impl)
DESTINATION ${ITK_INSTALL_PACKAGE_DIR}/Modules
COMPONENT Development
)
itk_module_doxygen( ${itk-module} ) # module name
itk_module_doxygen(${itk-module}) # module name
endmacro()

# itk_module_link_dependencies()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file contains CMake functions and macros used when testing ITK modules.

#-----------------------------------------------------------------------------
# Create source code, compile and link a test driver
# Two variables must be defined before including this file.
# KIT should define a unique name for the test driver.
Expand Down Expand Up @@ -114,3 +117,43 @@ EM_ASM(
target_link_libraries(${KIT}TestDriver LINK_PUBLIC ${KIT_LIBS} ${ITKTestKernel_LIBRARIES})
itk_module_target_label(${KIT}TestDriver)
endmacro()

#-----------------------------------------------------------------------------
# ITK wrapper for add_test that automatically sets the test's LABELS property
# to the value of its containing module.
#
function(itk_add_test)
# Add tests with data in the ITKData group.
ExternalData_add_test(ITKData ${ARGN})

if("NAME" STREQUAL "${ARGV0}")
set(_iat_testname ${ARGV1})
else()
set(_iat_testname ${ARGV0})
endif()

if(itk-module)
set(_label ${itk-module})
if(TARGET ${itk-module}-all AND "${ARGN}" MATCHES "DATA{")
add_dependencies(${itk-module}-all ITKData)
endif()
else()
set(_label ${main_project_name})
endif()

set_property(TEST ${_iat_testname} PROPERTY LABELS ${_label})
endfunction()

#-----------------------------------------------------------------------------
# ITK function to ignore a test
#
function(itk_tests_ignore)
set_property(GLOBAL APPEND PROPERTY CTEST_CUSTOM_TESTS_IGNORE ${ARGN})
endfunction()

#-----------------------------------------------------------------------------
# ITK function to ignore a test during MemCheck
#
function(itk_memcheck_ignore)
set_property(GLOBAL APPEND PROPERTY CTEST_CUSTOM_MEMCHECK_IGNORE ${ARGN})
endfunction()
Loading

0 comments on commit db4a339

Please sign in to comment.