Browse Source

Added support for libdepend files

Clemens-Alexander Brust 11 years ago
parent
commit
2a09365fb0
2 changed files with 123 additions and 13 deletions
  1. 86 0
      CMakeLists.txt
  2. 37 13
      cmake/NiceModules.cmake

+ 86 - 0
CMakeLists.txt

@@ -33,6 +33,8 @@ set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR})
 
 set(NICE_SOURCEFILES_FIND_GLOBALLYRECURSIVE ON CACHE STRING "Scan a sublibraries directory for source files instead of using an explicit src file list")
 
+set(external_deps "")
+
 NICE_OPTION(WITH_MEX "Build with MEX support" OFF)
 if(WITH_MEX)
   set(MATLAB_DEFAULT_ROOT "/home/matlab/8.2/academic")
@@ -77,6 +79,7 @@ if(WITH_MEX)
   SET(MEX_ENDING ".mexa64")
   ADD_DEFINITIONS("-DNICE_USELIB_MEX")
   MESSAGE(STATUS "Found mex libraries at ${MEX_LIBRARIES}")
+  set(external_deps ${external_deps} "MEX")
 endif()
 
 NICE_OPTION(WITH_BOOST "Build with Boost support" OFF)
@@ -89,6 +92,7 @@ if(WITH_BOOST)
       ADD_DEFINITIONS( "-DNICE_BOOST_FOUND" )
 	  ADD_DEFINITIONS( "-DNICE_USELIB_BOOST" )
   ENDIF()
+  set(external_deps ${external_deps} "BOOST")
 endif()
 
 FIND_PACKAGE(CppUnit)
@@ -101,6 +105,7 @@ else()
   #set(CPPUNIT_INCLUDE_DIR "/usr/include/") #can be found in  /usr/include/cppunit
  # ADD_DEFINITIONS( "-DNICE_USELIB_CPPUNIT" )
   message(STATUS "CppUnit not found")
+  set(external_deps ${external_deps} "BOOST")
 ENDIF()
 
 NICE_OPTION(WITH_DBV_LIBRARIES "Build with DBV extern librares" OFF)
@@ -122,6 +127,7 @@ if(WITH_DBV_LIBRARIES)
 	ADD_DEFINITIONS( "-lpthread" )
         INCLUDE_DIRECTORIES(${IPP_INCLUDE_DIRS})
         
+        set(external_deps ${external_deps} "IPP")
       else()
         message(STATUS "IPP library not found")
       endif()
@@ -136,6 +142,7 @@ if(WITH_DBV_LIBRARIES)
         INCLUDE_DIRECTORIES(${LINAL_INCLUDE_DIR})
 	#message(STATUS "linal link libs: ${LINAL_LIBRARIES}")
         message(STATUS "Using LinAl include dir: ${LINAL_INCLUDE_DIR}")
+        set(external_deps ${external_deps} "LINAL")
       endif()
     endif()
 
@@ -152,6 +159,7 @@ if(WITH_OPENMP)
       set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
       set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
       ADD_DEFINITIONS( "-DNICE_USELIB_OPENMP")
+      set (external_deps ${external_deps} "OPENMP")
   endif()
 endif()
 
@@ -161,6 +169,7 @@ if(WITH_PNG)
     if (PNG_FOUND)
       INCLUDE_DIRECTORIES(${PNG_INCLUDE_DIRS})
       ADD_DEFINITIONS( "-DNICE_USELIB_PNG")
+      set (external_deps ${external_deps} "PNG")
     endif()
 endif()
 
@@ -175,6 +184,7 @@ if(WITH_MATIO)
     message(STATUS "Matio-dir: ${MATIO_INCLUDE_DIRS}")
     ADD_DEFINITIONS( "-DNICE_USELIB_MATIO")
     INCLUDE_DIRECTORIES(${MATIO_INCLUDE_DIRS})
+    set (external_deps ${external_deps} "MATIO")
   endif()
 endif()
 
@@ -200,6 +210,8 @@ if(WITH_QT)
     INCLUDE(${QT_USE_FILE})
     ADD_DEFINITIONS(${QT_DEFINITIONS})
     ADD_DEFINITIONS( "-DNICE_USELIB_QT")
+    set(external_deps ${external_deps} "QT4")
+    set(external_deps ${external_deps} "QT4_XML")
   endif()
 endif()
 
@@ -288,6 +300,80 @@ foreach(_curSubdir ${__listSubDirs})
 	endif()
 endforeach()
 
+set(internal_deps "")
+
+
+foreach(_curSubLib ${__listSubLibs})
+	nice_get_real_path(__modpath "${NICE_CURR_DIR}/${_curSubLib}")
+	message(STATUS "Scanning ${__modpath}...")
+	SUBDIRREC(__depDirs "${__modpath}")
+	foreach(__depDir ${__depDirs})
+		#message(STATUS "Adding (${_curSubLib}) ${__depDir} to list...")
+		set(internal_deps ${internal_deps} ${_curSubLib}/${__depDir})
+	endforeach()
+	set(internal_deps ${internal_deps} ${_curSubLib})
+endforeach()
+
+set(update_dependencies ON)
+
+while(update_dependencies)
+	message(STATUS "updating dependencies...")
+	set(update_dependencies OFF)
+	set(remove_these "")
+	foreach(_curDep ${internal_deps})
+		nice_get_real_path(_curDepPath ${NICE_CURR_DIR}/${_curDep})
+		if(EXISTS ${_curDepPath}/libdepend.inc)
+			#message(STATUS "Reading dependencies for ${_curDep}...")
+			file(STRINGS ${_curDepPath}/libdepend.inc _dependencies REGEX "^[$][(]call( )+PKG_DEPEND_INT,")
+			file(STRINGS ${_curDepPath}/libdepend.inc _extdependencies REGEX "^[$][(]call( )+PKG_DEPEND_EXT,")
+			#message(STATUS "Deps: ${_dependencies}")
+			#message(STATUS "Deps: ${_extdependencies}")
+
+			list(LENGTH _dependencies _depCount)
+			if(${_depCount} GREATER 0)
+				foreach(_innerDep ${_dependencies})
+					string(REGEX REPLACE "^[$][(]call( )+PKG_DEPEND_INT,(.*)[)].*$" "\\2" _innerDepName "${_innerDep}")
+					string(REGEX REPLACE "(.*)/$" "\\1" _innerDepName ${_innerDepName})
+					#message(STATUS "Inner dep: ${_innerDepName} (command: ${_innerDep})")
+					list(FIND internal_deps "${_innerDepName}" _innerDepFound)
+					if(${_innerDepFound} LESS 0)
+						message(STATUS "Removing ${_curDep} from build because ${_innerDepName} is missing") 
+						set(remove_these ${remove_these} ${_curDep})	
+						set(update_dependencies ON)
+					endif()
+				endforeach()
+			endif()
+
+			list(LENGTH _extdependencies _extdepCount)
+			if(${_depCount} GREATER 0)
+				foreach(_extDep ${_extdependencies})
+					string(REGEX REPLACE "^[$][(]call( )+PKG_DEPEND_EXT,(.*)[)].*$" "\\2" _extDepName "${_extDep}")
+					string(REGEX REPLACE "(.*)/$" "\\1" _extDepName ${_extDepName})
+					#message(STATUS "External dep: ${_extDepName} (command: ${_extDep})")
+					list(FIND external_deps "${_extDepName}" _extDepFound)
+					if(${_extDepFound} LESS 0)
+						message(STATUS "Removing ${_curDep} from build because ${_extDepName} (external) is missing")
+						set(remove_these ${remove_these} ${_curDep})
+						set(update_dependencies ON)
+					endif()
+				endforeach()
+			endif()
+
+		endif()
+	endforeach()
+	foreach(_toRemove ${remove_these})
+		message(STATUS "Checking subdirectories for ${_toRemove}")
+		foreach(_checkDep ${internal_deps})
+			if(${_checkDep} MATCHES "^${_toRemove}.*$")
+				message(STATUS "Removing ${_checkDep}...")
+				LIST(REMOVE_ITEM internal_deps ${_checkDep})
+			endif()
+		endforeach()
+	endforeach()
+endwhile()
+
+message(STATUS "Done.")
+message(STATUS "${internal_deps}")
 foreach(_curSublib ${__listSubLibs})
   if(BUILD_LIB_${_curSublib})
     nice_get_real_path(__modpath "${NICE_CURR_DIR}/${_curSublib}/")

