]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
gtkglext: build and bundle built-in gtkglext
authorThomas Debesse <dev@illwieckz.net>
Thu, 17 Dec 2020 20:54:29 +0000 (21:54 +0100)
committerThomas Debesse <dev@illwieckz.net>
Tue, 22 Dec 2020 22:53:06 +0000 (23:53 +0100)
There is a chicken-and-egg problem, so the build must be done in two steps,

First build built-in libraries:

cmake -G "Unix Makefiles" -S. -Bbuild -DBUILTIN_GTKGLEXT=ON -DBUNDLE_LIBRARIES=ON
cmake --build build --parallel $(nproc) -- builtins

Then detect the built-in libraries and build netradiant and install the bundle as usual:

cmake -S. -Bbuild
cmake --build build --parallel $(nproc) install

There is no need to set cmake options on second step but cmake still has to be called again to detect the new files.

CMakeLists.txt
bundle/CMakeLists.txt
cmake/FindGtkGLExt.cmake
library-bundler

index d861842cc3446049a14982c1fc43e8ac9c30cecc..29743727a9579ac8539e8cd20a216088ed4eedb1 100644 (file)
@@ -1,8 +1,46 @@
 cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
 
-list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
 project(NetRadiant C CXX)
 
+#-----------------------------------------------------------------------
+# Builtins: configuration
+#-----------------------------------------------------------------------
+
+set(BUILTINS_INSTALL_DIR "${CMAKE_BINARY_DIR}/builtins")
+set(BUILTINS_INCLUDE_DIR "${BUILTINS_INSTALL_DIR}/include")
+set(BUILTINS_LIB_DIR "${BUILTINS_INSTALL_DIR}/lib")
+set(BUILTINS_PKGCONFIG_DIR "${BUILTINS_INSTALL_DIR}/lib/pkgconfig")
+
+option(BUILTIN_GTKGLEXT "Builtin GtkGLExt" OFF)
+
+set(BUILTIN_GTKGLEXT_BUILT OFF CACHE INTERNAL "...")
+if (EXISTS "${BUILTINS_INSTALL_DIR}/lib/pkgconfig/gtkglext-1.0.pc")
+    set(BUILTIN_GTKGLEXT_BUILT ON)
+endif ()
+
+if (EXISTS "${BUILTINS_INCLUDE_DIR}")
+    include_directories("${BUILTINS_INCLUDE_DIR}")
+endif ()
+
+if (EXISTS "${BUILTINS_LIB_DIR}")
+    set(ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}:${BUILTINS_LIB_DIR}")
+    link_directories("${BUILTINS_LIB_DIR}")
+endif ()
+
+if (EXISTS "${BUILTINS_PKGCONFIG_DIR}")
+    set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${BUILTINS_PKGCONFIG_DIR}")
+endif ()
+
+#-----------------------------------------------------------------------
+# CMake modules
+#-----------------------------------------------------------------------
+
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
+
+#-----------------------------------------------------------------------
+# Submodules
+#-----------------------------------------------------------------------
+
 if (EXISTS "${PROJECT_SOURCE_DIR}/libs/crunch/inc/crn_decomp.h")
     set(DEFAULT_BUILD_CRUNCH ON CACHE INTERNAL "...")
 else ()
@@ -15,6 +53,10 @@ else ()
     set(DEFAULT_BUILD_DAEMONMAP OFF CACHE INTERNAL "...")
 endif ()
 
+#-----------------------------------------------------------------------
+# Build options
+#-----------------------------------------------------------------------
+
 option(BUILD_RADIANT "Build the GUI" ON)
 option(BUILD_TOOLS "Build the tools" ON)
 option(BUILD_CRUNCH "Build Crunch image support" ${DEFAULT_BUILD_CRUNCH})
@@ -162,27 +204,6 @@ if (BUILD_RADIANT)
     endif ()
 endif ()
 
-option(BUILTIN_GTKGLEXT "Builtin GtkGLExt" OFF)
-if (BUILTIN_GTKGLEXT)
-    include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
-
-    execute_process(COMMAND pkg-config --libs gdk-2.0 gtk+-2.0 glib-2.0 gl
-        OUTPUT_VARIABLE GTKGLEXT_LDFLAGS
-        OUTPUT_STRIP_TRAILING_WHITESPACE
-    )
-    set(GTKGLEXT_LDFLAGS "-lm ${GTKGLEXT_LDFLAGS}")
-
-    ExternalProject_Add(gtkglext
-        GIT_REPOSITORY https://gitlab.gnome.org/illwieckz/gtkglext.git
-        GIT_TAG fixes
-        BUILD_IN_SOURCE ON
-        CONFIGURE_COMMAND NOCONFIGURE=1 ./autogen.sh
-        CONFIGURE_COMMAND && ./configure --prefix "${CMAKE_BINARY_DIR}/external"
-        BUILD_COMMAND $(MAKE) LDFLAGS=${GTKGLEXT_LDFLAGS}
-        INSTALL_COMMAND $(MAKE) install
-    )
-endif ()
-
 #-----------------------------------------------------------------------
 # Defs
 #-----------------------------------------------------------------------
@@ -278,6 +299,50 @@ if (BUILD_BINARIES)
     endmacro ()
 endif ()
 
