OpenFlipper_common.cmake 9.21 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1 2 3 4 5 6 7
set (ACG_PROJECT_MACOS_BUNDLE "1")

macro (acg_modify_project_dirs)
  # set directory structures for the different platforms
  if (WIN32)
    add_definitions(
      -D_USE_MATH_DEFINES -DNOMINMAX
Matthias Möller's avatar
Matthias Möller committed
8
      -D_CRT_SECURE_NO_WARNINGS
Jan Möbius's avatar
Dennis:  
Jan Möbius committed
9
      -DOPENFLIPPER_APPDIR="."
Jan Möbius's avatar
 
Jan Möbius committed
10 11 12 13 14 15 16 17
      -DOPENFLIPPER_PLUGINDIR="${ACG_PROJECT_PLUGINDIR}"
      -DOPENFLIPPER_DATADIR="${ACG_PROJECT_DATADIR}"
    )
    if (NOT EXISTS ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_BINDIR})
      file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_BINDIR})
    endif ()
  elseif (APPLE)
    set (MAC_OPENFLIPPER_BASEDIR "OpenFlipper.app/Contents/Resources")
Jan Möbius's avatar
Jan Möbius committed
18 19 20 21
    set (ACG_PROJECT_DATADIR "${MAC_OPENFLIPPER_BASEDIR}")
    set (ACG_PROJECT_PLUGINDIR "${MAC_OPENFLIPPER_BASEDIR}/Plugins")
    set (ACG_PROJECT_LIBDIR "${MAC_OPENFLIPPER_BASEDIR}/../MacOS")
    set (ACG_PROJECT_BINDIR "${MAC_OPENFLIPPER_BASEDIR}/../MacOS")
Jan Möbius's avatar
 
Jan Möbius committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    add_definitions(
      -DOPENFLIPPER_APPDIR="../Resources"
      -DOPENFLIPPER_PLUGINDIR="Plugins"
      -DOPENFLIPPER_DATADIR="."
    )
  else ()
    add_definitions(
      -DOPENFLIPPER_APPDIR=".."
      -DOPENFLIPPER_PLUGINDIR="${ACG_PROJECT_PLUGINDIR}"
      -DOPENFLIPPER_DATADIR="${ACG_PROJECT_DATADIR}"
    )
  endif ()
endmacro ()

# search all plugins and add them to build
function (of_add_plugins)
    file (
        GLOB _plugins_in
        RELATIVE "${CMAKE_SOURCE_DIR}"
        "${CMAKE_SOURCE_DIR}/Plugin-*/CMakeLists.txt"
Jan Möbius's avatar
Jan Möbius committed
42
        "${CMAKE_SOURCE_DIR}/PluginCollection-*/Plugin-*/CMakeLists.txt"
43 44
        "${CMAKE_SOURCE_DIR}/Package*/Plugin-*/CMakeLists.txt"
        "${CMAKE_SOURCE_DIR}/Package*/PluginCollection-*/Plugin-*/CMakeLists.txt"
Jan Möbius's avatar
Jan Möbius committed
45 46
        "${CMAKE_SOURCE_DIR}/Type-*/Plugin-*/CMakeLists.txt"
        "${CMAKE_SOURCE_DIR}/*/Type-*/Plugin-*/CMakeLists.txt"
Jan Möbius's avatar
 
Jan Möbius committed
47
    )
48
    
Jan Möbius's avatar
 
Jan Möbius committed
49 50
    foreach (_plugin ${_plugins_in})
        get_filename_component (_plugin_dir ${_plugin} PATH)
Jan Möbius's avatar
Jan Möbius committed
51

52 53
        # In INSTALLDATA_DIRS the resource directories will be handed down.
        set(INSTALLDATA_DIRS)
Jan Möbius's avatar
 
Jan Möbius committed
54
        add_subdirectory (${CMAKE_SOURCE_DIR}/${_plugin_dir})
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        
        # Add targets for data dirs
        if (INSTALLDATA_DIRS)
            # Extract plugin name
	        string (REGEX MATCH "Plugin-.+[/\\]?$" _dir ${_plugin_dir})
			string (REPLACE "Plugin-" "" _plugin ${_dir})
			
			# Crawl for resoruce files
	        set(DATA_FILES)
	        foreach (_dir ${INSTALLDATA_DIRS})
	            set(dst "${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_DATADIR}/${_dir}")
	            set(src "${CMAKE_SOURCE_DIR}/${_plugin_dir}/${_dir}")
				acg_unset (_files)
				acg_get_files_in_dir (_files ${src})
				foreach (_file ${_files})
				    add_custom_command(OUTPUT "${dst}/${_file}"
				    	DEPENDS "${src}/${_file}"
					    COMMAND ${CMAKE_COMMAND} -E copy "${src}/${_file}" "${dst}/${_file}"
			    	)
			    	# Collect command targets
			    	list(APPEND DATA_FILES "${dst}/${_file}")
			    endforeach ()
	        endforeach ()
	        # Add custom target that will copy the files and make it a
	        # dependency of the plugin target.
	        add_custom_target(RSRC-${_plugin} DEPENDS ${DATA_FILES})
	        add_dependencies(Plugin-${_plugin} RSRC-${_plugin})
82 83
                # group by folder on msvc
                GROUP_PROJECT(RSRC-${_plugin} "Ressources")
84
	    endif()
Jan Möbius's avatar
 
Jan Möbius committed
85
    endforeach ()
86 87
    
    # Hand down loaded packages to caller.
88
    set(LOADED_PACKAGES ${LOADED_PACKAGES} PARENT_SCOPE)
89 90 91 92 93 94 95 96 97 98 99 100 101

#          #acg_copy_after_build (Plugin-${plugin} "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" "${CMAKE_BINARY_DIR}/Build/${ACG_PROJECT_DATADIR}/${_dir}")
#    
#      set(OUTPUT_FILES "")
#    add_custom_command(OUTPUT "${dst}/${_file}"
#    	DEPENDS "${src}/${_file}"
#	    COMMAND ${CMAKE_COMMAND} -E copy "${src}/${_file}" "${dst}/${_file}"
#    )
#    list(APPEND OUTPUT_FILES "${dst}/${_file}")
#  get_filename_component(BASENAME "${dst}" NAME)
#  add_custom_target("${target}_CPY_${BASENAME}" DEPENDS ${OUTPUT_FILES})
#  add_dependencies(${target} "${target}_CPY_${BASENAME}")
    
Jan Möbius's avatar
 
Jan Möbius committed
102 103
endfunction ()

104
macro(_common_get_plugin_name _path _name)
Jan Möbius's avatar
Jan Möbius committed
105 106 107 108 109 110 111 112 113

   # Only get the plugins name:
   string (REGEX MATCH "Plugin-.+[/\\]?$" ${_name} ${${_path}})

   # Strip the Plugin- Prefix
   string (REPLACE "Plugin-" "" ${_name} ${${_name}})

endmacro()

Jan Möbius's avatar
 
Jan Möbius committed
114 115
# print plugin statistics
function (of_print_plugin_stats)
116

Jan Möbius's avatar
 
Jan Möbius committed
117 118 119 120 121
  acg_color_message ("\n${_escape}[4mPlugin configure check results:${_escape}[0m\n")
  file (
    GLOB _plugins_in
    RELATIVE "${CMAKE_SOURCE_DIR}"
    "${CMAKE_SOURCE_DIR}/Plugin-*"
Jan Möbius's avatar
Jan Möbius committed
122
    "${CMAKE_SOURCE_DIR}/PluginCollection-*/Plugin-*"
123 124
    "${CMAKE_SOURCE_DIR}/Package*/Plugin-*"
    "${CMAKE_SOURCE_DIR}/Package*/PluginCollection-*/Plugin-*"
Jan Möbius's avatar
Jan Möbius committed
125 126
    "${CMAKE_SOURCE_DIR}/Type-*/Plugin-*"
    "${CMAKE_SOURCE_DIR}/*/Type-*/Plugin-*"
127

Jan Möbius's avatar
 
Jan Möbius committed
128 129
  )

Jan Möbius's avatar
Jan Möbius committed
130 131
  list (SORT _plugins_in)

Jan Möbius's avatar
 
Jan Möbius committed
132
  foreach (_plugin ${_plugins_in})
Jan Möbius's avatar
Jan Möbius committed
133 134

    # Extract plugin name from path
135
    _common_get_plugin_name( _plugin _plugin_name )
Jan Möbius's avatar
Jan Möbius committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

    # Possibly get the collection name
    string (REGEX MATCH "PluginCollection-.+[/\\]" collection_name ${_plugin})
   
    # If plugin belongs to a selection, we check that here
    if ( collection_name )
        # Strip the Plugin- Prefix
        string (REPLACE "PluginCollection-" "" collection_name ${collection_name})
        string (REPLACE "/" "" collection_name ${collection_name})
    endif()

    # TODO Group the plugins by selection!
    # TODO Correctly sort plugins by their name

    # We need the upper case name that is used for the plugin handling variables
Jan Möbius's avatar
 
Jan Möbius committed
151
    string (TOUPPER ${_plugin_name} _PLUGIN)
Jan Möbius's avatar
Jan Möbius committed
152

Jan Möbius's avatar
 
Jan Möbius committed
153 154 155 156 157 158 159
    if (NOT EXISTS ${CMAKE_SOURCE_DIR}/${_plugin}/CMakeLists.txt AND DISABLE_QMAKE_BUILD)
      list (APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_SOURCE_DIR}/${_plugin}")
    elseif (DISABLE_PLUGIN_${_PLUGIN})
      list (APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_SOURCE_DIR}/${_plugin}")
    endif ()
  endforeach ()

160 161 162 163 164 165 166

  # Sort plugins into lists depending on configure status:
  set (PLUGINS_OK "")
  set (PLUGINS_DISABLED "")
  set (PLUGINS_DEPENDENCIES "")
  set (PLUGINS_NO_CMAKE "")

Jan Möbius's avatar
 
Jan Möbius committed
167
  foreach (_plugin ${_plugins_in})
Jan Möbius's avatar
Jan Möbius committed
168 169

     # Extract plugin name from path
170
     _common_get_plugin_name( _plugin _plugin_name )
Jan Möbius's avatar
Jan Möbius committed
171 172

     # We need the upper case name that is used for the plugin handling variables
173
     string (TOUPPER ${_plugin_name} _PLUGIN)
Jan Möbius's avatar
Jan Möbius committed
174 175 176 177 178 179 180 181 182

     # Disable the problematic plugins in the cpack pass
     if (NOT EXISTS ${CMAKE_SOURCE_DIR}/${_plugin}/CMakeLists.txt AND DISABLE_QMAKE_BUILD)
       list (APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_SOURCE_DIR}/${_plugin}")
     elseif (DISABLE_PLUGIN_${_PLUGIN})
       list (APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_SOURCE_DIR}/${_plugin}")
     endif ()

     
183
     acg_format_string (${_plugin_name} 25 _plugin_name)
Jan Möbius's avatar
 
Jan Möbius committed
184

185
     if (DISABLE_PLUGIN_${_PLUGIN})
Jan Möbius's avatar
Jan Möbius committed
186
          list( APPEND PLUGINS_DISABLED ${_plugin_name} )
Jan Möbius's avatar
 
Jan Möbius committed
187
      elseif (NOT EXISTS ${CMAKE_SOURCE_DIR}/${_plugin}/CMakeLists.txt)
Jan Möbius's avatar
Jan Möbius committed
188
           list( APPEND PLUGINS_NO_CMAKE ${_plugin_name} )
Jan Möbius's avatar
 
Jan Möbius committed
189 190
      else ()
          if (OPENFLIPPER_${_PLUGIN}_BUILD)
Jan Möbius's avatar
Jan Möbius committed
191
              list( APPEND PLUGINS_OK ${_plugin_name} )
