Skip to content

Commit

Permalink
Improved structure: rename SocketSynergy, add CMakeLists.txt, src/inc…
Browse files Browse the repository at this point in the history
…lude dirs
  • Loading branch information
vanrein committed Feb 21, 2017
1 parent 7761f6b commit a98358b
Show file tree
Hide file tree
Showing 13 changed files with 388 additions and 23 deletions.
75 changes: 75 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#
# CMakeLists.txt for synergy
#
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
project ("SocketSynergy" C)

set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)

include (MacroEnsureOutOfSourceBuild)
include (MacroAddUninstallTarget)
include (MacroGitVersionInfo)
include (MacroCreateConfigFiles)


#
# OPTIONS / BUILD SETTINGS
#

macro_ensure_out_of_source_build ("Do not build SocketSynergy in the source dir!")

get_version_from_git (SocketSynergy 0.0.0)

enable_testing ()


#
# DEPENDENCIES
#


#
# BUILDING
#

include_directories (include)

add_library (synergyShared SHARED src/synergy.c)

set_target_properties (synergyShared
PROPERTIES OUTPUT_NAME synergy)

add_executable (synergy.d
src/daemon.c)

add_executable (listendemo
src/listendemo.c)

target_link_libraries (synergy.d synergyShared)
target_link_libraries (listendemo synergyShared)


#
# INSTALLING
#

install (TARGETS synergyShared synergy.d
LIBRARY DESTINATION lib
RUNTIME DESTINATION sbin
PUBLIC_HEADER DESTINATION include/sys/socketsynergy.h)

add_uninstall_target ()


#
# PACKAGING
#

set (CPACK_PACKAGE_NAME "SocketSynergy")
set (CPACK_PACKAGE_VERSION ${SocketSynergy_VERSION})
set (CPACK_PACKAGE_VENDOR "OpenFortress.nl")
set (CPACK_PACKAGE_CONTACT "Rick van Rein <rick@openfortress.nl>")
include (PackAllPossible)
include (CPack)

# create_config_files (SocketSynergy)
14 changes: 0 additions & 14 deletions Makefile.in

This file was deleted.

19 changes: 19 additions & 0 deletions cmake/MacroAddUninstallTarget.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ADD_UNINSTALL_TARGET()
# Add custom target 'uninstall' that removes all the files
# installed by this build (not recommended by CMake devs though).
#
# Add an uninstall target, as described on the CMake wiki.
# Include this file, then call add_uninstall_target().
# Requires a top-level cmake/ directory containing this
# macro file and a cmake_uninstall.cmake.in.

macro(add_uninstall_target)
# uninstall target
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake)
endmacro()
68 changes: 68 additions & 0 deletions cmake/MacroCreateConfigFiles.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# CREATE_CONFIG_FILES(<packagename>)
# Call this macro to generate CMake and pkg-config configuration
# files from templates found in the top-level source directory.
#
# Most ARPA2-related components write configuration-information
# files and install them. There are two flavors:
#
# - CMake config-info files (<foo>Config.cmake and <foo>ConfigVersion.cmake)
# - pkg-config files (<foo>.pc)
#
# The macro create_config_files() simplifies this process
# by using named template files for all three output files.
# Pass a package name (e.g. "Quick-DER") to the macro, and
# the source files (e.g. <file>.in for the files named above
# will be taken from the top-level source directory.
#
# As an (un)special case, the ConfigVersion file may be taken from
# the cmake/ directory, since there is nothing particularly special
# for that file (as opposed to the other files, which need to
# specify paths, dependencies, and other things).

# Copyright 2017, Adriaan de Groot <groot@kde.org>
#
# Redistribution and use is allowed according to the terms of the two-clause BSD license.
# https://opensource.org/licenses/BSD-2-Clause
# SPDX short identifier: BSD-2-Clause

macro (create_config_files _packagename)
export (PACKAGE ${_packagename})
# The CMake configuration files are written to different locations
# depending on the host platform, since different conventions apply.
if (WIN32 AND NOT CYGWIN)
set (DEF_INSTALL_CMAKE_DIR CMake)
else ()
set (DEF_INSTALL_CMAKE_DIR lib/cmake/${_packagename})
endif ()
set (INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
"Installation directory for CMake files")