+ 37 - 13
cmake/NiceModules.cmake

@@ -20,6 +20,21 @@ MACRO(SUBDIRLIST result curdir)
   SET(${result} ${dirlist})
 ENDMACRO()
 
+MACRO(SUBDIRREC result curdir)
+	FILE(GLOB_RECURSE children RELATIVE ${curdir} ${curdir}/*.c ${curdir}/*.cpp ${curdir}/*.h ${curdir}/*.tcc ${curdir}/Makefile)
+	SET(dirlist "")
+	FOREACH(child ${children})
+		#message(STATUS ${child})
+		GET_FILENAME_COMPONENT(to_add ${curdir}/${child} PATH)
+		FILE(RELATIVE_PATH to_add_rel ${curdir} ${to_add})
+		IF(IS_DIRECTORY ${curdir}/${to_add_rel})
+			SET(dirlist ${dirlist} ${to_add_rel})
+		ENDIF()
+	ENDFOREACH()
+	LIST(REMOVE_DUPLICATES dirlist)
+	SET(${result} ${dirlist})
+ENDMACRO()
+
 # get absolute path with symlinks resolved
 macro(nice_get_real_path VAR PATHSTR)
   if(CMAKE_VERSION VERSION_LESS 2.8)
@@ -80,19 +95,28 @@ macro(nice_get_source_files)
     file(GLOB_RECURSE list_tmp1 RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.cpp *.tcc *.c)
     #message(STATUS "list_tmp1: ${list_tmp1}")
     foreach( t_SrcFile ${list_tmp1})
-      if( NOT t_SrcFile MATCHES "moc_" )
-        if( t_SrcFile MATCHES "tests/" )
-          #message(STATUS "test: ${t_SrcFile}")
-          LIST(APPEND nice_${the_library}_TESTFILES_SRC ${t_SrcFile})
-        elseif( t_SrcFile MATCHES "progs/" )
-          #message(STATUS "prog: ${t_SrcFile}")
-          LIST(APPEND nice_${the_library}_PROGFILES_SRC ${t_SrcFile})
-	elseif( t_SrcFile MATCHES "Mex[.]" )
-	  message(STATUS "mex: ${t_SrcFile}")
-          LIST(APPEND nice_${the_library}_MEXFILES_SRC ${t_SrcFile})
-        else()
-          LIST(APPEND nice_${the_library}_SRC ${t_SrcFile})
-        endif()
+      get_filename_component(t_SrcPath ${t_SrcFile} PATH)
+      set(t_SrcPath ${the_library}/${t_SrcPath})
+      string(REGEX REPLACE "(.*)/+$" "\\1" t_SrcPath ${t_SrcPath})
+      list(FIND internal_deps ${t_SrcPath} dep_index)
+      if(NOT ${dep_index} LESS 0)
+
+	      if( NOT t_SrcFile MATCHES "moc_" )
+		if( t_SrcFile MATCHES "tests/" )
+		  #message(STATUS "test: ${t_SrcFile}")
+		  LIST(APPEND nice_${the_library}_TESTFILES_SRC ${t_SrcFile})
+		elseif( t_SrcFile MATCHES "progs/" )
+		  #message(STATUS "prog: ${t_SrcFile}")
+		  LIST(APPEND nice_${the_library}_PROGFILES_SRC ${t_SrcFile})
+		elseif( t_SrcFile MATCHES "Mex[.]" )
+		  message(STATUS "mex: ${t_SrcFile}")
+		  LIST(APPEND nice_${the_library}_MEXFILES_SRC ${t_SrcFile})
+		else()
+		  LIST(APPEND nice_${the_library}_SRC ${t_SrcFile})
+		endif()
+	      endif()
+      else()
+	message(STATUS "Not building ${t_SrcFile} because ${t_SrcPath} is excluded (dependencies)")
       endif()
     endforeach()