Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #CMakeLists.txt file for compiling and running gtk3 applications on Debian 12 (Linux distro )
- cmake_minimum_required(VERSION 3.10)
- project(gtk3_examples C)
- # Custom function to introduce a time delay
- function(delay seconds)
- execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep ${seconds})
- endfunction()
- message(STATUS "Hello all this is GTK3 CMakeLists.txt file Written By Mark David Harrington!")
- delay(2) # Delay for 2 seconds
- message(STATUS "Im about to show you the power of CMake right the way from compilation to exe to lauch ")
- delay(2) # Delay for 2 second
- message(STATUS " Watch this do all of this for you !! Worth learning this and spending time doing ")
- delay(3)
- # Set the flags passed to the compiler
- set(CMAKE_C_FLAGS "-Wall -Wextra -Werror -rdynamic ${CMAKE_C_FLAGS}")
- # Set the standard required by the compiler
- set(CMAKE_C_STANDARD 11)
- set(CMAKE_C_STANDARD_REQUIRED ON)
- # Set the output directory for the build files
- set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
- # Set the output directory for the debug exe files
- set(CMAKE_DEBUG_DIR ${CMAKE_SOURCE_DIR}/debug)
- # Set the executable path to the debug subdirectory
- set(EXECUTABLE_OUTPUT_PATH ${CMAKE_DEBUG_DIR})
- # Find the GTK3 package
- find_package(PkgConfig REQUIRED)
- # Check if packages exist
- pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
- # Set the include directories
- include_directories(${GTK3_INCLUDE_DIRS})
- # Set the source and include files directories
- set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
- set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include)
- # Get all C source files in the subdirectory
- file(GLOB SOURCES ${SOURCE_DIR}/*.c)
- # Get all header files in the include directory
- file(GLOB HEADERS ${INCLUDE_DIR}/*.h)
- # Add the source files and headers to the project
- add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
- # Link against the GTK3 libraries
- target_link_libraries(${PROJECT_NAME} PRIVATE ${GTK3_LIBRARIES})
- # Define the run command
- add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
- COMMAND ${PROJECT_NAME}
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- COMMENT "Running ${PROJECT_NAME}"
- )
- # Create a custom target to run the project
- add_custom_target(run
- COMMAND ${CMAKE_BINARY_DIR}/${PROJECT_NAME}
- DEPENDS ${PROJECT_NAME}
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
- COMMENT "Running ${PROJECT_NAME}"
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement