CMakeLists.txt : I do not get any executable output

61 views Asked by At

I want to convert this command line compilation and building:

g++ tutorial01.cpp -o tutorial01 -std=c++17 -I /usr/local/include/webkitgtk-4.1/webkit2 $(pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0)

into a CMake building:

With this CMakeLists.txt file : cmake_minimum_required(VERSION 3.24) project(tutorial01 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)

set(export WEBKIT_DISABLE_COMPOSITING_MODE=1)

find_package(PkgConfig)
pkg_check_modules(gtk+-3.0 webkit2gtk-4.0)

add_executable(tutorial01 tutorial01.cpp)

target_compile_options(tutorial01 PUBLIC ${webkit2gtk-4.1_CFLAGS_OTHER} ${gtk+-3.0_CFLAGS_OTHER})
target_include_directories(tutorial01 PUBLIC ${webkit2gtk-4.1_INCLUDE_DIRS})



target_link_libraries(tutorial01 PUBLIC
    gtk+-3.0_LIBRARIES
    webkit2gtk-4.1_LIBRARIES
)

There are no errors, but I do not get the executable file tutorial01 :

raphy@raohy:~/tutorial_webkitgtk$ cmake -B build
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") 
-- Checking for module 'webkit2gtk-4.0'
--   Found webkit2gtk-4.0, version 2.42.3
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/raphy/tutorial_webkitgtk/build


raphy@raohy:~/tutorial_webkitgtk/build$ ls -lah
total 48K
drwxrwxr-x 3 raphy raphy 4,0K dic 20 16:00 .
drwxrwxr-x 3 raphy raphy 4,0K dic 20 16:01 ..
-rw-rw-r-- 1 raphy raphy  24K dic 20 16:00 CMakeCache.txt
drwxrwxr-x 6 raphy raphy 4,0K dic 20 16:00 CMakeFiles
-rw-rw-r-- 1 raphy raphy 1,6K dic 20 16:00 cmake_install.cmake
-rw-rw-r-- 1 raphy raphy 5,3K dic 20 16:00 Makefile

raphy@raohy:~/tutorial_webkitgtk$ ls -lah
total 20K
drwxrwxr-x  3 raphy raphy 4,0K dic 20 16:01 .
drwxr-x--- 78 raphy raphy 4,0K dic 20 15:23 ..
drwxrwxr-x  3 raphy raphy 4,0K dic 20 16:00 build
-rw-rw-r--  1 raphy raphy  609 dic 20 16:00 CMakeLists.txt
-rw-rw-r--  1 raphy raphy 1,7K dic 20 13:41 tutorial01.cpp

Update 1:

With:

cmake_minimum_required(VERSION 3.24)
project(tutorial01 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)

set(export WEBKIT_DISABLE_COMPOSITING_MODE=1)

find_package(PkgConfig)
pkg_check_modules(gtk gtk+-3.0)
pkg_check_modules(webkit2gtk webkit2gtk-4.0)

message( STATUS IncludeDir: ${webkit2gtk-4.1_INCLUDE_DIRS})

add_executable(tutorial01 tutorial01.cpp)

target_compile_options(tutorial01 PUBLIC ${webkit2gtk-4.1_CFLAGS_OTHER} ${gtk+-3.0_CFLAGS_OTHER})
target_include_directories(tutorial01 PUBLIC ${webkit2gtk-4.1_INCLUDE_DIRS} ${gtk+-3.0_INCLUDE_DIRS})

target_link_libraries(tutorial01 PUBLIC
    gtk+-3.0_LIBRARIES
    webkit2gtk-4.1_LIBRARIES
)

I get "fatal error: gtk/gtk.h: No such file or directory" error: in the building phase:

raphy@raohy:~/tutorial_webkitgtk$ cmake -B build
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") 
-- Checking for module 'gtk+-3.0'
--   Found gtk+-3.0, version 3.24.33
-- Checking for module 'webkit2gtk-4.0'
--   Found webkit2gtk-4.0, version 2.42.3
-- IncludeDir:
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/raphy/tutorial_webkitgtk/build
raphy@raohy:~/tutorial_webkitgtk$ 
raphy@raohy:~/tutorial_webkitgtk$ cmake --build build
[ 50%] Building CXX object CMakeFiles/tutorial01.dir/tutorial01.cpp.o
/home/raphy/tutorial_webkitgtk/tutorial01.cpp:3:10: fatal error: gtk/gtk.h: No such file or directory
    3 | #include <gtk/gtk.h>
      |          ^~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/tutorial01.dir/build.make:76: CMakeFiles/tutorial01.dir/tutorial01.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/tutorial01.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

Update 2)

Thanks to all the people who commented, I reached the solution.

With this CMakeLists.txt :

cmake_minimum_required(VERSION 3.24)
project(tutorial01 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)

set(export WEBKIT_DISABLE_COMPOSITING_MODE=1)

find_package(PkgConfig REQUIRED)
pkg_check_modules(gtk REQUIRED IMPORTED_TARGET gtk+-3.0)
pkg_check_modules(webkit2gtk REQUIRED IMPORTED_TARGET webkit2gtk-4.0)

add_executable(tutorial01 tutorial01.cpp)

target_compile_options(tutorial01 PUBLIC ${webkit2gtk_CFLAGS_OTHER} ${gtk_CFLAGS_OTHER})
target_include_directories(tutorial01 PUBLIC ${webkit2gtk_INCLUDE_DIRS} ${gtk_INCLUDE_DIRS})


target_link_libraries(tutorial01 PUBLIC
    PkgConfig::gtk
    PkgConfig::webkit2gtk
)

I get the correct compilation and building:

raphy@raohy:~/tutorial_webkitgtk$ cmake -B build
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") 
-- Checking for module 'gtk+-3.0'
--   Found gtk+-3.0, version 3.24.33
-- Checking for module 'webkit2gtk-4.0'
--   Found webkit2gtk-4.0, version 2.42.3
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/raphy/tutorial_webkitgtk/build
 
raphy@raohy:~/tutorial_webkitgtk$ cmake --build build
[ 50%] Building CXX object CMakeFiles/tutorial01.dir/tutorial01.cpp.o
[100%] Linking CXX executable tutorial01
[100%] Built target tutorial01
raphy@raohy:~/tutorial_webkitgtk$ ./build/tutorial01
0

There are 0 answers