Skip to content

Commit

Permalink
Port from GTK 2 to GTK 3
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Dec 22, 2020
1 parent 1df580c commit 3811c09
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ set(NEKO_VERSION ${NEKO_VERSION_MAJOR}.${NEKO_VERSION_MINOR}.${NEKO_VERSION_PATC
TEST_BIG_ENDIAN(NEKO_BIG_ENDIAN)

option(WITH_REGEXP "Build Perl-compatible regex support." ON)
option(WITH_UI "Build GTK-2 UI support." ON)
option(WITH_UI "Build GTK-3 UI support." ON)
option(WITH_SSL "Build SSL support." ON)
option(WITH_MYSQL "Build MySQL support." ON)
option(WITH_SQLITE "Build Sqlite support." ON)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Users of other Linux/FreeBSD distributions should build Neko from source. See be

Neko can be built using CMake (version 3.x is recommended) and one of the C compilers listed as follows:

* Windows: Visual Studio 2010 / 2013 / 2015 / 2017
* Windows: Visual Studio 2010 / 2013 / 2015 / 2017
* Mac: XCode (with its "Command line tools")
* Linux: gcc (can be obtained by installing the "build-essential" Debian/Ubuntu package)

Expand All @@ -41,7 +41,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](http://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 @@ -73,7 +73,7 @@ You may use the CMake GUI and Visual Studio to build it instead.
mkdir build
cd build

# run cmake specifying the visual studio version you need
# run cmake specifying the visual studio version you need
# Visual Studio 12 2013, Visual Studio 14 2015, Visual Studio 15 2017
# you can additionally specify platform via -A switch (x86, x64)
cmake -G "Visual Studio 12 2013" ..
Expand All @@ -99,7 +99,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 @@ -113,7 +113,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), can be linked statically. We do not support statically linking GTK+2 due to the difficulty of building it and its own dependencies.
All third-party libraries, except GTK+3 (Linux), can be linked statically. We do not support statically linking GTK+3 due to the difficulty of building it and its own dependencies.

#### `RELOCATABLE`

Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,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 ()
4 changes: 2 additions & 2 deletions extra/azure-pipelines/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
vmImage: ${{ parameters.vmImage }}
variables:
${{ if eq(parameters.staticDeps, 'true') }}:
APT_PACKAGES: cmake ninja-build pkg-config libgtk2.0-dev
APT_PACKAGES: cmake ninja-build pkg-config libgtk-3-dev
STATIC_DEPS: all
${{ if eq(parameters.staticDeps, 'false') }}:
APT_PACKAGES: cmake ninja-build pkg-config libgtk2.0-dev libgc-dev libpcre3-dev zlib1g-dev apache2-dev libmysqlclient-dev libsqlite3-dev
APT_PACKAGES: cmake ninja-build pkg-config libgtk-3-dev libgc-dev libpcre3-dev zlib1g-dev apache2-dev libmysqlclient-dev libsqlite3-dev
STATIC_DEPS: none
steps:
- script: |
Expand Down
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 @@ -48,7 +48,7 @@ enum { pFunc = 'func' };
<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 @@ -248,7 +248,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 3811c09

Please sign in to comment.