# Calculate include/ relative to the installed place of the config file.
file (RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}"
"${CMAKE_INSTALL_PREFIX}/include")
set (CONF_INCLUDE_DIRS "\${${_packagename}_CMAKE_DIR}/${REL_INCLUDE_DIR}")
# Substitute in real values for the placeholders in the .in files,
# create the files in the build tree, and install them.
configure_file (${PROJECT_SOURCE_DIR}/${_packagename}Config.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}Config.cmake" @ONLY)
set (_conf_version_filename ${PROJECT_SOURCE_DIR}/${_packagename}ConfigVersion.cmake.in)
if (NOT EXISTS ${_conf_version_filename})
# (un)special-case: use the generic version-checking file,
# assume ${_packagename}_VERSION exists and copy that to
# the generic version-variable for this file.
set (_conf_version_filename ${PROJECT_SOURCE_DIR}/cmake/ConfigVersion.cmake.in)
set (_conf_version ${${_packagename}_VERSION})
endif ()
configure_file (${_conf_version_filename}
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}ConfigVersion.cmake" @ONLY)
configure_file (${PROJECT_SOURCE_DIR}/${_packagename}.pc.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}.pc" @ONLY)

install (FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}Config.cmake"
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}ConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
install (FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}.pc"
DESTINATION "lib/pkgconfig/")
endmacro ()
19 changes: 19 additions & 0 deletions cmake/MacroEnsureOutOfSourceBuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
# Call this macro in your project if you want to enforce out-of-source builds.
# If an in-source build is detected, it will abort with the given error message.
# This macro works in any of the CMakeLists.txt of your project, but the recommended
# location to call this is close to the beginning of the top level CMakeLists.txt

# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

MACRO (MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage)

STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
IF(insource)
MESSAGE(FATAL_ERROR "${_errorMessage}")
ENDIF(insource)

