Advertisement
Mark2020H

#CMakeLists.txt file for compiling and running gtk3 applications on Debian 12 (Linux distro )

Jul 12th, 2023
1,990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 2.34 KB | None | 0 0
  1. #CMakeLists.txt file for compiling and running gtk3  applications on  Debian 12 (Linux distro )
  2.  
  3. cmake_minimum_required(VERSION 3.10)
  4. project(gtk3_examples C)
  5.  
  6. # Custom function to introduce a time delay
  7. function(delay seconds)
  8.     execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep ${seconds})
  9. endfunction()
  10.  
  11. message(STATUS "Hello all this is GTK3 CMakeLists.txt file Written  By Mark David Harrington!")
  12. delay(2)  # Delay for 2 seconds
  13. message(STATUS "Im about to show you the power of CMake  right the way from compilation to exe to lauch ")
  14. delay(2)  # Delay for 2 second
  15.  
  16. message(STATUS " Watch this  do all of this for you !! Worth learning this and spending time doing ")
  17.  
  18. delay(3)
  19.  
  20.  
  21. # Set the flags passed to the compiler
  22. set(CMAKE_C_FLAGS "-Wall -Wextra -Werror -rdynamic ${CMAKE_C_FLAGS}")
  23.  
  24. # Set the standard required by the compiler
  25. set(CMAKE_C_STANDARD 11)
  26. set(CMAKE_C_STANDARD_REQUIRED ON)
  27.  
  28. # Set the output directory for the build files
  29. set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
  30. # Set the output directory for the debug exe files
  31. set(CMAKE_DEBUG_DIR ${CMAKE_SOURCE_DIR}/debug)
  32. # Set the executable path to the debug subdirectory
  33. set(EXECUTABLE_OUTPUT_PATH ${CMAKE_DEBUG_DIR})
  34.  
  35. # Find the GTK3 package
  36. find_package(PkgConfig REQUIRED)
  37. # Check if packages exist
  38. pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
  39.  
  40. # Set the include directories
  41. include_directories(${GTK3_INCLUDE_DIRS})
  42.  
  43. # Set the source and include files directories
  44. set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
  45. set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
  46.  
  47. # Get all C source files in the subdirectory
  48. file(GLOB SOURCES ${SOURCE_DIR}/*.c)
  49.  
  50. # Get all header files in the include directory
  51. file(GLOB HEADERS ${INCLUDE_DIR}/*.h)
  52.  
  53. # Add the source files and headers to the project
  54. add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
  55.  
  56. # Link against the GTK3 libraries
  57. target_link_libraries(${PROJECT_NAME} PRIVATE ${GTK3_LIBRARIES})
  58.  
  59. # Define the run command
  60. add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
  61.     COMMAND ${PROJECT_NAME}
  62.     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  63.     COMMENT "Running ${PROJECT_NAME}"
  64. )
  65.  
  66. # Create a custom target to run the project
  67. add_custom_target(run
  68.     COMMAND ${CMAKE_BINARY_DIR}/${PROJECT_NAME}
  69.     DEPENDS ${PROJECT_NAME}
  70.     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  71.     COMMENT "Running ${PROJECT_NAME}"
  72. )
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement