Skip to content
Snippets Groups Projects
Commit 2fbfb9f7 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Switched to cmake build system for dserial-cli

parent 7b979947
No related branches found
No related tags found
No related merge requests found
BASE_URL := http://git.ok1kvk.cz/apps/ BASE_URL := http://git.ok1kvk.cz/apps/
QMAKE := qmake-qt5 QMAKE := qmake-qt5
CMAKE := cmake
build: dserial-cli/Readme.md dserial-protocol/Readme.md build-dserial-server/Makefile build: build-dserial-cli/Makefile dserial-protocol/Readme.md build-dserial-server/Makefile
cd build-dserial-server && make qmake && make cd build-dserial-server && make qmake && make
cd dserial-cli && make cd build-dserial-cli && make
build-dserial-server/Makefile: dserial-server/Readme.md build-dserial-server/Makefile: dserial-server/Readme.md
mkdir -p build-dserial-server && cd build-dserial-server && $(QMAKE) ../dserial-server/dserial-server.pro mkdir -p build-dserial-server && cd build-dserial-server && $(QMAKE) ../dserial-server/dserial-server.pro
build-dserial-cli/Makefile: dserial-cli/Readme.md
mkdir -p build-dserial-cli && cd build-dserial-cli && $(CMAKE) ../dserial-cli/
install: dserial-cli/Readme.md dserial-protocol/Readme.md dserial-server/Readme.md install: dserial-cli/Readme.md dserial-protocol/Readme.md dserial-server/Readme.md
cd dserial-cli && make install cd build-dserial-cli && make install
cd build-dserial-server && make install cd build-dserial-server && make install
push: push:
......
project("dserial-cli" C)
cmake_minimum_required(VERSION 3.1)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/vala)
find_package(Vala 0.29.3 REQUIRED)
include(${VALA_USE_FILE})
set(VALA_FILES
src/bigint.vala
src/dbus-serial-client.vala
src/error.vala
src/option-values.vala
src/serial-communicator-cli.vala
src/commands/AddCommand.vala
src/commands/AutodetectCommand.vala
src/commands/AutowriteCommand.vala
src/commands/BindCommand.vala
src/commands/CloseCommand.vala
src/commands/Command.vala
src/commands/ExitCommand.vala
src/commands/GetCommand.vala
src/commands/HelpCommand.vala
src/commands/InfoCommand.vala
src/commands/InteractiveCommand.vala
src/commands/ListCommand.vala
src/commands/OpenCommand.vala
src/commands/ReadCommand.vala
src/commands/SetCommand.vala
src/commands/UnbindCommand.vala
src/commands/ValuesCommand.vala
src/commands/WriteCommand.vala
)
vala_precompile(VALA_C
${VALA_FILES}
PACKAGES
readline
gio-2.0
posix
)
find_package(PkgConfig)
pkg_check_modules(GOBJECT REQUIRED gobject-2.0)
add_definitions(${GOBJECT_CFLAGS} ${GOBJECT_CFLAGS_OTHER})
link_libraries(${GOBJECT_LIBRARIES})
link_directories(${GOBJECT_LIBRARY_DIRS})
link_libraries(readline gio-2.0)
set(CMAKE_C_FLAGS "-g")
add_executable("dserial" ${VALA_C})
install(TARGETS dserial
RUNTIME DESTINATION bin)
# from http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/FindReadline.cmake
# http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/COPYING-CMAKE-SCRIPTS
# --> BSD licensed
#
# GNU Readline library finder
if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND NCURSES_LIBRARY)
set(READLINE_FOUND TRUE)
else(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND NCURSES_LIBRARY)
FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h
/usr/include/readline
)
# 2008-04-22 The next clause used to read like this:
#
# FIND_LIBRARY(READLINE_LIBRARY NAMES readline)
# FIND_LIBRARY(NCURSES_LIBRARY NAMES ncurses )
# include(FindPackageHandleStandardArgs)
# FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG NCURSES_LIBRARY READLINE_INCLUDE_DIR READLINE_LIBRARY )
#
# I was advised to modify it such that it will find an ncurses library if
# required, but not if one was explicitly given, that is, it allows the
# default to be overridden. PH
FIND_LIBRARY(READLINE_LIBRARY NAMES readline)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY )
MARK_AS_ADVANCED(READLINE_INCLUDE_DIR READLINE_LIBRARY)
endif(READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND NCURSES_LIBRARY)
# --------------------------------------------------
# Vala Makefile
# --------------------------------------------------
#
# This Makefile provides a starting point for building
# and testing Vala projects on Linux.
#
# There are two types of projects supported: executable
# and shared library. Basic installation/uninstallation
# support is provided as well.
#
# To build your project, first fill in some details below.
# At a minimum you need to specify a name for your
# project's target (the executable or library to be
# produced). You may also configure what packages are
# used to build it, how the files in your project's
# root are organized, and of course, whether it is an
# executable or library.
#
# There are three important subdirectories that this
# Makefile uses. The names of these can be configured
# further down, if you so desire.
#
# src/
# all *.vala source files. The `find' command
# is used to locate them, so feel free to create
# as many subdirectories here as you wish
#
# data/
# any additional data files for your project. When
# installed, the contents of this folder are copied
# directly to $(PREFIX)/share, so you should make
# sure that the contents mirror where you want them
# to be installed. For example, to create a launcher
# for your program, you could put the .desktop file
# in data/applications so that it would be installed
# to $(PREFIX)/share/applications.
# NOTE: this directory is only used for executable
# projects, and is set to read-only as long as the
# project is installed. To regain write access, you
# must first uninstall your project from the
# filesystem.
#
# build/
# where compiled results are placed, including
# intermediate .c and .o files as well as the final
# executable or library
#
# To build your project, make sure your desired source
# files are placed in src/, then run make.
#
# The following targets are supported:
#
# all/target: compiles the source and generates the
# final result in build/ (default)
# compile: compiles vala down to its C source, but
# doesn't generate the final result
# clean: cleans all compilation results for a fresh build
# install: installs this program/library
# uninstall: uninstalls this program/library
#
# To install the project, run `make install' with root
# privileges. The default prefix is /usr/local, which can
# be changed by specifying a new PREFIX variable on the
# command-line, e.g. `make install PREFIX=/usr'. Likewise,
# it can be uninstalled using `make uninstall` as root,
# using the same PREFIX variable as when it was installed.
#
# WHAT THIS MAKEFILE DOES NOT DO:
#
# - dependency/version checking
# - program configuration prior to running make
# - internationalization
# - anything besides compile vala and cp/rm files
#
# Enjoy.
#
# --------------------------------------------------
# BEGIN PROJECT CONFIGURATION
# --------------------------------------------------
# The name of the final result.
TARGET := dserial
# A space-separated list of packages required by your
# project. Names must be compatible with pkg-config, e.g.
# gtk+-3.0
PKGS :=
# Configure the project's directories.
SRC_DIR := $(DIRECTORY)src/
BUILD_DIR := $(DIRECTORY)build/
DATA_DIR := $(DIRECTORY)data/
# This is a hidden folder, simply used to help parallel builds
VALA_AUX := $(DIRECTORY).vala-aux/
# Set the vala compiler.
VALAC := valac
# Add any additional flags to pass to the vala compiler.
VALAFLAGS := --pkg readline --pkg gio-2.0 --pkg posix -g
# Set the C compiler.
CC := gcc
# Add any additional flags to pass to the C compiler.
CFLAGS := -O -w -lreadline -lgio-2.0 -g
# Add any additional flags to pass to the compiler during
# the linking phase.
OFLAGS :=
# --------------------------------------------------
# END PROJECT CONFIGURATION
# --------------------------------------------------
# Get pkg-config cflags and libs
PKG_CFLAGS := $(shell pkg-config --cflags gobject-2.0 $(PKGS))
PKG_LIBS := $(shell pkg-config --libs gobject-2.0 $(PKGS))
# Locate necessary files
VALA_FILES := $(shell find $(SRC_DIR) -type f -name "*.vala")
C_FILES = $(subst $(SRC_DIR),$(BUILD_DIR)c/,$(VALA_FILES:.vala=.c))
O_FILES = $(subst $(SRC_DIR),$(BUILD_DIR)o/,$(VALA_FILES:.vala=.o))
# Set stamp and deps information
# This part is needed in order to avoid re-building everything each time
BASENAMES = $(subst $(SRC_DIR),,$(subst $(SRC_DIR)/,,$(basename $(VALA_FILES))))
VALA_FASTVAPI_FILES = $(foreach f, $(BASENAMES), $(VALA_AUX)$(f).vapi)
VALA_FASTVAPI_STAMPS = $(foreach f, $(BASENAMES), $(VALA_AUX)$(f).vapi.stamp)
VALA_DEPS = $(foreach f, $(BASENAMES), $(VALA_AUX)$(f).dep)
# Default installation prefix
PREFIX = /usr/local
BUILDMSG := Generating executable...
.PRECIOUS: $(VALA_AUX)%.vapi.stamp $(VALA_AUX)%.dep
# Fast option
ifneq ($(INCREMENTAL), true)
$(BUILD_DIR)$(TARGET): src/*.vala src/commands/*.vala Makefile
@echo ' $(BUILDMSG) ';mkdir -p $(BUILD_DIR) && $(VALAC) $(wildcard src/*.vala) $(wildcard src/*/*.vala) -X -w -o $(BUILD_DIR)$(TARGET) $(VALAFLAGS) -X -lreadline -g
@echo " Done"
# At first slower but then faster option, sometimes buggy
else
all: $(BUILD_DIR)$(TARGET)
$(VALA_FASTVAPI_FILES): ;
$(VALA_AUX)%.vapi.stamp: $(SRC_DIR)%.vala | $(VALA_AUX)
@echo ' GEN '$(@:$(VALA_AUX)%.stamp=%); mkdir -p $(dir $@) && $(VALAC) --fast-vapi=$(@:.stamp=) $(@:$(VALA_AUX)%.vapi.stamp=$(SRC_DIR)%.vala) && touch $@
$(VALA_AUX)%.dep: $(SRC_DIR)%.vala | $(VALA_FASTVAPI_STAMPS)
@echo ' VALAC -> dep '$(patsubst $(VALA_AUX)%.dep,%.vala,$(subst //,/,$@)); $(VALAC) -C --deps=$@ -b $(SRC_DIR) -d $(BUILD_DIR)c $(VALAFLAGS) $(addprefix --use-fast-vapi=,$(subst $(patsubst $(VALA_AUX)%.dep,%.vapi,$(subst //,/,$@)),, $(VALA_FASTVAPI_FILES))) $(addprefix --pkg=,$(PKGS)) $<
$(VALA_AUX):
@mkdir -p $(VALA_AUX)
$(BUILD_DIR)c/%.c : | $(VALA_AUX)%.dep ;
@echo ' VALAC -> c '$(@:$(BUILD_DIR)c/%=%);$(VALAC) -C -b $(SRC_DIR) -d $(BUILD_DIR)c $(VALAFLAGS) $(addprefix --use-fast-vapi=,$(subst $(VALA_AUX)$(@:$(BUILD_DIR)c/%.c=%.vapi),, $(VALA_FASTVAPI_FILES))) $(addprefix --pkg=,$(PKGS)) $(@:$(BUILD_DIR)c/%.c=$(SRC_DIR)%.vala)
$(BUILD_DIR)o/%.o: $(BUILD_DIR)c/%.c
@echo ' CC '$(<:$(BUILD_DIR)c/%=%); mkdir -p $(dir $@); $(CC) -c $(CFLAGS) $(PKG_CFLAGS) -o $@ $(@:$(BUILD_DIR)o/%.o=$(BUILD_DIR)c/%.c)
$(BUILD_DIR)$(TARGET): $(O_FILES) $(C_FILES)
@echo ' $(BUILDMSG) ';$(CC) -o $(BUILD_DIR)$(TARGET) $(OFLAGS) $(O_FILES) $(PKG_LIBS) $(CFLAGS)
@echo ' Done.'
endif
run: $(BUILD_DIR)$(TARGET)
./$(BUILD_DIR)$(TARGET) interactive
clean:
@echo ' Cleaning up...'; $(RM) -rf $(BUILD_DIR) $(VALA_AUX)
@echo ' Done.'
install:
@echo ' Installing to $(PREFIX)...' && cp $(BUILD_DIR)$(TARGET) $(PREFIX)/bin/$(TARGET)
@echo ' Done.'
uninstall:
@echo ' Removing $(PREFIX)/bin/$(TARGET)...'; $(RM) $(PREFIX)/bin/$(TARGET)
@echo ' Done.'
.PHONY: all clean $(BUILD_DIR)$(TARGET) install install-EXEC install-LIB uninstall uninstall-EXEC uninstall-LIB
include $(wildcard $(VALA_AUX)/*.dep)
...@@ -75,7 +75,7 @@ public class InteractiveCommand : Object, Command ...@@ -75,7 +75,7 @@ public class InteractiveCommand : Object, Command
state.interactive = true; state.interactive = true;
stdout.printf("dserial: Serial communication program\n"); stdout.printf("dserial: Serial communication program\n");
stdout.printf("License: GPL3+\n"); stdout.printf("License: GPL3+\n");
stdout.printf("Version: 0.4\n"); stdout.printf("Version: 0.4b\n");
stdout.printf("Write help for help\n"); stdout.printf("Write help for help\n");
Readline.History.read(Environment.get_variable("HOME")+"/.dserial-history"); Readline.History.read(Environment.get_variable("HOME")+"/.dserial-history");
Readline.attempted_completion_function = readline_completion; Readline.attempted_completion_function = readline_completion;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment