Commit b98ff925 authored by saubatn's avatar saubatn
Browse files

NEW CMake macro CamiTKInstallAllHeaders: install all headers (.h) of a project...

NEW CMake macro CamiTKInstallAllHeaders: install all headers (.h) of a project and KEEP its directories structure (subdirectories containing .h are kept at build & installation times. This macro extends and simplify the CamiTK macro ExportHeaders
UPDATED CamiTKLibrary CMake macro now calls CamiTKInstallAllHeaders by default

git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@1983 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 995cbef5
......@@ -12,6 +12,7 @@ include(GetSubdirectoryFiles)
# -- CamiTK specific macros
include(CamiTKAddSubDirectory)
include(ExportHeaders)
include(CamiTKInstallAllHeaders)
# -- CamiTK extensions and library macro
include(CamiTKExtensionProject)
......@@ -38,4 +39,4 @@ include(CamiTKParseTestAdd)
include(CamiTKParseTestValidate)
# -- Translations
include(CamiTKTranslate)
\ No newline at end of file
include(CamiTKTranslate)
#!
#! @ingroup group_sdk_cmake
#!
#! camitk_install_all_headers is a macro that install all header files of a project at build and install time
#!
#! Duplicate headers installation:
#! - one is used at compiled time and puts everything in
#! ${CMAKE_BINARY_DIR}/include/${CAMITK_SHORT_VERSION_STRING}/${GroupName}/${ComponentName}/...
#! - the other one is used at installation time and puts everything in
#! ${CMAKE_INSTALL_PREFIX}/include/${CAMITK_SHORT_VERSION_STRING}/${GroupName}/${ComponentName}/...
#!
#! This macro keeps header files directories tree structure at installation. In other words, if your extension
#! has its header files located in subdirectories, this tree structure will be kept the same at installation.
#!
#! Usage:
#! \code
#! camitk_install_all_headers( COMPONENT ComponentName
#! [GROUP GroupName]
#! )
#! \endcode
#!
#! \param COMPONENT (required) Name of the component to use. This is also the include subdirectory name
#! used for copying the file
#! \param GROUP (optional) Name of the group this install should be using group will be
#! prepend to the component name. This is either actions, components or libraries.
#!
#! Example invocation:
#!
#! \code
#!
#! #--------------
#! # installation
#! #--------------
#! camitk_install_headers( COMPONENT ${MYPROJECT_NAME}
#! GROUP libraries
#! )
#!
#! Here, in this example, we will install all the header files, in the ${CAMITK_INCLUDE_DIR}/include/libraries/${MYPROJECT_NAME} directories (at build and installation times)
#! If my header files are located in some subdirectories, this structure will be kept the same at build and installation times.
#!
#! \endcode
macro(camitk_install_all_headers)
parse_arguments(CAMITK_INSTALL_ALL_HEADERS
"COMPONENT;GROUP;" # possible lists
"" # no possible options
${ARGN}
)
# The base include directories
set(CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR ${CMAKE_BINARY_DIR}/include/${CAMITK_SHORT_VERSION_STRING})
set(CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR include/${CAMITK_SHORT_VERSION_STRING})
# Get action, component or library name without its prefix
set(CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME ${CAMITK_INSTALL_ALL_HEADERS_COMPONENT})
string(REGEX REPLACE "^component-|^component_|^action-|^action_|^library_|^library-" "" CAMITK_INSTALL_ALL_HEADERS_COMPONENT ${CAMITK_INSTALL_ALL_HEADERS_COMPONENT})
# Check group directory
if(CAMITK_INSTALL_ALL_HEADERS_GROUP)
# Create group directory if not already existing
if (NOT EXISTS ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_GROUP} AND NOT CAMITK_INSTALL_ALL_HEADERS_DIRECTORY)
add_custom_command( TARGET ${CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_GROUP}
COMMENT "Creating build-time group include dir ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_GROUP}"
VERBATIM
)
endif()
# Update base dirs
set(CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_GROUP})
set(CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR ${CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_GROUP})
endif()
# Create component directory if not already existing
if (NOT EXISTS ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_COMPONENT} AND NOT CAMITK_INSTALL_ALL_HEADERS_DIRECTORY)
add_custom_command( TARGET ${CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_COMPONENT}
COMMENT "Creating build-time include dir ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_COMPONENT}"
VERBATIM
)
endif()
# Update base dirs
set(CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_COMPONENT})
set(CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR ${CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR}/${CAMITK_INSTALL_ALL_HEADERS_COMPONENT})
# Build time installation
file(GLOB_RECURSE HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/ *.h)
foreach(HEADER ${HEADERS})
# Get the subdirectory name of the header
string(REGEX MATCH ".*/" SUBDIR ${HEADER})
# Create subdirectory if not already existing
if(NOT EXISTS ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${SUBDIR} AND NOT CAMITK_INSTALL_ALL_HEADERS_${SUBDIR})
# Create directory at build time
add_custom_command( TARGET ${CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${SUBDIR}
COMMENT "Creating build-time include dir ${CAMITK_INSTALL_ALL_HEADERS_COMPONENT}/${SUBDIR}"
VERBATIM
)
set(CAMITK_INSTALL_ALL_HEADERS_${SUBDIR} "CREATED") # To avoid creating the directory another time
endif()
# Install header at build time
add_custom_command( TARGET ${CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER} ${CAMITK_INSTALL_ALL_HEADERS_BUILD_BASE_DIR}/${SUBDIR}
COMMENT "Installing build-time header ${CAMITK_INSTALL_ALL_HEADERS_COMPONENT}/${HEADER}"
VERBATIM
)
endforeach()
# Install time, copy all the .h directories structure
install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMPONENT ${CAMITK_INSTALL_ALL_HEADERS_TARGET_NAME}
DESTINATION ${CAMITK_INSTALL_ALL_HEADERS_INSTALL_RELATIVE_DIR}
FILES_MATCHING
PATTERN "*.h"
)
endmacro()
......@@ -14,9 +14,9 @@
#! \code
#! camitk_library(
#! SHARED|STATIC
#! SOURCES source1.cpp source1.h...
#! [LIBNAME libname]
#! [PUBLIC]
#! SOURCES source1.cpp source1.h...
#! [NEEDS_CEP_LIBRARIES lib1 lib2...]
#! [NEEDS_ITK]
#! [NEEDS_LIBXML2]
......@@ -31,6 +31,7 @@
#! [CEP_NAME]
#! [DESCRIPTION]
#! [EXTRA_TRANSLATE_LANGUAGE]
#! [CXX_FLAGS flag1 flag2 ...]
#!
#! )
#! \endcode
......@@ -58,6 +59,7 @@
#! No CEP_NAME provided will result in default categorization (generic extension).
#! \param DESCRIPTION Simple description of the extension. Used for packaging presentation for instance.
#! \param EXTRA_TRANSLATE_LANGUAGE Additionnal extra language to translate the application
#! \param CXX_FLAGS = list of compiler flags to add (such as warning levels (-Wall ...)).
macro(camitk_library)
......@@ -73,7 +75,7 @@ macro(camitk_library)
get_directory_name(${CMAKE_CURRENT_SOURCE_DIR} DEFAULT_LIBRARY_NAME)
parse_arguments(${DEFAULT_LIBRARY_NAME_CMAKE}
"SOURCES;NEEDS_CEP_LIBRARIES;EXTERNAL_LIBRARIES;INCLUDE_DIRECTORIES;LIBNAME;DEFINES;LINK_DIRECTORIES;HEADERS_TO_INSTALL;CEP_NAME;DESCRIPTION;EXTRA_TRANSLATE_LANGUAGE" # possible lists
"SOURCES;NEEDS_CEP_LIBRARIES;EXTERNAL_LIBRARIES;INCLUDE_DIRECTORIES;LIBNAME;DEFINES;LINK_DIRECTORIES;HEADERS_TO_INSTALL;CEP_NAME;DESCRIPTION;EXTRA_TRANSLATE_LANGUAGE;CXX_FLAGS" # possible lists
"SHARED;STATIC;NEEDS_ITK;NEEDS_LIBXML2;NEEDS_XERCESC;NEEDS_XSD;NEEDS_QT_MODULES;PUBLIC" # possible options
${ARGN}
)
......@@ -853,6 +855,13 @@ macro(camitk_library)
endforeach()
endif()
# USER INPUT CUSTOM COMPILER FLAG
if(${DEFAULT_LIBRARY_NAME_CMAKE}_CXX_FLAGS)
foreach (FLAG ${${DEFAULT_LIBRARY_NAME_CMAKE}_CXX_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
endforeach()
endif()
# PLATFORM SPECIFIC COMPILER FLAG
# 64bits and other platform with relocation needs -fPIC
include(TestCXXAcceptsFlag)
......@@ -911,9 +920,8 @@ macro(camitk_library)
# If headers information provided for installation => install them
export_headers(${${DEFAULT_LIBRARY_NAME_CMAKE}_HEADERS_TO_INSTALL} COMPONENT ${LIBRARY_TARGET_NAME} GROUP libraries)
else()
# if not, install all headers (*.h) by default in the build/include/libraries/library-name directory
file(GLOB_RECURSE ${DEFAULT_LIBRARY_NAME_CMAKE}_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
export_headers(${${DEFAULT_LIBRARY_NAME_CMAKE}_HEADERS} COMPONENT ${LIBRARY_TARGET_NAME} GROUP libraries)
# By default, install all headers and keep include directories structure
camitk_install_all_headers(COMPONENT ${LIBRARY_TARGET_NAME} GROUP libraries)
endif()
......
......@@ -24,11 +24,11 @@ macro(get_subdirectories Name)
if (LS)
foreach(FILENAME ${LS})
if(IS_DIRECTORY ${FILENAME} AND EXISTS ${FILENAME}/CMakeLists.txt)
get_directory_name(${FILENAME} DIRNAME)
# ignore .svn
if (NOT ${DIRNAME} STREQUAL ".svn")
get_directory_name(${FILENAME} DIRNAME)
# ignore .svn
if (NOT ${DIRNAME} STREQUAL ".svn")
set(${Name} ${${Name}} ${DIRNAME})
endif()
endif()
endif()
endforeach()
......
Supports Markdown
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