ENDMACRO (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
106 changes: 106 additions & 0 deletions cmake/MacroGitVersionInfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# GET_VERSION_FROM_GIT(<appname> <default>)
# Uses git tags to determine a version name and sets <appname>_VERSION
# (along with split-out _MAJOR, _MINOR and _PATCHLEVEL variables). If
# git isn't available, use <default> for version information (which should
# be a string in the format M.m.p).
#
# Version Information
#
# This assumes you are working from a git checkout that uses tags
# in an orderly fashion (e.g. according to the ARPA2 project best
# practices guide, with version-* tags). It also checks for local
# modifications and uses that to munge the <patchlevel> part of
# the version number.
#
# Produces version numbers <major>.<minor>.<patchlevel>.
#
# To use the macro, provide an app- or package name; this is
# used to fill variables called <app>_VERSION_MAJOR, .. and
# overall <app>_VERSION. If git can't be found or does not Produce
# meaningful output, use the provided default, e.g.:
#
# get_version_from_git(Quick-DER 0.1.5)
#
# After the macro invocation, Quick-DER_VERSION is set according
# to the git tag or 0.1.5.
#

# Copyright 2017, Adriaan de Groot <groot@kde.org>
#
# Redistribution and use is allowed according to the terms of the two-clause BSD license.
# https://opensource.org/licenses/BSD-2-Clause
# SPDX short identifier: BSD-2-Clause

macro(get_version_from_git _appname _default)
find_package (Git QUIET)

if (Git_FOUND)
message("-- Looking for git-versioning information.")
exec_program (
${GIT_EXECUTABLE}
ARGS diff --quiet
RETURN_VALUE GIT_HAVE_CHANGES
)

exec_program (
${GIT_EXECUTABLE}
ARGS describe --tags --match 'version-*.*-*'
OUTPUT_VARIABLE GIT_VERSION_INFO
)
else(NOT Git_FOUND)
message(WARNING "Git not found; git-versioning uses default ${_default}.")
set(GIT_VERSION_INFO "version-${_default}")
set(GIT_HAVE_CHANGES 0)
endif()

string (
REGEX REPLACE "^version-([1-9][0-9]*|0)[.]([1-9][0-9]*|0)-(.*)$"
"\\1"
GIT_VERSION_MAJOR
${GIT_VERSION_INFO}
)

string (
REGEX REPLACE "^version-([1-9][0-9]*|0)[.]([1-9][0-9]*|0)-(.*)$"
"\\2"
GIT_VERSION_MINOR
${GIT_VERSION_INFO}
)

if (GIT_HAVE_CHANGES EQUAL 0)
string (
REGEX REPLACE "^version-([1-9][0-9]*|0)[.]([1-9][0-9]*|0)-(.*)$"
"\\3"
GIT_VERSION_PATCHLEVEL
${GIT_VERSION_INFO}
)

set (
USER_SUPPLIED_PATCHLEVEL
"${GIT_VERSION_PATCHLEVEL}"
CACHE STRING "User-override for patch level under ${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}"
)

else()

exec_program (
date
ARGS '+%Y%m%d-%H%M%S'
OUTPUT_VARIABLE GIT_CHANGES_TIMESTAMP
)
set (GIT_VERSION_PATCHLEVEL "local-${GIT_CHANGES_TIMESTAMP}")
message (" Git reports local changes, fixing patch level to local-${GIT_CHANGES_TIMESTAMP}")

unset (USER_SUPPLIED_PATCHLEVEL CACHE)

endif()

set(${_appname}_VERSION_MAJOR ${GIT_VERSION_MAJOR})
set(${_appname}_VERSION_MINOR ${GIT_VERSION_MINOR})
set(${_appname}_VERSION_PATCHLEVEL ${GIT_VERSION_PATCHLEVEL})
set(${_appname}_VERSION ${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_PATCHLEVEL})

if(Git_FOUND)
message(" Got version ${${_appname}_VERSION}")
endif()
endmacro()
62 changes: 62 additions & 0 deletions cmake/PackAllPossible.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# PackAllPossible.cmake -- find what target package formats can be made locally
#
# This package creates package formats for a maximum number of target formats:
# - .tar.bz2 for source code
# - .deb for Debian / Ubuntu / Mint Linux
# - .rpm for RedHat / Fedora / SuSe Linux
# - .pkg for Mac OS X
#
# The main output from this script is setting up the CPACK_GENERATOR list.
#
# The code below detects the available options automatically, by looking at
# their CPack generator support and the availability of the main driving
# program. There are no warnings for missing out on options, so you simply
# may have to add such drivers if you intend to package for a wider range
# of target platforms.
#
# No notion is taken of machine formats, also because CMake might be used for
# cross-compiling. Please do not forget to think for yourself. Sure you can
# build a Windows package filled with Linux executables, but it is not going
# to be as useful as building a FreeBSD package with Linux executables.
#
#
# Copyright 2017, Rick van Rein <rick@openfortress.nl>
#
# Redistribution and use is allowed according to the terms of the two-clause BSD license.
# https://opensource.org/licenses/BSD-2-Clause
# SPDX short identifier: BSD-2-Clause


# Always produce a source tar ball
set (CPACK_GENERATOR TGZ;TBZ2)

# Support DEB packaging for Debian / Ubuntu / Mint Linux
find_program (PROGRAM_LINUX_DEBBUILD dpkg-buildpackage)
if (NOT ${PROGRAM_LINUX_DEBBUILD} STREQUAL "PROGRAM_LINUX_DEBBUILD-NOTFOUND")
list (APPEND CPACK_GENERATOR DEB)
endif ()
unset (PROGRAM_LINUX_DEBBUILD CACHE)

# Support RPM packaging for RedHat / Fedora / SuSe Linux
find_program (PROGRAM_LINUX_RPMBUILD rpmbuild)
if (NOT ${PROGRAM_LINUX_RPMBUILD} STREQUAL "PROGRAM_LINUX_RPMBUILD-NOTFOUND")
list (APPEND CPACK_GENERATOR RPM)
endif ()
unset (PROGRAM_LINUX_RPMBUILD CACHE)

# Support PackageMaker packaging for Mac OS X
find_program (PROGRAM_MACOSX_PKGBUILD pkgbuild)
if (NOT ${PROGRAM_MACOSX_PKGBUILD} STREQUAL "PROGRAM_MACOSX_PKGBUILD-NOTFOUND")
list (APPEND CPACK_GENERATOR PackageMaker)
endif ()
unset (PROGRAM_MACOSX_PKGBUILD CACHE)

# Support NSIS packaging for Windows
find_program (PROGRAM_WINDOWS_NSISBUILD makensis)
if (NOT ${PROGRAM_WINDOWS_NSISBUILD} STREQUAL "PROGRAM_WINDOWS_NSISBUILD-NOTFOUND")
list (APPEND CPACK_GENERATOR NSIS)
endif ()
unset (PROGRAM_WINDOWS_NSISBUILD CACHE)

# Publish the results in the global cached scope
set (CPACK_GENERATOR "${CPACK_GENERATOR}" CACHE STRING "CPack generators that will be run")
23 changes: 23 additions & 0 deletions cmake/cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# From the CMake wiki; see MacroAddUninstallTarget.cmake

if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")

file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif(NOT "${rm_retval}" STREQUAL 0)
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)
Loading

0 comments on commit a98358b

Please sign in to comment.