Эх сурвалжийг харах

Moved UPDATE_NICE_DEPENDENCIES macro around, corrected linkage behavior between modules

Clemens-Alexander Brust 11 жил өмнө
parent
commit
d64b68e7eb

+ 2 - 58
CMakeLists.txt

@@ -326,64 +326,8 @@ endforeach()
 
 
 message(STATUS "External dependencies found: ${external_deps}")
 message(STATUS "External dependencies found: ${external_deps}")
 
 
-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(${_extdepCount} 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.")
+## Update deps
+UPDATE_NICE_DEPENDENCIES()
 
 
 foreach(_curSublib ${__listSubLibs})
 foreach(_curSublib ${__listSubLibs})
   if(BUILD_LIB_${_curSublib})
   if(BUILD_LIB_${_curSublib})

+ 89 - 0
cmake/NiceModules.cmake

@@ -20,6 +20,8 @@ MACRO(SUBDIRLIST result curdir)
   SET(${result} ${dirlist})
   SET(${result} ${dirlist})
 ENDMACRO()
 ENDMACRO()
 
 
+# get a list of all sub directories in curdir (recursive)
+# this function lists only the directories that contain relevant files
 MACRO(SUBDIRREC result curdir)
 MACRO(SUBDIRREC result curdir)
 	FILE(GLOB_RECURSE children RELATIVE ${curdir} ${curdir}/*.c ${curdir}/*.cpp ${curdir}/*.h ${curdir}/*.tcc ${curdir}/Makefile)
 	FILE(GLOB_RECURSE children RELATIVE ${curdir} ${curdir}/*.c ${curdir}/*.cpp ${curdir}/*.h ${curdir}/*.tcc ${curdir}/Makefile)
 	SET(dirlist "")
 	SET(dirlist "")
@@ -35,6 +37,75 @@ MACRO(SUBDIRREC result curdir)
 	SET(${result} ${dirlist})
 	SET(${result} ${dirlist})
 ENDMACRO()
 ENDMACRO()
 
 
+
+# update internal and external dependencies
+#
+# ${internal_deps} contains all the folders that are
+# "allowed". files in folders that are not part of this list will
+# _NOT_ be built.
+# the relevant libdepend.inc files are parsed until no more changes
+# are made
+macro(UPDATE_NICE_DEPENDENCIES)
+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(${_extdepCount} 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.")
+
+endmacro()
+
 # get absolute path with symlinks resolved
 # get absolute path with symlinks resolved
 macro(nice_get_real_path VAR PATHSTR)
 macro(nice_get_real_path VAR PATHSTR)
   if(CMAKE_VERSION VERSION_LESS 2.8)
   if(CMAKE_VERSION VERSION_LESS 2.8)
@@ -150,6 +221,24 @@ endmacro()
 
 
 macro(nice_build_library)
 macro(nice_build_library)
   ADD_LIBRARY("nice_${the_library}" ${nice_${the_library}_HDR} ${nice_${the_library}_SRC})
   ADD_LIBRARY("nice_${the_library}" ${nice_${the_library}_HDR} ${nice_${the_library}_SRC})
+  LIST(LENGTH nice_${the_library}_LINKING_DEPENDENCIES dependency_count)
+  SET(tmp_dependencies "")
+  IF(dependency_count GREATER 0)
+	FOREACH(tmp_dependency ${nice_${the_library}_LINKING_DEPENDENCIES})
+		IF("${tmp_dependency}" MATCHES "^nice_")
+			STRING(REGEX REPLACE "^nice_(.*)" "\\1" tmp_dependency_nice ${tmp_dependency})
+			LIST(FIND internal_deps ${tmp_dependency_nice} dep_found)
+			IF(NOT ${dep_found} LESS 0)
+				SET(tmp_dependencies ${tmp_dependencies} ${tmp_dependency})
+			ELSE()
+				MESSAGE(STATUS "${the_library} wants to link to NICE module: ${tmp_dependency_nice}, but it is not available.")
+			ENDIF()
+		ELSE()
+			SET(tmp_dependencies ${tmp_dependencies} ${tmp_dependency})
+		ENDIF()
+	ENDFOREACH()
+  ENDIF()
+  SET(nice_${the_library}_LINKING_DEPENDENCIES ${tmp_dependencies})
   TARGET_LINK_LIBRARIES("nice_${the_library}" ${nice_${the_library}_LINKING_DEPENDENCIES})
   TARGET_LINK_LIBRARIES("nice_${the_library}" ${nice_${the_library}_LINKING_DEPENDENCIES})
   #TARGET_LINK_LIBRARIES("nice_${the_library}" ${nice_${the_library}_LINKING_DEPENDENCIES} ${Boost_LIBRARIES} ${OPENGL_LIBRARY} ${GLUT_LIBRARY} ${QT_LIBRARIES})
   #TARGET_LINK_LIBRARIES("nice_${the_library}" ${nice_${the_library}_LINKING_DEPENDENCIES} ${Boost_LIBRARIES} ${OPENGL_LIBRARY} ${GLUT_LIBRARY} ${QT_LIBRARIES})
   SET_PROPERTY(TARGET "nice_${the_library}" PROPERTY FOLDER "library")
   SET_PROPERTY(TARGET "nice_${the_library}" PROPERTY FOLDER "library")