Skip to content

Commit

Permalink
Port from GTK 2 to GTK 3 (#220)
Browse files Browse the repository at this point in the history
* Port from GTK 2 to GTK 3

* Update the Earthfile

* Add missing line from README

* Update the Earthfile
  • Loading branch information
xyproto authored Mar 27, 2023
1 parent e13b726 commit c08639c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ set(NEKO_VERSION ${NEKO_VERSION_MAJOR}.${NEKO_VERSION_MINOR}.${NEKO_VERSION_PATC
TEST_BIG_ENDIAN(NEKO_BIG_ENDIAN)

option(WITH_REGEXP "Build with Perl-compatible regex support." ON)
option(WITH_UI "Build with GTK-2 UI support." ON)
option(WITH_UI "Build with GTK-3 UI support." ON)
option(WITH_SSL "Build with SSL support." ON)
option(WITH_MYSQL "Build with MySQL support." ON)
option(WITH_SQLITE "Build with Sqlite support." ON)
Expand Down
4 changes: 2 additions & 2 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ devcontainer-base:
cmake \
ninja-build \
pkg-config \
libgtk2.0-dev \
libgtk-3-dev \
$LINK_DYNAMIC_PACKAGES \
#
# Clean up
Expand Down Expand Up @@ -151,7 +151,7 @@ build-env:
git \
ninja-build \
pkg-config \
libgtk2.0-dev \
libgtk-3-dev \
#
# Clean up
&& apt-get autoremove -y \
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Neko needs to link with various third-party libraries, which are summarized as f
| MariaDB / MySQL (Connector/C) | all | libmariadb-client-lgpl-dev-compat (or libmysqlclient-dev) |
| SQLite | all | libsqlite3-dev |
| mbed TLS | all | libmbedtls-dev |
| GTK+2 | Linux | libgtk2.0-dev |
| GTK+3 | Linux | libgtk-3-dev |

On Windows, CMake will automatically download and build the libraries in the build folder during the build process. However, you need to install [Perl](https://www.activestate.com/activeperl) manually because OpenSSL needs it for configuration. On Mac/Linux, you should install the libraries manually to your system before building Neko, or use the `STATIC_DEPS` CMake option, which will be explained in [CMake options](#cmake-options).

Expand Down Expand Up @@ -105,7 +105,7 @@ cmake "-Doption=value" ..
Settings that allow to exclude libraries and their dependencies from the build; available on all platforms. By default all are `ON`:

- `WITH_REGEXP` - Build Perl-compatible regex support
- `WITH_UI` - Build GTK-2 UI support
- `WITH_UI` - Build GTK-3 UI support
- `WITH_SSL` - Build SSL support
- `WITH_MYSQL` - Build MySQL support
- `WITH_SQLITE` - Build Sqlite support
Expand All @@ -119,7 +119,7 @@ It defines the dependencies that should be linked statically. Can be `all`, `non

CMake will automatically download and build the specified dependencies into the build folder. If a library is not present in this list, it should be installed manually, and it will be linked dynamically.

All third-party libraries, except GTK+2 (Linux) and BoehmGC on Windows, can be linked statically. We do not support statically linking GTK+2 due to the difficulty of building it and its own dependencies. Additionally, we do not support statically linking the BoehmGC library on Windows systems. Finally, on MacOS, APRutil cannot be linked statically as it has been merged with APR 2.0, which is used on MacOS builds.
All third-party libraries, except GTK+3 (Linux) and BoehmGC on Windows, can be linked statically. We do not support statically linking GTK+3 due to the difficulty of building it and its own dependencies. Additionally, we do not support statically linking the BoehmGC library on Windows systems. Finally, on MacOS, APRutil cannot be linked statically as it has been merged with APR 2.0, which is used on MacOS builds.

#### `RELOCATABLE`

Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ stages:
- script: |
set -ex
sudo apt-get update -qqy
sudo apt-get install -qqy ninja-build pkg-config libgtk2.0-dev devscripts git-buildpackage ubuntu-dev-tools dh-make dh-apache2
sudo apt-get install -qqy ninja-build pkg-config libgtk-3-dev devscripts git-buildpackage ubuntu-dev-tools dh-make dh-apache2
displayName: Install devscripts
- script: cmake . -DSTATIC_DEPS=all
displayName: CMake
Expand Down
54 changes: 27 additions & 27 deletions cmake/FindGTK2.cmake → cmake/FindGTK3.cmake
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
FILE(TO_CMAKE_PATH "$ENV{GTK2_DIR}" TRY1_DIR)
FILE(TO_CMAKE_PATH "${GTK2_DIR}" TRY2_DIR)
FILE(TO_CMAKE_PATH "$ENV{GTK3_DIR}" TRY1_DIR)
FILE(TO_CMAKE_PATH "${GTK3_DIR}" TRY2_DIR)
FILE(GLOB GTK_DIR ${TRY1_DIR} ${TRY2_DIR})

FIND_PATH(GTK_gtk_2_INCLUDE_DIR gtk/gtk.h
FIND_PATH(GTK_gtk_3_INCLUDE_DIR gtk/gtk.h
ENV INCLUDE DOC "Directory containing gtk/gtk.h include file")

FIND_PATH(GTK_gdk_2_INCLUDE_DIR gdk/gdk.h
FIND_PATH(GTK_gdk_3_INCLUDE_DIR gdk/gdk.h
ENV INCLUDE DOC "Directory containing gdk/gdk.h include file")

FIND_PATH(GTK_gdkconfig_2_INCLUDE_DIR gdkconfig.h
FIND_PATH(GTK_gdkconfig_3_INCLUDE_DIR gdkconfig.h
ENV INCLUDE DOC "Directory containing gdkconfig.h include file")

FIND_LIBRARY(GTK_gdk_pixbuf_2_LIBRARY NAMES gdk_pixbuf-2.0
FIND_LIBRARY(GTK_gdk_pixbuf_3_LIBRARY NAMES gdk_pixbuf-3.0
PATHS ${GTK_DIR}/lib ${GTK_DIR}/bin ${GTK_DIR}/win32/bin ${GTK_DIR}/lib ${GTK_DIR}/win32/lib /usr/local/lib /usr/lib
ENV LIB
DOC "gdk_pixbuf library to link with"
NO_SYSTEM_ENVIRONMENT_PATH)

FIND_LIBRARY(GTK_gdk_2_LIBRARY NAMES gdk-win32-2.0 gdk-x11-2.0
FIND_LIBRARY(GTK_gdk_3_LIBRARY NAMES gdk-win32-3.0 gdk-x11-3.0
PATHS ${GTK_DIR}/lib ${GTK_DIR}/bin ${GTK_DIR}/win32/bin ${GTK_DIR}/lib ${GTK_DIR}/win32/lib /usr/lib /usr/local/lib
ENV LIB
DOC "gdk2 library to link with"
DOC "gdk3 library to link with"
NO_SYSTEM_ENVIRONMENT_PATH)

FIND_LIBRARY(GTK_gtk_2_LIBRARY NAMES gtk-win32-2.0 gtk-x11-2.0
FIND_LIBRARY(GTK_gtk_3_LIBRARY NAMES gtk-win32-3.0 gtk-x11-3.0
PATHS ${GTK_DIR}/lib ${GTK_DIR}/bin ${GTK_DIR}/win32/bin ${GTK_DIR}/lib ${GTK_DIR}/win32/lib /usr/lib /usr/local/lib
ENV LIB
DOC "gtk2 library to link with"
DOC "gtk3 library to link with"
NO_SYSTEM_ENVIRONMENT_PATH)

FIND_LIBRARY(GTK_gdk_pixbuf_2_STATIC_LIBRARY NAMES libgdk_pixbuf-2.0.a
FIND_LIBRARY(GTK_gdk_pixbuf_3_STATIC_LIBRARY NAMES libgdk_pixbuf-3.0.a
PATHS ${GTK_DIR}/lib ${GTK_DIR}/bin ${GTK_DIR}/win32/bin ${GTK_DIR}/lib ${GTK_DIR}/win32/lib /usr/local/lib /usr/lib
ENV LIB
DOC "gdk_pixbuf library to link with"
NO_SYSTEM_ENVIRONMENT_PATH)

FIND_LIBRARY(GTK_gdk_2_STATIC_LIBRARY NAMES libgdk-x11-2.0.a
FIND_LIBRARY(GTK_gdk_3_STATIC_LIBRARY NAMES libgdk-x11-3.0.a
PATHS ${GTK_DIR}/lib ${GTK_DIR}/bin ${GTK_DIR}/win32/bin ${GTK_DIR}/lib ${GTK_DIR}/win32/lib /usr/lib /usr/local/lib
ENV LIB
DOC "gdk2 library to link with"
DOC "gdk3 library to link with"
NO_SYSTEM_ENVIRONMENT_PATH)

FIND_LIBRARY(GTK_gtk_2_STATIC_LIBRARY NAMES libgtk-x11-2.0.a
FIND_LIBRARY(GTK_gtk_3_STATIC_LIBRARY NAMES libgtk-x11-3.0.a
PATHS ${GTK_DIR}/lib ${GTK_DIR}/bin ${GTK_DIR}/win32/bin ${GTK_DIR}/lib ${GTK_DIR}/win32/lib /usr/lib /usr/local/lib
ENV LIB
DOC "gtk2 library to link with"
DOC "gtk3 library to link with"
NO_SYSTEM_ENVIRONMENT_PATH)


IF (GTK_gtk_2_INCLUDE_DIR AND GTK_gdk_2_INCLUDE_DIR AND GTK_gdkconfig_2_INCLUDE_DIR)
SET(GTK2_INCLUDE_DIR ${GTK_gtk_2_INCLUDE_DIR} ${GTK_gdk_2_INCLUDE_DIR} ${GTK_gdkconfig_2_INCLUDE_DIR})
list(REMOVE_DUPLICATES GTK2_INCLUDE_DIR)
SET(GTK2_LIBRARIES ${GTK_gdk_pixbuf_2_LIBRARY} ${GTK_gdk_2_LIBRARY} ${GTK_gtk_2_LIBRARY})
list(REMOVE_DUPLICATES GTK2_LIBRARIES)
SET(GTK2_STATIC_LIBRARIES ${GTK_gdk_pixbuf_2_STATIC_LIBRARY} ${GTK_gdk_2_STATIC_LIBRARY} ${GTK_gtk_2_STATIC_LIBRARY})
list(REMOVE_DUPLICATES GTK2_STATIC_LIBRARIES)
SET(GTK2_FOUND TRUE)
IF (GTK_gtk_3_INCLUDE_DIR AND GTK_gdk_3_INCLUDE_DIR AND GTK_gdkconfig_3_INCLUDE_DIR)
SET(GTK3_INCLUDE_DIR ${GTK_gtk_3_INCLUDE_DIR} ${GTK_gdk_3_INCLUDE_DIR} ${GTK_gdkconfig_3_INCLUDE_DIR})
list(REMOVE_DUPLICATES GTK3_INCLUDE_DIR)
SET(GTK3_LIBRARIES ${GTK_gdk_pixbuf_3_LIBRARY} ${GTK_gdk_3_LIBRARY} ${GTK_gtk_3_LIBRARY})
list(REMOVE_DUPLICATES GTK3_LIBRARIES)
SET(GTK3_STATIC_LIBRARIES ${GTK_gdk_pixbuf_3_STATIC_LIBRARY} ${GTK_gdk_3_STATIC_LIBRARY} ${GTK_gtk_3_STATIC_LIBRARY})
list(REMOVE_DUPLICATES GTK3_STATIC_LIBRARIES)
SET(GTK3_FOUND TRUE)


message(STATUS "GTK2_INCLUDE_DIR: ${GTK2_INCLUDE_DIR}")
message(STATUS "GTK2_LIBRARIES: ${GTK2_LIBRARIES}")
message(STATUS "GTK2_STATIC_LIBRARIES: ${GTK2_STATIC_LIBRARIES}")
ENDIF ()
message(STATUS "GTK3_INCLUDE_DIR: ${GTK3_INCLUDE_DIR}")
message(STATUS "GTK3_LIBRARIES: ${GTK3_LIBRARIES}")
message(STATUS "GTK3_STATIC_LIBRARIES: ${GTK3_STATIC_LIBRARIES}")
ENDIF ()
8 changes: 4 additions & 4 deletions libs/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ if(APPLE)
find_library(CARBON_LIBRARY Carbon REQUIRED)
target_link_libraries(ui.ndll ${CARBON_LIBRARY})
elseif(UNIX)
pkg_check_modules(GTK2 REQUIRED gtk+-2.0)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
target_include_directories(ui.ndll PRIVATE
${GTK2_INCLUDEDIR}
${GTK2_INCLUDE_DIRS}
${GTK3_INCLUDEDIR}
${GTK3_INCLUDE_DIRS}
)
target_link_libraries(ui.ndll ${GTK2_LIBRARIES})
target_link_libraries(ui.ndll ${GTK3_LIBRARIES})
endif()

set_target_properties(ui.ndll
Expand Down
4 changes: 2 additions & 2 deletions libs/ui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern void QuitApplicationEventLoop(void);
<h1>UI</h1>
<p>
Core native User Interface support. This API uses native WIN32 API on Windows,
Carbon API on OSX, and GTK2 on Linux.
Carbon API on OSX, and GTK3 on Linux.
</p>
</doc>
**/
Expand Down Expand Up @@ -250,7 +250,7 @@ static value ui_sync( value f ) {
// however the GTK lock mechanism is a LOT slower than
// using a pthread_mutex
pthread_mutex_lock(&data.lock);
gtk_timeout_add( 0, onSyncCall, (gpointer)r );
gdk_threads_add_timeout( 0, onSyncCall, (gpointer)r );
pthread_mutex_unlock(&data.lock);
# endif
return val_null;
Expand Down

0 comments on commit c08639c

Please sign in to comment.