## -------------------------------------------------------------------------
-FUNCTION(NormPaths output_files)
-SET(_out)
+FUNCTION(cpPlugins_GetFiles output)
+SET(_o)
FOREACH(_f ${ARGN})
- SET(_d)
- FILE(TO_CMAKE_PATH ${_f} _d)
- LIST(APPEND _out ${_d})
+ FILE(GLOB_RECURSE _r "${_f}")
+ LIST(APPEND _o ${_r})
ENDFOREACH(_f)
-SET(${output_files} "${_out}" PARENT_SCOPE)
+SET(${output} "${_o}" PARENT_SCOPE)
ENDFUNCTION()
-
## -------------------------------------------------------------------------
-FUNCTION(Wrap_Qt_CPP output_files)
-SET(_out)
-FOREACH(_f ${ARGN})
- IF(EXISTS ${_f})
- FILE(READ ${_f} _txt)
- STRING(FIND "${_txt}" "Q_OBJECT" _pos)
- IF(NOT ${_pos} EQUAL -1)
- SET(_s)
- QT4_WRAP_CPP(_s ${_f})
- SET(_out ${_out} ${_s})
- ENDIF(NOT ${_pos} EQUAL -1)
- ENDIF(EXISTS ${_f})
-ENDFOREACH(_f)
-SET(${output_files} "${_out}" PARENT_SCOPE)
-ENDFUNCTION()
## -------------------------------------------------------------------------
FUNCTION(Wrap_Qt_UI output_files)
-NormPaths(_source_dir ${PROJECT_SOURCE_DIR})
-NormPaths(_binary_dir ${PROJECT_BINARY_DIR})
+GET_FILENAME_COMPONENT(_src ${PROJECT_SOURCE_DIR} ABSOLUTE)
+GET_FILENAME_COMPONENT(_bin ${PROJECT_BINARY_DIR} ABSOLUTE)
SET(_out)
FOREACH(_f ${ARGN})
IF(EXISTS ${_f})
GET_FILENAME_COMPONENT(_name ${_f} NAME_WE)
GET_FILENAME_COMPONENT(_dir ${_f} DIRECTORY)
- SET(_base_dir ${_source_dir})
+ SET(_base_dir ${_src})
STRING(FIND "${_dir}" "${_base_dir}" _pos)
IF(${_pos} EQUAL -1)
- SET(_base_dir ${_binary_dir})
+ SET(_base_dir ${_bin})
STRING(FIND "${_dir}" "${_base_dir}" _pos)
ENDIF(${_pos} EQUAL -1)
IF(NOT ${_pos} EQUAL -1)
STRING(REPLACE "${_base_dir}/" "" _dir ${_dir})
- SET(_out_f ${_binary_dir}/${_dir}/ui_${_name}.h)
+ SET(_out_f ${_bin}/${_dir}/ui_${_name}.h)
LIST(APPEND _out ${_out_f})
ADD_CUSTOM_COMMAND(
OUTPUT ${_out_f}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${_bin}/${_dir}
COMMAND Qt4::uic
ARGS -o ${_out_f} ${_f}
MAIN_DEPENDENCY ${_f} VERBATIM
ENDFOREACH(_f)
SET(${output_files} "${_out}" PARENT_SCOPE)
ENDFUNCTION()
-
## -------------------------------------------------------------------------
-FUNCTION(
- PrepareSourceFiles
- lib_name
- out_sources_list
- out_headers_list
- out_headers_paths
- )
-SET(_config_extensions .c.in .cpp.in .cxx.in .h.in .hpp.in .hxx.in .ui.in)
-SET(_sources_extensions .c .cpp .cxx)
-SET(_headers_extensions .h .hpp .hxx)
-SET(_qt_ui_extensions .ui)
-SET(_demangler_extensions .d)
-SET(_instances_extensions .i)
-## -- Configure inputs
-SET(_all_files)
-FOREACH(_file ${ARGN})
- GET_FILENAME_COMPONENT(_ext ${_file} EXT)
- LIST(FIND _config_extensions ${_ext} _cfg)
- IF(NOT ${_cfg} EQUAL -1)
- STRING(
- REPLACE
- ${PROJECT_SOURCE_DIR}
- ${PROJECT_BINARY_DIR}
- _file_bin
- ${_file}
- )
- STRING(LENGTH ${_file_bin} _file_bin_len)
- MATH(EXPR _file_bin_len "${_file_bin_len}-3")
- STRING(SUBSTRING ${_file_bin} 0 ${_file_bin_len} _file_bin)
- CONFIGURE_FILE(${_file} ${_file_bin} @ONLY)
- LIST(APPEND _all_files ${_file_bin})
- ELSE(NOT ${_cfg} EQUAL -1)
- LIST(APPEND _all_files ${_file})
- ENDIF(NOT ${_cfg} EQUAL -1)
-ENDFOREACH(_file)
+## -------------------------------------------------------------------------
+FUNCTION(cpPlugins_PrepareFiles out_src out_hdr out_dirs)
-## -- Separate files
-SET(_srcs)
-SET(_hdrs)
-SET(_qts)
-SET(_demanglers)
-SET(_instances)
-FOREACH(_file ${_all_files})
- GET_FILENAME_COMPONENT(_ext ${_file} EXT)
- LIST(FIND _sources_extensions ${_ext} _src)
- LIST(FIND _headers_extensions ${_ext} _hdr)
- LIST(FIND _qt_ui_extensions ${_ext} _ui)
- LIST(FIND _demangler_extensions ${_ext} _dem)
- LIST(FIND _instances_extensions ${_ext} _ins)
- IF(NOT ${_src} EQUAL -1)
- LIST(APPEND _srcs ${_file})
- ENDIF(NOT ${_src} EQUAL -1)
- IF(NOT ${_hdr} EQUAL -1)
- LIST(APPEND _hdrs ${_file})
- ENDIF(NOT ${_hdr} EQUAL -1)
- IF(NOT ${_ui} EQUAL -1)
- LIST(APPEND _qts ${_file})
- ENDIF(NOT ${_ui} EQUAL -1)
- IF(NOT ${_dem} EQUAL -1)
- LIST(APPEND _demanglers ${_file})
- ENDIF(NOT ${_dem} EQUAL -1)
- IF(NOT ${_ins} EQUAL -1)
- LIST(APPEND _instances ${_file})
- ENDIF(NOT ${_ins} EQUAL -1)
-ENDFOREACH(_file)
+## -- Separe files by extension
+SET(_src)
+SET(_hdr)
+SET(_ui)
+SET(_dirs)
+FOREACH(_f ${ARGN})
+ GET_FILENAME_COMPONENT(_file ${_f} ABSOLUTE)
+ GET_FILENAME_COMPONENT(_e ${_file} EXT)
+ STRING(TOLOWER ${_e} _ext)
+ STRING(COMPARE EQUAL "${_ext}" ".c" _cmp_c)
+ STRING(COMPARE EQUAL "${_ext}" ".cpp" _cmp_cpp)
+ STRING(COMPARE EQUAL "${_ext}" ".cxx" _cmp_cxx)
+ STRING(COMPARE EQUAL "${_ext}" ".h" _cmp_h)
+ STRING(COMPARE EQUAL "${_ext}" ".hpp" _cmp_hpp)
+ STRING(COMPARE EQUAL "${_ext}" ".hxx" _cmp_hxx)
+ STRING(COMPARE EQUAL "${_ext}" ".ui" _cmp_ui)
+ IF(_cmp_c OR _cmp_cpp OR _cmp_cxx)
+ LIST(APPEND _src ${_file})
+ ENDIF(_cmp_c OR _cmp_cpp OR _cmp_cxx)
+ IF(_cmp_h OR _cmp_hpp OR _cmp_hxx)
+ LIST(APPEND _hdr ${_file})
+ GET_FILENAME_COMPONENT(_d ${_file} DIRECTORY)
+ LIST(APPEND _dirs ${_d})
+ ENDIF(_cmp_h OR _cmp_hpp OR _cmp_hxx)
+ IF(_cmp_ui)
+ LIST(APPEND _ui ${_file})
+ ENDIF(_cmp_ui)
+ENDFOREACH(_f)
-# -- Prepare Qt4-based code
+## -- Wrap possible Qt code
IF(Qt4_FOUND)
- ## -- Guess what headers sould be qt-moc'ed
- Wrap_Qt_CPP(_moc ${_hdrs})
- IF(_moc)
- LIST(APPEND _srcs ${_moc})
- ENDIF(_moc)
- ## -- Guess what qt-ui's sould be qt-uic'ed
- ## -- Wrap qt-ui headers: this is equivalent to QT4_WRAP_UI except to change
- ## -- the output file
- Wrap_Qt_UI(_qt_hdrs ${_qts})
- IF(_qt_hdrs)
- LIST(APPEND _hdrs ${_qt_hdrs})
- ENDIF(_qt_hdrs)
+ ## -- Wrap user interfaces
+ Wrap_Qt_UI(_qt_ui_hdr ${_ui})
+ FOREACH(_h ${_qt_ui_hdr})
+ LIST(APPEND _hdr ${_h})
+ GET_FILENAME_COMPONENT(_d ${_h} DIRECTORY)
+ LIST(APPEND _dirs ${_d})
+ ENDFOREACH(_h)
+
+ ## -- Wrap headers
+ SET(_qt_src)
+ FOREACH(_f ${_hdr} ${_src})
+ IF(EXISTS ${_f})
+ FILE(READ ${_f} _txt)
+ STRING(FIND "${_txt}" "Q_OBJECT" _pos)
+ IF(NOT ${_pos} EQUAL -1)
+ SET(_s)
+ QT4_WRAP_CPP(_s ${_f})
+ LIST(APPEND _qt_src ${_s})
+ ENDIF(NOT ${_pos} EQUAL -1)
+ ENDIF(EXISTS ${_f})
+ ENDFOREACH(_f ${_hdr} ${_src})
+ LIST(APPEND _src ${_qt_src})
ENDIF(Qt4_FOUND)
-## -- Create demanglers
-FOREACH(_d ${_demanglers})
- STRING(
- REPLACE
- ${PROJECT_SOURCE_DIR}
- ${PROJECT_BINARY_DIR}
- _d_bin
- ${_d}
- )
- GET_FILENAME_COMPONENT(_d_path ${_d_bin} DIRECTORY)
- GET_FILENAME_COMPONENT(_out_name ${_d_bin} NAME_WE)
- SET(_d_out ${_d_path}/${_out_name}_Demanglers.h)
- ADD_CUSTOM_COMMAND(
- OUTPUT ${_d_out}
- COMMAND ${CMAKE_COMMAND} -E make_directory ${_d_path}
- COMMAND ${cpPlugins_bash_CreateDemanglers_APP} ${_d} ${_out_name} ${_d_out}
- DEPENDS ${cpPlugins_bash_CreateDemanglers_APP} ${_d}
- )
- LIST(APPEND _hdrs ${_d_out})
-ENDFOREACH(_d)
-
-## -- Create instances
-FOREACH(_i ${_instances})
- STRING(
- REPLACE
- ${PROJECT_SOURCE_DIR}
- ${PROJECT_BINARY_DIR}
- _i_bin
- ${_i}
- )
- GET_FILENAME_COMPONENT(_i_path ${_i_bin} DIRECTORY)
- GET_FILENAME_COMPONENT(_out_name ${_i} NAME_WE)
-
- ## -- Infere source code filenames
- MATH(EXPR _last_range "${cpPlugins_NUMBER_OF_FILES}-1")
- SET(_out_code)
- FOREACH(_n RANGE 0 ${_last_range})
- LIST(APPEND _out_code ${_i_path}/${_out_name}_${_n}.cxx)
- LIST(APPEND _srcs ${_i_path}/${_out_name}_${_n}.cxx)
- ENDFOREACH(_n)
-
- ## -- Command to write source code
- ADD_CUSTOM_COMMAND(
- OUTPUT ${_out_code}
- DEPENDS ${cpPlugins_bash_CreateInstances_APP} ${_i}
- COMMAND ${CMAKE_COMMAND} -E make_directory ${_i_path}
- COMMAND ${cpPlugins_bash_CreateInstances_APP} ${_i} ${lib_name} ${_i_path}/${_out_name}
- )
-ENDFOREACH(_i)
-
-## -- Real compilation
-SET(_hdrs_paths)
-FOREACH(_hdr ${_hdrs})
- GET_FILENAME_COMPONENT(_path ${_hdr} DIRECTORY)
- LIST(FIND _hdrs_paths ${_path} _path_idx)
- IF(${_path_idx} EQUAL -1)
- LIST(APPEND _hdrs_paths ${_path})
- ENDIF(${_path_idx} EQUAL -1)
-ENDFOREACH(_hdr)
-
-SET(${out_sources_list} ${_srcs} PARENT_SCOPE)
-SET(${out_headers_list} ${_hdrs} PARENT_SCOPE)
-SET(${out_headers_paths} ${_hdrs_paths} PARENT_SCOPE)
+## -- Outputs
+SET(${out_src} "${_src}" PARENT_SCOPE)
+SET(${out_hdr} "${_hdr}" PARENT_SCOPE)
+SET(${out_dirs} "${_dirs}" PARENT_SCOPE)
ENDFUNCTION()
+## -------------------------------------------------------------------------
## -------------------------------------------------------------------------
FUNCTION(cpPlugins_BuildLibrary lib_name lib_type)
-# -- Detect all source files
-SET(_all_files)
-FOREACH(_c ${ARGN})
- GET_FILENAME_COMPONENT(_cname ${_c} ABSOLUTE)
- SET(_files)
- IF(IS_DIRECTORY ${_cname})
- FILE(GLOB_RECURSE _files "${_cname}/*")
- ELSE(IS_DIRECTORY ${_cname})
- SET(_files ${_cname})
- ENDIF(IS_DIRECTORY ${_cname})
- LIST(APPEND _all_files ${_files})
-ENDFOREACH(_c ${ARGN})
-
-## -- Prepare sources by types
-PrepareSourceFiles(${lib_name} _srcs _hdrs _paths ${_all_files})
-## -- Build library
-IF(_srcs)
- INCLUDE_DIRECTORIES(
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_BINARY_DIR}
- )
- ADD_LIBRARY(${lib_name} ${lib_type} ${_srcs} ${_hdrs})
- GENERATE_EXPORT_HEADER(
- ${lib_name}
- BASE_NAME ${lib_name}
- EXPORT_MACRO_NAME ${lib_name}_EXPORT
- EXPORT_FILE_NAME ${lib_name}_Export.h
- STATIC_DEFINE ${lib_name}_BUILT_AS_STATIC
- )
-ENDIF(_srcs)
+## -- Prepare files
+cpPlugins_PrepareFiles(_src _hdr _dirs ${ARGN})
+
+## -- Create library
+ADD_LIBRARY(${lib_name} ${lib_type} ${_src} ${_hdr})
+GENERATE_EXPORT_HEADER(
+ ${lib_name}
+ BASE_NAME ${lib_name}
+ EXPORT_MACRO_NAME ${lib_name}_EXPORT
+ EXPORT_FILE_NAME ${lib_name}_Export.h
+ STATIC_DEFINE ${lib_name}_BUILT_AS_STATIC
+ )
ENDFUNCTION()
-
## -------------------------------------------------------------------------
-FUNCTION(cpPlugins_BuildPluginsLibrary lib_name)
-# -- Detect all source files
-SET(_all_files)
-FOREACH(_c ${ARGN})
- GET_FILENAME_COMPONENT(_cname ${_c} ABSOLUTE)
- SET(_files)
- IF(IS_DIRECTORY ${_cname})
- FILE(GLOB_RECURSE _files "${_cname}/*")
- ELSE(IS_DIRECTORY ${_cname})
- SET(_files ${_cname})
- ENDIF(IS_DIRECTORY ${_cname})
- LIST(APPEND _all_files ${_files})
-ENDFOREACH(_c ${ARGN})
-## -- Prepare sources by types
-PrepareSourceFiles(${lib_name} _srcs _hdrs _paths ${_all_files})
+## -------------------------------------------------------------------------
+FUNCTION(cpPlugins_BuildLibraryFromDirectory lib_name lib_type lib_dir)
+INCLUDE_DIRECTORIES(
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ )
+cpPlugins_GetFiles(_files "${lib_dir}/*")
+cpPlugins_BuildLibrary(${lib_name} ${lib_type} ${_files} ${ARGN})
+ENDFUNCTION()
+## -------------------------------------------------------------------------
-## -- Check which headers need to be wrapped to build host code
-SET(_hdrs_to_wrap)
-FOREACH(_hdr ${_hdrs})
- IF(EXISTS ${_hdr})
- FILE(READ ${_hdr} _txt)
- STRING(FIND "${_txt}" "cpPluginsObject" _res)
- IF(NOT ${_res} EQUAL -1)
- LIST(APPEND _hdrs_to_wrap ${_hdr})
- ENDIF(NOT ${_res} EQUAL -1)
- ENDIF(EXISTS ${_hdr})
-ENDFOREACH(_hdr)
+## -------------------------------------------------------------------------
+FUNCTION(cpPlugins_BuildApplicationFromDirectory app_name app_dir)
-## -- Wrap headers
-IF(_hdrs_to_wrap)
- SET(_host ${CMAKE_CURRENT_BINARY_DIR}/${lib_name}_host.cxx)
- ADD_CUSTOM_COMMAND(
- OUTPUT ${_host}
- DEPENDS ${cpPlugins_bash_HostCreator_APP} ${_hdrs_to_wrap}
- COMMAND ${cpPlugins_bash_HostCreator_APP} ${lib_name} ${_host} ${_hdrs_to_wrap}
- )
- LIST(APPEND _all_files ${_host})
-ENDIF(_hdrs_to_wrap)
+## -- Prepare files
+cpPlugins_GetFiles(_files "${app_dir}/*")
+cpPlugins_PrepareFiles(_src _hdr _dirs ${_files})
-cpPlugins_BuildLibrary(${lib_name} SHARED ${_all_files})
-ENDFUNCTION()
+## -- Guess compilation source
+SET(_app_os_target)
+IF(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+ SET(_app_os_target WIN32)
+ELSEIF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+ SET(_app_os_target MACOSX_BUNDLE)
+ENDIF(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
-## -------------------------------------------------------------------------
-FUNCTION(cpPlugins_BuildApplication app_name)
-OPTION(BUILD_${app_name} "Build \"${app_name}\" application?" OFF)
-IF(BUILD_${app_name})
- # -- Detect all source files
- SET(_all_files)
- FOREACH(_c ${ARGN})
- GET_FILENAME_COMPONENT(_cname ${_c} ABSOLUTE)
- SET(_files)
- IF(IS_DIRECTORY ${_cname})
- FILE(GLOB_RECURSE _files "${_cname}/*")
- ELSE(IS_DIRECTORY ${_cname})
- SET(_files ${_cname})
- ENDIF(IS_DIRECTORY ${_cname})
- LIST(APPEND _all_files ${_files})
- ENDFOREACH(_c ${ARGN})
+## -- Include directories
+INCLUDE_DIRECTORIES(${_dirs})
- ## -- Prepare sources by types
- PrepareSourceFiles(${app_name} _srcs _hdrs _paths ${_all_files})
+## -- Compile application
+ADD_EXECUTABLE(${app_name} ${_app_os_target} ${_src} ${_hdr})
- ## -- Build library
- IF(_srcs)
- INCLUDE_DIRECTORIES(
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_BINARY_DIR}
- )
- SET(_app_os_target)
- IF(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
- SET(_app_os_target WIN32)
- ELSEIF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
- SET(_app_os_target MACOSX_BUNDLE)
- ENDIF(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
- ADD_EXECUTABLE(${app_name} ${_app_os_target} ${_srcs} ${_hdrs})
- ENDIF(_srcs)
-ENDIF(BUILD_${app_name})
ENDFUNCTION()
+## -------------------------------------------------------------------------
## eof - $RCSfile$