+#-----------------------------------------------------------------------
+# Builtins: targets
+#-----------------------------------------------------------------------
+
+add_custom_target(builtins)
+
+if (BUILTIN_GTKGLEXT)
+    include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
+
+    execute_process(COMMAND pkg-config --libs gdk-2.0 gtk+-2.0 glib-2.0 gl
+        OUTPUT_VARIABLE GTKGLEXT_DEPS_LDFLAGS
+        OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+    set(GTKGLEXT_DEPS_LDFLAGS "-lm ${GTKGLEXT_DEPS_LDFLAGS}")
+
+    ExternalProject_Add(gtkglext
+        GIT_REPOSITORY https://gitlab.gnome.org/illwieckz/gtkglext.git
+        GIT_TAG fixes
+        BUILD_IN_SOURCE ON
+        CONFIGURE_COMMAND NOCONFIGURE=1 ./autogen.sh
+        CONFIGURE_COMMAND && ./configure --prefix "${BUILTINS_INSTALL_DIR}" --disable-gtk-doc --disable-gtk-doc-html --disable-gtk-doc-pdf
+        BUILD_COMMAND $(MAKE) LDFLAGS=${GTKGLEXT_DEPS_LDFLAGS}
+        INSTALL_COMMAND $(MAKE) install
+    )
+
+#    set(ENV{PKG_CONFIG_PATH} $ENV{PKG_CONFIG_PATH}:${BUILTINS_INSTALL_DIR}lib/pkgconfig/)
+#    execute_process(COMMAND pkg-config --libs gtkglext-1.0
+#        OUTPUT_VARIABLE GTKGLEXT_LDFLAGS
+#        OUTPUT_STRIP_TRAILING_WHITESPACE
+#    )
+#    set(CMAKE_EXE_LINKER_FLAGS ${GTKGLEXT_LDFLAGS})
+
+#    list(APPEND CMAKE_PREFIX_PATH "${BUILTINS_INSTALL_DIR}")
+    include_directories("${BUILTINS_INSTALL_DIR}/lib/gtkglext-1.0/include")
+    include_directories("${BUILTINS_INSTALL_DIR}/include/gtkglext-1.0")
+
+    add_dependencies(builtins gtkglext)
+    set_target_properties(gtkglext PROPERTIES EXCLUDE_FROM_ALL ON)
+endif ()
+
+if (BUNDLE_LIBRARIES AND EXISTS ${BUILTINS_LIB_DIR})
+    set(CMAKE_SKIP_BUILD_RPATH ON)
+endif()
+
 #-----------------------------------------------------------------------
 # Libraries
 #-----------------------------------------------------------------------
index eb09c24daa56053b2f1713e0bab27b8b87a1e00b..1ab7609c6c9151249b4ce8f1b17b43c972c483b1 100644 (file)
@@ -8,7 +8,9 @@ else ()
 endif ()
 
 add_custom_target(bundle ALL
-    COMMAND "${PROJECT_SOURCE_DIR}/library-bundler"
+    COMMAND
+    export LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} &&
+    "${PROJECT_SOURCE_DIR}/library-bundler"
     "${BUNDLE_OS_NAME}" "${PROJECT_BINARY_DIR}"
     VERBATIM
     COMMENT "Bundling libraries"
index 8fa486e570fdb09b933a5d842d1d2f61a17562e8..fa8ddda9af38d324e0789a37bc6faf7d0c2c8441 100644 (file)
@@ -1,4 +1,5 @@
 find_package(PkgConfig)
+if (NOT BUILTIN_GTKGLEXT OR BUILTIN_GTKGLEXT_BUILT)
 if (PKG_CONFIG_FOUND)
     if (GtkGLExt_FIND_REQUIRED)
         set(_pkgconfig_REQUIRED REQUIRED)
@@ -25,3 +26,4 @@ else ()
     endif ()
 endif ()
 mark_as_advanced(GtkGLExt_INCLUDE_DIRS GtkGLExt_LIBRARIES)
+endif()
index db2f1ca1c857d804a895af252dfeb89dac63bff9..1a3389c9dc0aab23f4f80b5bcc0b7d74f8ae735b 100755 (executable)
@@ -44,6 +44,7 @@ Common::stripLdd () {
 Multi::excludeLdd () {
        case "${system_name}" in
                'linux')
+                       # - always bundle built-in libraries
                        # - always rely on up-to-date x11 and gl libraries, bundling them will break on future distros
                        # - gtk is not easily bundlable on linux because it looks for harcoded system path to optional
                        #   shared libraries like image codecs, theme engines, sound notification system, etc.
@@ -52,8 +53,24 @@ Multi::excludeLdd () {
                        #   which is likely to pull gtk itself, x11 and gl dependencies
                        # - old fontconfig does not work correctly if newer fontconfig configuration is installed
                        # - if gtk and fontconfig is installed, pango and freetype are
-                       egrep -v '/libc\.|/libstdc\+\+\.|/libdl\.|/libm\.|/libX|/libxcb|/libGL|/libICE\.|/libSM\.|/libpthread\.' \
-                       | egrep -v '/libatk|/libgdk|/libgtk|/libgio|/libglib|/libgmodule|/libgobject|/libcairo|/libpango|/libfontconfig|/libfreetype'
+                       local ldd_line
+                       while read ldd_line
+                       do
+                               if echo "${ldd_line}" | egrep '/builtins/'
+                               then
+                                       echo "${ldd_line}"
+                               elif echo "${ldd_line}" \
+                                       | egrep -q '/libc\.|/libstdc\+\+\.|/libdl\.|/libm\.|/libX|/libxcb|/libGL|/libICE\.|/libSM\.|/libpthread\.'
+                               then
+                                       Common::noOp
+                               elif echo "${ldd_line}" \
+                                       | egrep -q '/libatk|/libgdk|/libgtk|/libgio|/libglib|/libgmodule|/libgobject|/libcairo|/libpango|/libfontconfig|/libfreetype'
+                               then
+                                       Common::noOp
+                               else
+                                       echo "${ldd_line}"
+                               fi
+                       done
                        ;;
                'windows')
                        egrep -i '\.dll => [A-Z]:\\msys64\\'