From 73cb161bc4a49578801a7b1e98c7776661a88305 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Thu, 28 Sep 2017 16:41:09 -0500 Subject: [PATCH] ... --- CMakeLists.txt | 2 +- cmake/Functions.cmake | 125 +++++++++++++++++++++++------------ lib/cpPlugins/CMakeLists.txt | 10 +-- lib/ivq/CMakeLists.txt | 9 ++- 4 files changed, 96 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 335f9e9..cc162d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,6 @@ endif(VTK_FOUND) subdirs(lib) ## == Installation commands -include(cmake/InstallCommands.cmake) +## include(cmake/InstallCommands.cmake) ## eof - $RCSfile$ diff --git a/cmake/Functions.cmake b/cmake/Functions.cmake index 8ca0f15..53046e6 100644 --- a/cmake/Functions.cmake +++ b/cmake/Functions.cmake @@ -3,18 +3,28 @@ ## ========================================================================= ## ------------------------------------------------------------------------- -function(BuildLibrary lib typ src maj min rel) +function(BuildLibrary lib typ) +set(options RECURRENT INSTALL_ALL INSTALL_BIN INSTALL_DEV) +set(oneValueArgs) +set(multiValueArgs SOURCE VERSION LINKS) +cmake_parse_arguments( + BuildLibrary "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} + ) ## -- Get sources set(_files) -foreach(_s ${src}) +foreach(_s ${BuildLibrary_SOURCE}) ## -- Canonicalize path get_filename_component(_p "${_s}" ABSOLUTE) ## -- Check type of input if(IS_DIRECTORY ${_p}) - file(GLOB _f "${_p}/*") + if(BuildLibrary_RECURRENT) + file(GLOB_RECURSE _f "${_p}/*") + else(BuildLibrary_RECURRENT) + file(GLOB _f "${_p}/*") + endif(BuildLibrary_RECURRENT) foreach(_x ${_f}) if(NOT IS_DIRECTORY ${_x}) list(APPEND _files ${_x}) @@ -76,39 +86,62 @@ if(${_qui_len} GREATER 0) qt5_wrap_ui(_qui_hpp ${_qui}) endif(${_qui_len} GREATER 0) -## -- Real build -add_library(${lib} ${typ} ${_cpp} ${_hpp} ${_qui_hpp}) +if(_cpp) -## -- Header creation -generate_export_header(${lib}) -set_property(TARGET ${lib} PROPERTY VERSION "${maj}.${min}.${rel}") -set_property(TARGET ${lib} PROPERTY SOVERSION ${maj}) -set_property(TARGET ${lib} PROPERTY INTERFACE_${lib}_MAJOR_VERSION ${maj}) -set_property(TARGET ${lib} APPEND PROPERTY COMPATIBLE_INTERFACE_STRING ${maj}) + ## -- Real build + add_library(${lib} ${typ} ${_cpp} ${_hpp} ${_qui_hpp}) -## -- Link library -target_link_libraries(${lib} PUBLIC ${ARGN}) + ## -- Header creation + generate_export_header(${lib}) + + ## -- Put version strings + if(BuildLibrary_VERSION) + list(GET BuildLibrary_VERSION 0 _a) + list(GET BuildLibrary_VERSION 1 _b) + list(GET BuildLibrary_VERSION 2 _c) + set_property(TARGET ${lib} PROPERTY VERSION "${_a}.${_b}.${_c}") + set_property(TARGET ${lib} PROPERTY SOVERSION ${_a}) + set_property(TARGET ${lib} PROPERTY INTERFACE_${lib}_MAJOR_VERSION ${_a}) + set_property( + TARGET ${lib} APPEND PROPERTY COMPATIBLE_INTERFACE_STRING ${_a} + ) + endif(BuildLibrary_VERSION) + + ## -- Link library + if(BuildLibrary_LINKS) + target_link_libraries(${lib} PUBLIC ${BuildLibrary_LINKS}) + endif(BuildLibrary_LINKS) + +endif(_cpp) ## -- Installation rules -option(${lib}_INSTALL_DEVEL "Install development files for ${lib}" OFF) -string(COMPARE EQUAL "${type}" "SHARED" _cmp) -if(_cmp OR ${lib}_INSTALL_DEVEL) - install( - TARGETS ${lib} - EXPORT "${targets_export_name}" - LIBRARY DESTINATION "lib" - ARCHIVE DESTINATION "lib" - RUNTIME DESTINATION "bin" - INCLUDES DESTINATION "${include_install_dir}" - ) -endif(_cmp OR ${lib}_INSTALL_DEVEL) -if(${lib}_INSTALL_DEVEL) +if(BuildLibrary_INSTALL_ALL) + set(BuildLibrary_INSTALL_BIN ${BuildLibrary_INSTALL_ALL}) + set(BuildLibrary_INSTALL_DEV ${BuildLibrary_INSTALL_ALL}) +endif(BuildLibrary_INSTALL_ALL) + +## -- Installation rules +if(_cpp) + if(BuildLibrary_INSTALL_BIN) + install( + TARGETS ${lib} + EXPORT "${targets_export_name}" + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "${include_install_dir}" + ) + endif(BuildLibrary_INSTALL_BIN) +endif(_cpp) +if(BuildLibrary_INSTALL_DEV) string(TOLOWER ${lib} _lower_lib) - set( - _install_hdr - ${_hpp} - ${CMAKE_CURRENT_BINARY_DIR}/${_lower_lib}_export.h - ) + set(_install_hdr ${_hpp}) + if(_cpp) + list( + APPEND _install_hdr + ${CMAKE_CURRENT_BINARY_DIR}/${_lower_lib}_export.h + ) + endif(_cpp) set(_install_dirs) foreach(_h ${_install_hdr}) string(REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "" _h_name ${_h}) @@ -123,19 +156,27 @@ if(${lib}_INSTALL_DEVEL) DESTINATION "${_h_dir}" ) endforeach(_h) -endif(${lib}_INSTALL_DEVEL) +endif(BuildLibrary_INSTALL_DEV) endfunction() -## ------------------------------------------------------------------------- -function(BuildLibraryRecursive lib typ dir maj min rel) - -## -- Globbing directory -file(GLOB_RECURSE _files "${dir}/*") - -## -- Build library -BuildLibrary(${lib} ${typ} "${_files}" ${maj} ${min} ${rel} ${ARGN}) - -endfunction() +### ------------------------------------------------------------------------- +#function(BuildApplication app) +#option(BUILD_${app} "Build ${app}" OFF) +#if(BUILD_${app}) +# ## -- Use a static library +# BuildLibraryRecursive( +# _${app}_ STATIC ${CMAKE_CURRENT_SOURCE_DIR} 0 0 0 ${ARGN} +# ) + +# ## -- Create an empty application +# set(_m ${CMAKE_CURRENT_BINARY_DIR}/__main__${app}.cxx) +# file(WRITE ${_m} "// Automatically generated dummy file") +# add_executable(${app} ${EXECUTABLE_TYPE} ${_m}) + +# ## -- Link it against static library +# target_link_libraries(${app} PUBLIC _${app}_) +#endif(BUILD_${app}) +#endfunction() ## eof - $RCSfile$ diff --git a/lib/cpPlugins/CMakeLists.txt b/lib/cpPlugins/CMakeLists.txt index b663bc1..5d8922f 100644 --- a/lib/cpPlugins/CMakeLists.txt +++ b/lib/cpPlugins/CMakeLists.txt @@ -2,10 +2,12 @@ ## @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) ## ========================================================================= -BuildLibraryRecursive( - cpPlugins SHARED . - ${prj_MAJ} ${prj_MIN} ${prj_REL} - ${ITK_LIBRARIES} ${VTK_LIBRARIES} +BuildLibrary( + cpPlugins SHARED + RECURRENT INSTALL_ALL + SOURCE . + VERSION ${prj_MAJ} ${prj_MIN} ${prj_REL} + LINKS ${ITK_LIBRARIES} ${VTK_LIBRARIES} ) ## eof - $RCSfile$ diff --git a/lib/ivq/CMakeLists.txt b/lib/ivq/CMakeLists.txt index 1a55abc..8d4a985 100644 --- a/lib/ivq/CMakeLists.txt +++ b/lib/ivq/CMakeLists.txt @@ -16,10 +16,13 @@ if(BUILD_ivq) ## -- Build BuildLibrary( - ivq SHARED "${_dirs}" - ${prj_MAJ} ${prj_MIN} ${prj_REL} - ${ITK_LIBRARIES} ${VTK_LIBRARIES} + ivq SHARED + INSTALL_ALL + SOURCE ${_dirs} + VERSION ${prj_MAJ} ${prj_MIN} ${prj_REL} + LINKS ${ITK_LIBRARIES} ${VTK_LIBRARIES} ) + endif(BUILD_ivq) ## eof - $RCSfile$ -- 2.47.1