## =========================================================================
## -------------------------------------------------------------------------
-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})
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})
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$