## ------------------------------------------------------------------------- FUNCTION(NormPaths output_files) SET(_out) FOREACH(_f ${ARGN}) SET(_d) FILE(TO_CMAKE_PATH ${_f} _d) LIST(APPEND _out ${_d}) ENDFOREACH(_f) SET(${output_files} "${_out}" 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}) 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}) STRING(FIND "${_dir}" "${_base_dir}" _pos) IF(${_pos} EQUAL -1) SET(_base_dir ${_binary_dir}) 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) LIST(APPEND _out ${_out_f}) ADD_CUSTOM_COMMAND( OUTPUT ${_out_f} COMMAND Qt4::uic ARGS -o ${_out_f} ${_f} MAIN_DEPENDENCY ${_f} VERBATIM ) ENDIF(NOT ${_pos} EQUAL -1) ENDIF(EXISTS ${_f}) 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) ## -- 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) # -- Prepare Qt4-based 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) 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) 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) 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}) ## -- 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) ## -- 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) cpPlugins_BuildLibrary(${lib_name} SHARED ${_all_files}) ENDFUNCTION() ## ------------------------------------------------------------------------- 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}) ## -- Prepare sources by types PrepareSourceFiles(${app_name} _srcs _hdrs _paths ${_all_files}) ## -- 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$