view maintainers_add_the_linux_kbuilddir_finder.patch @ 49:0c55f24c6b3d

Add a series of patch related to the build systme
author Louis Opter <louis@lse.epitech.net>
date Sun, 15 Jan 2012 21:36:15 +0100
parents
children
line wrap: on
line source

# HG changeset patch
# Parent 6682d6e4330ef0429c41af6dcbe0362ff15d9841
maintainers: add a CMake finder for the Linux build tree and only build the e1000 sample if it is found

diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,12 +29,17 @@
 
 FIND_PACKAGE(LATEX)
 FIND_PACKAGE(CodeWorker REQUIRED)
+FIND_PACKAGE(LinuxKBuildDir)
 
 INCLUDE(AddFileDependencies)
 INCLUDE(FileCopy)
 INCLUDE(RathaxesCopyLatexClasses)
 INCLUDE(UseRathaxes)
 
+IF (CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT LINUX_KBUILD_DIR)
+    MESSAGE(STATUS "No valid Linux build tree found, kernel modules will not be built")
+ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT LINUX_KBUILD_DIR)
+
 # Global definitions ###########################################################
 
 ENABLE_TESTING()
diff --git a/maintainers/CMakeScripts/FindLinuxKBuildDir.cmake b/maintainers/CMakeScripts/FindLinuxKBuildDir.cmake
new file mode 100644
--- /dev/null
+++ b/maintainers/CMakeScripts/FindLinuxKBuildDir.cmake
@@ -0,0 +1,41 @@
+# Check if the kernel build directory exists
+#
+# This finder will seek for the usual /lib/modules/`uname -r`/build/
+# directory. Obviously, this is Linux specific.
+#
+# You can specify an alternate build directory by using the environment
+# variable LINUX_KBUILD_DIR.
+#
+# This is necessary to build Linux kernel modules!
+#
+# Usage: FIND_PACKAGE(LinuxKBuildDir [REQUIRED])
+#
+# This will set the variable LINUX_KBUILD_DIR with the path to the KBuild
+# directory, if it is found.
+
+IF (NOT LINUX_KBUILD_DIR)
+    IF ($ENV{LINUX_KBUILD_DIR})
+        SET(KDIR $ENV{LINUX_KBUILD_DIR})
+    ELSE ($ENV{LINUX_KBUILD_DIR})
+        SET(KDIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build/")
+    ENDIF ($ENV{LINUX_KBUILD_DIR})
+
+    IF (IS_DIRECTORY "${KDIR}")
+        FIND_FILE(LINUX_KBUILD_DIR_MAKEFILE "Makefile"
+                  PATHS "${KDIR}"
+                  # Restrict the search to this directory only:
+                  NO_DEFAULT_PATH
+                  NO_CMAKE_ENVIRONMENT_PATH
+                  NO_CMAKE_PATH
+                  NO_SYSTEM_ENVIRONMENT_PATH
+                  NO_CMAKE_SYSTEM_PATH)
+        # Check if it looks legit:
+        IF (LINUX_KBUILD_DIR_MAKEFILE)
+            SET(LINUX_KBUILD_DIR "${KDIR}" CACHE PATH "Path to the Linux KBuild directory (usually /lib/modules/`uname -r`/build/)")
+        ENDIF (LINUX_KBUILD_DIR_MAKEFILE)
+    ENDIF (IS_DIRECTORY "${KDIR}")
+ENDIF (NOT LINUX_KBUILD_DIR)
+
+INCLUDE(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LinuxKBuildDir DEFAULT_MSG LINUX_KBUILD_DIR)
diff --git a/rathaxes/samples/e1000/CMakeLists.txt b/rathaxes/samples/e1000/CMakeLists.txt
--- a/rathaxes/samples/e1000/CMakeLists.txt
+++ b/rathaxes/samples/e1000/CMakeLists.txt
@@ -2,10 +2,6 @@
                      RTI log.rti lkm.rti pci.rti socket.rti ethernet.rti e1000.rti
                      BLT log.blt lkm.blt pci.blt socket.blt ethernet.blt e1000.blt)
 
-# We can't name lkm since it's already used as the target name to generate the
-# source (with ADD_RATHAXES_SOURCES).
-
-# does not work atm
-IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
-	ADD_RATHAXES_LKM(e1000 e1000_src)
-ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+IF (LINUX_KBUILD_DIR)
+    ADD_RATHAXES_LKM(e1000 e1000_src)
+ENDIF (LINUX_KBUILD_DIR)