Skip to content

Instantly share code, notes, and snippets.

@okhlybov
Created August 26, 2019 15:26
Show Gist options
  • Save okhlybov/724f5bef90f2dc45d5a44372e7f621d7 to your computer and use it in GitHub Desktop.
Save okhlybov/724f5bef90f2dc45d5a44372e7f621d7 to your computer and use it in GitHub Desktop.
CMake project template for incremental Vala program build
### CMake project template for building Vala program
### Makes use of the Vala support module https://github.com/nemequ/gnome-cmake/blob/master/modules/FindVala.cmake
### FindVala.cmake is expected to be put alongside this file
# Set to the project name from which executable name will be deduced
project()
# Set to the list of C, C++ and Vala sources which constitute the program
set(PROJECT_SOURCES )
# Set to the list of dependent PkgConfig packages
set(PROJECT_PACKAGES )
### No user-serviceable parts below
list(APPEND PROJECT_PACKAGES glib-2.0 gobject-2.0) # Mandatory dependencies for most Vala codes
cmake_minimum_required(VERSION 3.0)
list(APPEND CMAKE_MODULE_PATH .)
include_directories(.)
find_package(Vala REQUIRED)
find_package(PkgConfig REQUIRED)
set(VALA_TARGET ${PROJECT_NAME}-vala)
vala_precompile_target(${VALA_TARGET} AUTO_SOURCES ${PROJECT_SOURCES} PACKAGES ${PROJECT_PACKAGES})
foreach(PC ${PROJECT_PACKAGES})
pkg_check_modules(${PC} REQUIRED ${PC})
link_directories(${${PC}_LIBRARY_DIRS})
include_directories(${${PC}_INCLUDE_DIRS})
add_compile_options(${${PC}_CFLAGS_OTHER})
endforeach(PC)
add_executable(${PROJECT_NAME} ${AUTO_SOURCES})
foreach(PC ${PROJECT_PACKAGES})
target_link_libraries(${PROJECT_NAME} ${${PC}_LDFLAGS_OTHER})
target_link_libraries(${PROJECT_NAME} ${${PC}_LIBRARIES})
endforeach(PC)
add_dependencies(${PROJECT_NAME} ${VALA_TARGET})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment