-## =========================================================================
-## @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
-## =========================================================================
-
-## -------------------------------------------------------------------------
-function(BuildLibrary lib typ src maj min rel)
-
-## -- Get sources
-set(_files)
-foreach(_s ${src})
-
- ## -- Canonicalize path
- get_filename_component(_p "${_s}" ABSOLUTE)
-
- ## -- Check type of input
- if(IS_DIRECTORY ${_p})
- file(GLOB _f "${_p}/*")
- foreach(_x ${_f})
- if(NOT IS_DIRECTORY ${_x})
- list(APPEND _files ${_x})
- endif(NOT IS_DIRECTORY ${_x})
- endforeach(_x)
- else(IS_DIRECTORY ${_p})
- list(APPEND _files ${_p})
- endif(IS_DIRECTORY ${_p})
-
-endforeach(_s)
-
-## -- Process sources
-set(_cpp)
-set(_hpp)
-set(_qui)
-foreach(_f ${_files})
-
- ## -- Separate filename from extension
- string(REGEX REPLACE "\\.[^.]*$" "" _name ${_f})
- string(REPLACE ${_name} "" _ext ${_f})
- set(_out_name ${_name})
- set(_out_ext ${_ext})
-
- ## -- Process .in files
- string(COMPARE EQUAL "${_ext}" ".in" _in_cmp)
- if(_in_cmp)
- string(REPLACE ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} _out ${_name})
- configure_file(${_f} ${_out} @ONLY)
- string(REGEX REPLACE "\\.[^.]*$" "" _out_name ${_out})
- string(REPLACE ${_out_name} "" _out_ext ${_out})
- endif(_in_cmp)
-
- ## -- Now, get real extension
- string(SUBSTRING ${_out_ext} 0 2 _ext_cmp)
-
- ## -- Process .c?? files
- string(COMPARE EQUAL "${_ext_cmp}" ".c" _c_cmp)
- if(_c_cmp)
- list(APPEND _cpp ${_out_name}${_out_ext})
- endif(_c_cmp)
-
- ## -- Process .h?? files
- string(COMPARE EQUAL "${_ext_cmp}" ".h" _h_cmp)
- if(_h_cmp)
- list(APPEND _hpp ${_out_name}${_out_ext})
- endif(_h_cmp)
-
- ## -- Process .ui files
- string(COMPARE EQUAL "${_out_ext}" ".ui" _u_cmp)
- if(_u_cmp)
- list(APPEND _qui ${_out_name}${_out_ext})
- endif(_u_cmp)
-
-endforeach(_f)
-
-## -- Process Qt ui files
-list(LENGTH _qui _qui_len)
-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})
-
-## -- 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})
-
-## -- Link library
-target_link_libraries(${lib} PUBLIC ${ARGN})
-
-## -- 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)
- string(TOLOWER ${lib} _lower_lib)
- set(
- _install_hdr
- ${_hpp}
- ${CMAKE_CURRENT_BINARY_DIR}/${_lower_lib}_export.h
- )
- set(_install_dirs)
- foreach(_h ${_install_hdr})
- string(REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "" _h_name ${_h})
- string(COMPARE EQUAL "${_h_name}" "${_h}" _h_cmp)
- if(_h_cmp)
- string(REPLACE ${CMAKE_CURRENT_BINARY_DIR} "" _h_name ${_h})
- endif(_h_cmp)
- set(_h_out ${include_install_dir}/${lib}${_h_name})
- get_filename_component(_h_dir ${_h_out} DIRECTORY)
- install(
- FILES "${_h}"
- DESTINATION "${_h_dir}"
- )
- endforeach(_h)
-endif(${lib}_INSTALL_DEVEL)
-
-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$