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})
51 ## -- Process .in files
52 string(COMPARE EQUAL "${_ext}" ".in" _in_cmp)
54 string(REPLACE ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} _out ${_name})
55 configure_file(${_f} ${_out} @ONLY)
56 string(REGEX REPLACE "\\.[^.]*$" "" _out_name ${_out})
57 string(REPLACE ${_out_name} "" _out_ext ${_out})
60 ## -- Now, get real extension
61 string(SUBSTRING ${_out_ext} 0 2 _ext_cmp)
63 ## -- Process .c?? files
64 string(COMPARE EQUAL "${_ext_cmp}" ".c" _c_cmp)
66 list(APPEND _cpp ${_out_name}${_out_ext})
69 ## -- Process .h?? files
70 string(COMPARE EQUAL "${_ext_cmp}" ".h" _h_cmp)
72 list(APPEND _hpp ${_out_name}${_out_ext})
75 ## -- Process .ui files
76 string(COMPARE EQUAL "${_out_ext}" ".ui" _u_cmp)
78 list(APPEND _qui ${_out_name}${_out_ext})
83 ## -- Process Qt ui files
84 list(LENGTH _qui _qui_len)
85 if(${_qui_len} GREATER 0)
86 qt5_wrap_ui(_qui_hpp ${_qui})
87 endif(${_qui_len} GREATER 0)
92 add_library(${lib} ${typ} ${_cpp} ${_hpp} ${_qui_hpp})
95 generate_export_header(${lib})
97 ## -- Put version strings
98 if(BuildLibrary_VERSION)
99 list(GET BuildLibrary_VERSION 0 _a)
100 list(GET BuildLibrary_VERSION 1 _b)
101 list(GET BuildLibrary_VERSION 2 _c)
102 set_property(TARGET ${lib} PROPERTY VERSION "${_a}.${_b}.${_c}")
103 set_property(TARGET ${lib} PROPERTY SOVERSION ${_a})
104 set_property(TARGET ${lib} PROPERTY INTERFACE_${lib}_MAJOR_VERSION ${_a})
106 TARGET ${lib} APPEND PROPERTY COMPATIBLE_INTERFACE_STRING ${_a}
108 endif(BuildLibrary_VERSION)
111 if(BuildLibrary_LINKS)
112 target_link_libraries(${lib} PUBLIC ${BuildLibrary_LINKS})
113 endif(BuildLibrary_LINKS)
117 ## -- Installation rules
118 if(BuildLibrary_INSTALL_ALL)
119 set(BuildLibrary_INSTALL_BIN ${BuildLibrary_INSTALL_ALL})
120 set(BuildLibrary_INSTALL_DEV ${BuildLibrary_INSTALL_ALL})
121 endif(BuildLibrary_INSTALL_ALL)
123 ## -- Installation rules
125 if(BuildLibrary_INSTALL_BIN)
128 EXPORT "${targets_export_name}"
129 LIBRARY DESTINATION "lib"
130 ARCHIVE DESTINATION "lib"
131 RUNTIME DESTINATION "bin"
132 INCLUDES DESTINATION "${include_install_dir}"
134 endif(BuildLibrary_INSTALL_BIN)
136 if(BuildLibrary_INSTALL_DEV)
137 string(TOLOWER ${lib} _lower_lib)
138 set(_install_hdr ${_hpp})
142 ${CMAKE_CURRENT_BINARY_DIR}/${_lower_lib}_export.h
146 foreach(_h ${_install_hdr})
147 string(REPLACE ${CMAKE_CURRENT_SOURCE_DIR} "" _h_name ${_h})
148 string(COMPARE EQUAL "${_h_name}" "${_h}" _h_cmp)
150 string(REPLACE ${CMAKE_CURRENT_BINARY_DIR} "" _h_name ${_h})
152 set(_h_out ${include_install_dir}/${lib}${_h_name})
153 get_filename_component(_h_dir ${_h_out} DIRECTORY)
156 DESTINATION "${_h_dir}"
159 endif(BuildLibrary_INSTALL_DEV)
163 ## -------------------------------------------------------------------------
164 function(BuildApplication app)
166 set(options INSTALL RECURRENT)
168 set(multiValueArgs SOURCE LINKS)
169 cmake_parse_arguments(
170 BuildApplication "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
173 set(_lib __lib__${app})
174 if(BuildApplication_RECURRENT)
178 SOURCE ${BuildApplication_SOURCE}
179 LINKS ${BuildApplication_LINKS}
181 else(BuildApplication_RECURRENT)
184 SOURCE ${BuildApplication_SOURCE}
185 LINKS ${BuildApplication_LINKS}
187 endif(BuildApplication_RECURRENT)
189 ## -- Create an empty application
190 set(_m ${CMAKE_CURRENT_BINARY_DIR}/__main__${app}.cxx)
191 file(WRITE ${_m} "// Automatically generated dummy file")
192 add_executable(${app} ${EXECUTABLE_TYPE} ${_m})
194 ## -- Link it against the static library
195 target_link_libraries(${app} PUBLIC ${_lib})
197 ## -- Installation rules
198 if(BuildApplication_INSTALL)
201 EXPORT "${targets_export_name}"
202 LIBRARY DESTINATION "lib"
203 ARCHIVE DESTINATION "lib"
204 RUNTIME DESTINATION "bin"
205 INCLUDES DESTINATION "${include_install_dir}"
207 endif(BuildApplication_INSTALL)