1 ## =========================================================================
2 ## @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 ## =========================================================================
5 ## -------------------------------------------------------------------------
6 function(BuildLibrary lib typ src maj min rel)
12 ## -- Canonicalize path
13 get_filename_component(_p "${_s}" ABSOLUTE)
15 ## -- Check type of input
16 if(IS_DIRECTORY ${_p})
17 file(GLOB _f "${_p}/*")
19 if(NOT IS_DIRECTORY ${_x})
20 list(APPEND _files ${_x})
21 endif(NOT IS_DIRECTORY ${_x})
23 else(IS_DIRECTORY ${_p})
24 list(APPEND _files ${_p})
25 endif(IS_DIRECTORY ${_p})
35 ## -- Separate filename from extension
36 string(REGEX REPLACE "\\.[^.]*$" "" _name ${_f})
37 string(REPLACE ${_name} "" _ext ${_f})
38 set(_out_name ${_name})
41 ## -- Process .in files
42 string(COMPARE EQUAL "${_ext}" ".in" _in_cmp)
44 string(REPLACE ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} _out ${_name})
45 configure_file(${_f} ${_out} @ONLY)
46 string(REGEX REPLACE "\\.[^.]*$" "" _out_name ${_out})
47 string(REPLACE ${_out_name} "" _out_ext ${_out})
50 ## -- Now, get real extension
51 string(SUBSTRING ${_out_ext} 0 2 _ext_cmp)
53 ## -- Process .c?? files
54 string(COMPARE EQUAL "${_ext_cmp}" ".c" _c_cmp)
56 list(APPEND _cpp ${_out_name}${_out_ext})
59 ## -- Process .h?? files
60 string(COMPARE EQUAL "${_ext_cmp}" ".h" _h_cmp)
62 list(APPEND _hpp ${_out_name}${_out_ext})
65 ## -- Process .ui files
66 string(COMPARE EQUAL "${_out_ext}" ".ui" _u_cmp)
68 list(APPEND _qui ${_out_name}${_out_ext})
73 ## -- Process Qt ui files
74 list(LENGTH _qui _qui_len)
75 if(${_qui_len} GREATER 0)
76 qt5_wrap_ui(_qui_hpp ${_qui})
77 endif(${_qui_len} GREATER 0)
80 add_library(${lib} ${typ} ${_cpp} ${_hpp} ${_qui_hpp})
83 generate_export_header(${lib})
84 set_property(TARGET ${lib} PROPERTY VERSION "${maj}.${min}.${rel}")
85 set_property(TARGET ${lib} PROPERTY SOVERSION ${maj})
86 set_property(TARGET ${lib} PROPERTY INTERFACE_${lib}_MAJOR_VERSION ${maj})
87 set_property(TARGET ${lib} APPEND PROPERTY COMPATIBLE_INTERFACE_STRING ${maj})
90 target_link_libraries(${lib} PUBLIC ${ARGN})
92 ## -- Installation rules
93 option(${lib}_INSTALL_DEVEL "Install development files for ${lib}" OFF)
94 string(COMPARE EQUAL "${type}" "SHARED" _cmp)
95 if(_cmp OR ${lib}_INSTALL_DEVEL)
98 EXPORT "${targets_export_name}"
99 LIBRARY DESTINATION "lib"
100 ARCHIVE DESTINATION "lib"
101 RUNTIME DESTINATION "bin"
102 INCLUDES DESTINATION "${include_install_dir}"
104 endif(_cmp OR ${lib}_INSTALL_DEVEL)
105 if(${lib}_INSTALL_DEVEL)
106 string(TOLOWER ${lib} _lower_lib)
110 ${CMAKE_CURRENT_BINARY_DIR}/${_lower_lib}_export.h
113 foreach(_h ${_install_hdr})
114 string(REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "" _h_name ${_h})
115 string(COMPARE EQUAL "${_h_name}" "${_h}" _h_cmp)
117 string(REPLACE ${CMAKE_CURRENT_BINARY_DIR} "" _h_name ${_h})
119 set(_h_out ${include_install_dir}/${lib}${_h_name})
120 get_filename_component(_h_dir ${_h_out} DIRECTORY)
123 DESTINATION "${_h_dir}"
126 endif(${lib}_INSTALL_DEVEL)
130 ## -------------------------------------------------------------------------
131 function(BuildLibraryRecursive lib typ dir maj min rel)
133 ## -- Globbing directory
134 file(GLOB_RECURSE _files "${dir}/*")
137 BuildLibrary(${lib} ${typ} "${_files}" ${maj} ${min} ${rel} ${ARGN})