Jan Möbius's avatar
 
Jan Möbius committed
192
          else ()
Jan Möbius's avatar
Jan Möbius committed
193
              list( APPEND PLUGINS_DEPENDENCIES ${_plugin_name} )
Jan Möbius's avatar
 
Jan Möbius committed
194 195 196
          endif ()
      endif ()
  endforeach ()
197 198 199

  message ("")

Jan Möbius's avatar
Jan Möbius committed
200 201 202
  # The minimal distance to the : to allow all plugin names to fit into the column
  set (SPACING 30)

203
  # Print all plugins, which have no cmake build system
204 205 206
  acg_color_message ("\n${_escape}[4mPlugins without cmake build system:${_escape}[0m\n")
  foreach (_plugin ${PLUGINS_NO_CMAKE})
    string (REPLACE "Plugin-" "" _plugin_name ${_plugin})
Jan Möbius's avatar
Jan Möbius committed
207
    acg_format_string (${_plugin_name} ${SPACING} _plugin_name)
208
 
209 210
    acg_color_message ("  ${_plugin_name}: ${_escape}[1;34mNo CMake build system${_escape}[0m")
  endforeach ()
211

212
  message ("")
213 214

  # Print all plugins, which are ok
215
  acg_color_message ("\n${_escape}[4mPlugins configured successfully:${_escape}[0m\n")
Jan Möbius's avatar
Jan Möbius committed
216
  list( SORT PLUGINS_OK )
217 218
  foreach (_plugin ${PLUGINS_OK})
    string (REPLACE "Plugin-" "" _plugin_name ${_plugin})
Jan Möbius's avatar
Jan Möbius committed
219
    acg_format_string (${_plugin_name} ${SPACING} _plugin_name)
220
 
221 222
    acg_color_message ("  ${_plugin_name}: ${_escape}[1;32mYes${_escape}[0m")
  endforeach ()
223

224
  message ("")
225 226 227


  # Print all plugins, which are disabled
228
  acg_color_message ("\n${_escape}[4mPlugins disabled:${_escape}[0m\n")
Jan Möbius's avatar
Jan Möbius committed
229
  list( SORT PLUGINS_DISABLED )
230 231
  foreach (_plugin ${PLUGINS_DISABLED})
    string (REPLACE "Plugin-" "" _plugin_name ${_plugin})
Jan Möbius's avatar
Jan Möbius committed
232
    acg_format_string (${_plugin_name} ${SPACING} _plugin_name)
233 234 235
                                                                                     
    acg_color_message ("  ${_plugin_name}: ${_escape}[1;34mDisabled${_escape}[0m")
  endforeach ()
236

237
  message ("")
238

239
  # Print all plugins, which have missing dependencies
240
  acg_color_message ("\n${_escape}[4mPlugins with missing dependencies:${_escape}[0m\n")
Jan Möbius's avatar
Jan Möbius committed
241
  list( SORT PLUGINS_DEPENDENCIES )
242 243 244
  foreach (_plugin ${PLUGINS_DEPENDENCIES})
    string (REPLACE "Plugin-" "" _plugin_name ${_plugin})
    string (TOUPPER ${_plugin_name} _PLUGIN)
245 246 247 248 249
    acg_format_string (${_plugin_name} ${SPACING} _plugin_name_spaced)
    string(STRIP ${_PLUGIN} _PLUGIN)
    
    acg_color_message ("  ${_plugin_name_spaced}: ${_escape}[1;31mNo${_escape}[0m (Missing dependencies :${_${_PLUGIN}_MISSING_DEPS})")
   
250 251 252
  endforeach ()
  
  message ("")
253
 
254

255
  if ( NOT WIN32 )
256
    message("${_escape}[4mCurrent Build Type:${_escape}[0m ${_escape}[1;34m ${CMAKE_BUILD_TYPE} ${_escape}[0m")
257
  endif()
Jan Möbius's avatar
 
Jan Möbius committed
258
  message ("")
259 260


Jan Möbius's avatar
 
Jan Möbius committed
261
endfunction ()