## -------------------------------------------------------------------------
FUNCTION(
PrepareSourceFiles
- out_lib_name
+ lib_name
out_sources_list
out_headers_list
out_headers_paths
GET_FILENAME_COMPONENT(_out_name ${_i} NAME_WE)
## -- Infere source code filenames
- MATH(EXPR _last_range "${cpPlugins_CONFIG_NUMBER_OF_FILES}-1")
+ 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)
OUTPUT ${_out_code}
DEPENDS ${cpPlugins_bash_CreateInstances_APP} ${_i}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_i_path}
- COMMAND ${cpPlugins_bash_CreateInstances_APP} ${_i} ${out_lib_name} ${_i_path}/${_out_name}
+ COMMAND ${cpPlugins_bash_CreateInstances_APP} ${_i} ${lib_name} ${_i_path}/${_out_name}
)
ENDFOREACH(_i)
ENDFUNCTION()
## -------------------------------------------------------------------------
-FUNCTION(
- CreateLib
- lib_name
- lib_type
- )
-PrepareSourceFiles(${lib_name} _srcs _hdrs _paths ${ARGN})
-INCLUDE_DIRECTORIES(
- ${_paths}
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_BINARY_DIR}
- )
+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}
EXPORT_FILE_NAME ${lib_name}_Export.h
STATIC_DEFINE ${lib_name}_BUILT_AS_STATIC
)
- IF(${prj_NAME}_All_Headers)
- SET(_hdr_tmp "${${prj_NAME}_All_Headers};${_hdrs}")
- ELSE(${prj_NAME}_All_Headers)
- SET(_hdr_tmp "${_hdrs}")
- ENDIF(${prj_NAME}_All_Headers)
- LIST(REMOVE_DUPLICATES _hdr_tmp)
- SET(${prj_NAME}_All_Headers ${_hdr_tmp} CACHE INTERNAL "All headers." FORCE)
ENDIF(_srcs)
-ENDFUNCTION()
-## -------------------------------------------------------------------------
-FUNCTION(
- CompileLibFromDir
- lib_name
- lib_type
- lib_dir
- )
-FILE(GLOB_RECURSE _files "${lib_dir}/*")
-CreateLib(${lib_name} ${lib_type} ${_files} ${ARGN})
ENDFUNCTION()
## -------------------------------------------------------------------------
-FUNCTION(
- CreatePlugin
- lib_name
- lib_dir
- )
-GET_FILENAME_COMPONENT(_lib_dir ${lib_dir} REALPATH)
-FILE(GLOB_RECURSE _files "${_lib_dir}/*")
-SET(_hdr_to_wrap)
-FOREACH(_file ${_files})
- FILE(READ ${_file} _txt)
- STRING(FIND "${_txt}" "cpPluginsObject" _res)
- IF(NOT ${_res} EQUAL -1)
- LIST(APPEND _hdr_to_wrap ${_file})
- ENDIF(NOT ${_res} EQUAL -1)
-ENDFOREACH(_file)
+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})
-IF(_hdr_to_wrap)
- STRING(
- REPLACE
- ${PROJECT_SOURCE_DIR}
- ${PROJECT_BINARY_DIR}
- _out_dir
- ${_lib_dir}
- )
- SET(_host ${_out_dir}/${lib_name}_host.cxx)
+## -- 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} ${_hdr_to_wrap}
- COMMAND ${CMAKE_COMMAND} -E make_directory ${_out_dir}
- COMMAND ${cpPlugins_bash_HostCreator_APP} ${lib_name} ${_host} ${_hdr_to_wrap}
+ DEPENDS ${cpPlugins_bash_HostCreator_APP} ${_hdrs_to_wrap}
+ COMMAND ${cpPlugins_bash_HostCreator_APP} ${lib_name} ${_host} ${_hdrs_to_wrap}
)
- LIST(APPEND _files ${_host})
-ENDIF(_hdr_to_wrap)
-
-CreateLib(${lib_name} SHARED ${_files})
+ LIST(APPEND _all_files ${_host})
+ENDIF(_hdrs_to_wrap)
+cpPlugins_BuildLibrary(${lib_name} SHARED ${_all_files})
ENDFUNCTION()
## -------------------------------------------------------------------------
-FUNCTION(
- CompileAppFromDir
- app_name
- app_dir
- )
-OPTION(BUILD_${app_name} "Build ${app_name}" OFF)
+FUNCTION(cpPlugins_BuildApplication app_name)
+OPTION(BUILD_${app_name} "Build \"${app_name}\" application?" OFF)
IF(BUILD_${app_name})
- FILE(GLOB_RECURSE _files "${app_dir}/*")
- PrepareSourceFiles(${app_name} _srcs _hdrs _paths ${_files} ${ARGN})
- INCLUDE_DIRECTORIES(
- ${_paths}
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_BINARY_DIR}
- )
+ # -- 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)