1 ## =========================================================================
2 ## @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 ## =========================================================================
5 ## -------------------------------------------------------------------------
6 function(BuildLibrary lib typ)
7 set(options RECURRENT INSTALL_ALL INSTALL_BIN INSTALL_DEV)
9 set(multiValueArgs SOURCE VERSION LINKS)
10 cmake_parse_arguments(
11 BuildLibrary "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
16 foreach(_s ${BuildLibrary_SOURCE})
18 ## -- Canonicalize path
19 get_filename_component(_p "${_s}" ABSOLUTE)
21 ## -- Check type of input
22 if(IS_DIRECTORY ${_p})
23 if(BuildLibrary_RECURRENT)
24 file(GLOB_RECURSE _f "${_p}/*")
25 else(BuildLibrary_RECURRENT)
26 file(GLOB _f "${_p}/*")
27 endif(BuildLibrary_RECURRENT)
29 if(NOT IS_DIRECTORY ${_x})
30 list(APPEND _files ${_x})
31 endif(NOT IS_DIRECTORY ${_x})
33 else(IS_DIRECTORY ${_p})
34 list(APPEND _files ${_p})
35 endif(IS_DIRECTORY ${_p})
45 ## -- Separate filename from extension
46 string(REGEX REPLACE "\\.[^.]*$" "" _name ${_f})
47 string(REPLACE ${_name} "" _ext ${_f})
48 set(_out_name ${_name})
53 ## -- Process .in files
54 string(COMPARE EQUAL "${_ext}" ".in" _in_cmp)
56 string(REPLACE ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} _out ${_name})
57 configure_file(${_f} ${_out} @ONLY)
58 string(REGEX REPLACE "\\.[^.]*$" "" _out_name ${_out})
59 string(REPLACE ${_out_name} "" _out_ext ${_out})
62 ## -- Now, get real extension
63 string(SUBSTRING ${_out_ext} 0 2 _ext_cmp)
65 ## -- Process .c?? files
66 string(COMPARE EQUAL "${_ext_cmp}" ".c" _c_cmp)
68 list(APPEND _cpp ${_out_name}${_out_ext})
71 ## -- Process .h?? files
72 string(COMPARE EQUAL "${_ext_cmp}" ".h" _h_cmp)
74 list(APPEND _hpp ${_out_name}${_out_ext})
77 ## -- Process .ui files
78 string(COMPARE EQUAL "${_out_ext}" ".ui" _u_cmp)
80 list(APPEND _qui ${_out_name}${_out_ext})
87 ## -- Process Qt ui files
88 list(LENGTH _qui _qui_len)
89 if(${_qui_len} GREATER 0)
90 qt5_wrap_ui(_qui_hpp ${_qui})
91 endif(${_qui_len} GREATER 0)
96 add_library(${lib} ${typ} ${_cpp} ${_hpp} ${_qui_hpp})
99 generate_export_header(${lib})
101 ## -- Put version strings
102 if(BuildLibrary_VERSION)
103 list(GET BuildLibrary_VERSION 0 _a)
104 list(GET BuildLibrary_VERSION 1 _b)
105 list(GET BuildLibrary_VERSION 2 _c)
106 set_property(TARGET ${lib} PROPERTY VERSION "${_a}.${_b}.${_c}")
107 set_property(TARGET ${lib} PROPERTY SOVERSION ${_a})
108 set_property(TARGET ${lib} PROPERTY INTERFACE_${lib}_MAJOR_VERSION ${_a})
110 TARGET ${lib} APPEND PROPERTY COMPATIBLE_INTERFACE_STRING ${_a}
112 endif(BuildLibrary_VERSION)
115 if(BuildLibrary_LINKS)
116 target_link_libraries(${lib} PUBLIC ${BuildLibrary_LINKS})
117 endif(BuildLibrary_LINKS)
121 ## -- Installation rules
122 if(BuildLibrary_INSTALL_ALL)
123 set(BuildLibrary_INSTALL_BIN ${BuildLibrary_INSTALL_ALL})
124 set(BuildLibrary_INSTALL_DEV ${BuildLibrary_INSTALL_ALL})
125 endif(BuildLibrary_INSTALL_ALL)
127 ## -- Installation rules
129 if(BuildLibrary_INSTALL_BIN)
132 EXPORT "${targets_export_name}"
133 LIBRARY DESTINATION "lib"
134 ARCHIVE DESTINATION "lib"
135 RUNTIME DESTINATION "bin"
136 INCLUDES DESTINATION "${include_install_dir}"
138 endif(BuildLibrary_INSTALL_BIN)
140 if(BuildLibrary_INSTALL_DEV)
141 string(TOLOWER ${lib} _lower_lib)
142 set(_install_hdr ${_hpp})
146 ${CMAKE_CURRENT_BINARY_DIR}/${_lower_lib}_export.h
150 foreach(_h ${_install_hdr})
151 string(REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "" _h_name ${_h})
152 string(COMPARE EQUAL "${_h_name}" "${_h}" _h_cmp)
154 string(REPLACE ${CMAKE_CURRENT_BINARY_DIR} "" _h_name ${_h})
156 set(_h_out ${include_install_dir}/${lib}${_h_name})
157 get_filename_component(_h_dir ${_h_out} DIRECTORY)
160 DESTINATION "${_h_dir}"
163 endif(BuildLibrary_INSTALL_DEV)
167 ## -------------------------------------------------------------------------
168 function(BuildApplication app)
170 set(options INSTALL RECURRENT)
172 set(multiValueArgs SOURCE LINKS)
173 cmake_parse_arguments(
174 BuildApplication "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
177 set(_lib __lib__${app})
178 if(BuildApplication_RECURRENT)
182 SOURCE ${BuildApplication_SOURCE}
183 LINKS ${BuildApplication_LINKS}
185 else(BuildApplication_RECURRENT)
188 SOURCE ${BuildApplication_SOURCE}
189 LINKS ${BuildApplication_LINKS}
191 endif(BuildApplication_RECURRENT)
193 ## -- Create an empty application
194 set(_m ${CMAKE_CURRENT_BINARY_DIR}/__main__${app}.cxx)
195 file(WRITE ${_m} "// Automatically generated dummy file")
196 add_executable(${app} ${EXECUTABLE_TYPE} ${_m})
198 ## -- Link it against the static library
199 target_link_libraries(${app} PUBLIC ${_lib})
201 ## -- Installation rules
202 if(BuildApplication_INSTALL)
205 EXPORT "${targets_export_name}"
206 LIBRARY DESTINATION "lib"
207 ARCHIVE DESTINATION "lib"
208 RUNTIME DESTINATION "bin"
209 INCLUDES DESTINATION "${include_install_dir}"
211 endif(BuildApplication_INSTALL)