From: Thomas Debesse Date: Thu, 17 Dec 2020 20:54:29 +0000 (+0100) Subject: gtkglext: build and bundle built-in gtkglext X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=51f57c17f538d299fb6bdba3b1b5d71e630664b0;p=xonotic%2Fnetradiant.git gtkglext: build and bundle built-in gtkglext 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. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d861842c..29743727 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 #----------------------------------------------------------------------- diff --git a/bundle/CMakeLists.txt b/bundle/CMakeLists.txt index eb09c24d..1ab7609c 100644 --- a/bundle/CMakeLists.txt +++ b/bundle/CMakeLists.txt @@ -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" diff --git a/cmake/FindGtkGLExt.cmake b/cmake/FindGtkGLExt.cmake index 8fa486e5..fa8ddda9 100644 --- a/cmake/FindGtkGLExt.cmake +++ b/cmake/FindGtkGLExt.cmake @@ -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() diff --git a/library-bundler b/library-bundler index db2f1ca1..1a3389c9 100755 --- a/library-bundler +++ b/library-bundler @@ -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\\'