Skip to content

Commit a98358b

Browse files
committed
Improved structure: rename SocketSynergy, add CMakeLists.txt, src/include dirs
1 parent 7761f6b commit a98358b

13 files changed

Lines changed: 388 additions & 23 deletions

CMakeLists.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#
2+
# CMakeLists.txt for synergy
3+
#
4+
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
5+
project ("SocketSynergy" C)
6+
7+
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
8+
9+
include (MacroEnsureOutOfSourceBuild)
10+
include (MacroAddUninstallTarget)
11+
include (MacroGitVersionInfo)
12+
include (MacroCreateConfigFiles)
13+
14+
15+
#
16+
# OPTIONS / BUILD SETTINGS
17+
#
18+
19+
macro_ensure_out_of_source_build ("Do not build SocketSynergy in the source dir!")
20+
21+
get_version_from_git (SocketSynergy 0.0.0)
22+
23+
enable_testing ()
24+
25+
26+
#
27+
# DEPENDENCIES
28+
#
29+
30+
31+
#
32+
# BUILDING
33+
#
34+
35+
include_directories (include)
36+
37+
add_library (synergyShared SHARED src/synergy.c)
38+
39+
set_target_properties (synergyShared
40+
PROPERTIES OUTPUT_NAME synergy)
41+
42+
add_executable (synergy.d
43+
src/daemon.c)
44+
45+
add_executable (listendemo
46+
src/listendemo.c)
47+
48+
target_link_libraries (synergy.d synergyShared)
49+
target_link_libraries (listendemo synergyShared)
50+
51+
52+
#
53+
# INSTALLING
54+
#
55+
56+
install (TARGETS synergyShared synergy.d
57+
LIBRARY DESTINATION lib
58+
RUNTIME DESTINATION sbin
59+
PUBLIC_HEADER DESTINATION include/sys/socketsynergy.h)
60+
61+
add_uninstall_target ()
62+
63+
64+
#
65+
# PACKAGING
66+
#
67+
68+
set (CPACK_PACKAGE_NAME "SocketSynergy")
69+
set (CPACK_PACKAGE_VERSION ${SocketSynergy_VERSION})
70+
set (CPACK_PACKAGE_VENDOR "OpenFortress.nl")
71+
set (CPACK_PACKAGE_CONTACT "Rick van Rein <rick@openfortress.nl>")
72+
include (PackAllPossible)
73+
include (CPack)
74+
75+
# create_config_files (SocketSynergy)

Makefile.in

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# ADD_UNINSTALL_TARGET()
2+
# Add custom target 'uninstall' that removes all the files
3+
# installed by this build (not recommended by CMake devs though).
4+
#
5+
# Add an uninstall target, as described on the CMake wiki.
6+
# Include this file, then call add_uninstall_target().
7+
# Requires a top-level cmake/ directory containing this
8+
# macro file and a cmake_uninstall.cmake.in.
9+
10+
macro(add_uninstall_target)
11+
# uninstall target
12+
configure_file(
13+
"${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
14+
"${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
15+
IMMEDIATE @ONLY)
16+
17+
add_custom_target(uninstall
18+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake)
19+
endmacro()

cmake/MacroCreateConfigFiles.cmake

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# CREATE_CONFIG_FILES(<packagename>)
2+
# Call this macro to generate CMake and pkg-config configuration
3+
# files from templates found in the top-level source directory.
4+
#
5+
# Most ARPA2-related components write configuration-information
6+
# files and install them. There are two flavors:
7+
#
8+
# - CMake config-info files (<foo>Config.cmake and <foo>ConfigVersion.cmake)
9+
# - pkg-config files (<foo>.pc)
10+
#
11+
# The macro create_config_files() simplifies this process
12+
# by using named template files for all three output files.
13+
# Pass a package name (e.g. "Quick-DER") to the macro, and
14+
# the source files (e.g. <file>.in for the files named above
15+
# will be taken from the top-level source directory.
16+
#
17+
# As an (un)special case, the ConfigVersion file may be taken from
18+
# the cmake/ directory, since there is nothing particularly special
19+
# for that file (as opposed to the other files, which need to
20+
# specify paths, dependencies, and other things).
21+
22+
# Copyright 2017, Adriaan de Groot <groot@kde.org>
23+
#
24+
# Redistribution and use is allowed according to the terms of the two-clause BSD license.
25+
# https://opensource.org/licenses/BSD-2-Clause
26+
# SPDX short identifier: BSD-2-Clause
27+
28+
macro (create_config_files _packagename)
29+
export (PACKAGE ${_packagename})
30+
# The CMake configuration files are written to different locations
31+
# depending on the host platform, since different conventions apply.
32+
if (WIN32 AND NOT CYGWIN)
33+
set (DEF_INSTALL_CMAKE_DIR CMake)
34+
else ()
35+
set (DEF_INSTALL_CMAKE_DIR lib/cmake/${_packagename})
36+
endif ()
37+
set (INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
38+
"Installation directory for CMake files")
39+
40+
# Calculate include/ relative to the installed place of the config file.
41+
file (RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}"
42+
"${CMAKE_INSTALL_PREFIX}/include")
43+
set (CONF_INCLUDE_DIRS "\${${_packagename}_CMAKE_DIR}/${REL_INCLUDE_DIR}")
44+
# Substitute in real values for the placeholders in the .in files,
45+
# create the files in the build tree, and install them.
46+
configure_file (${PROJECT_SOURCE_DIR}/${_packagename}Config.cmake.in
47+
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}Config.cmake" @ONLY)
48+
set (_conf_version_filename ${PROJECT_SOURCE_DIR}/${_packagename}ConfigVersion.cmake.in)
49+
if (NOT EXISTS ${_conf_version_filename})
50+
# (un)special-case: use the generic version-checking file,
51+
# assume ${_packagename}_VERSION exists and copy that to
52+
# the generic version-variable for this file.
53+
set (_conf_version_filename ${PROJECT_SOURCE_DIR}/cmake/ConfigVersion.cmake.in)
54+
set (_conf_version ${${_packagename}_VERSION})
55+
endif ()
56+
configure_file (${_conf_version_filename}
57+
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}ConfigVersion.cmake" @ONLY)
58+
configure_file (${PROJECT_SOURCE_DIR}/${_packagename}.pc.in
59+
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}.pc" @ONLY)
60+
61+
install (FILES
62+
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}Config.cmake"
63+
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}ConfigVersion.cmake"
64+
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
65+
install (FILES
66+
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_packagename}.pc"
67+
DESTINATION "lib/pkgconfig/")
68+
endmacro ()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
2+
# Call this macro in your project if you want to enforce out-of-source builds.
3+
# If an in-source build is detected, it will abort with the given error message.
4+
# This macro works in any of the CMakeLists.txt of your project, but the recommended
5+
# location to call this is close to the beginning of the top level CMakeLists.txt
6+
7+
# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
8+
#
9+
# Redistribution and use is allowed according to the terms of the BSD license.
10+
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
11+
12+
MACRO (MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage)
13+
14+
STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
15+
IF(insource)
16+
MESSAGE(FATAL_ERROR "${_errorMessage}")
17+
ENDIF(insource)
18+
19+
ENDMACRO (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)

cmake/MacroGitVersionInfo.cmake

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# GET_VERSION_FROM_GIT(<appname> <default>)
2+
# Uses git tags to determine a version name and sets <appname>_VERSION
3+
# (along with split-out _MAJOR, _MINOR and _PATCHLEVEL variables). If
4+
# git isn't available, use <default> for version information (which should
5+
# be a string in the format M.m.p).
6+
#
7+
# Version Information
8+
#
9+
# This assumes you are working from a git checkout that uses tags
10+
# in an orderly fashion (e.g. according to the ARPA2 project best
11+
# practices guide, with version-* tags). It also checks for local
12+
# modifications and uses that to munge the <patchlevel> part of
13+
# the version number.
14+
#
15+
# Produces version numbers <major>.<minor>.<patchlevel>.
16+
#
17+
# To use the macro, provide an app- or package name; this is
18+
# used to fill variables called <app>_VERSION_MAJOR, .. and
19+
# overall <app>_VERSION. If git can't be found or does not Produce
20+
# meaningful output, use the provided default, e.g.:
21+
#
22+
# get_version_from_git(Quick-DER 0.1.5)
23+
#
24+
# After the macro invocation, Quick-DER_VERSION is set according
25+
# to the git tag or 0.1.5.
26+
#
27+
28+
# Copyright 2017, Adriaan de Groot <groot@kde.org>
29+
#
30+
# Redistribution and use is allowed according to the terms of the two-clause BSD license.
31+
# https://opensource.org/licenses/BSD-2-Clause
32+
# SPDX short identifier: BSD-2-Clause
33+
34+
macro(get_version_from_git _appname _default)
35+
find_package (Git QUIET)
36+
37+
if (Git_FOUND)
38+
message("-- Looking for git-versioning information.")
39+
exec_program (
40+
${GIT_EXECUTABLE}
41+
ARGS diff --quiet
42+
RETURN_VALUE GIT_HAVE_CHANGES
43+
)
44+
45+
exec_program (
46+
${GIT_EXECUTABLE}
47+
ARGS describe --tags --match 'version-*.*-*'
48+
OUTPUT_VARIABLE GIT_VERSION_INFO
49+
)
50+
else(NOT Git_FOUND)
51+
message(WARNING "Git not found; git-versioning uses default ${_default}.")
52+
set(GIT_VERSION_INFO "version-${_default}")
53+
set(GIT_HAVE_CHANGES 0)
54+
endif()
55+
56+
string (
57+
REGEX REPLACE "^version-([1-9][0-9]*|0)[.]([1-9][0-9]*|0)-(.*)$"
58+
"\\1"
59+
GIT_VERSION_MAJOR
60+
${GIT_VERSION_INFO}
61+
)
62+
63+
string (
64+
REGEX REPLACE "^version-([1-9][0-9]*|0)[.]([1-9][0-9]*|0)-(.*)$"
65+
"\\2"
66+
GIT_VERSION_MINOR
67+
${GIT_VERSION_INFO}
68+
)
69+
70+
if (GIT_HAVE_CHANGES EQUAL 0)
71+
string (
72+
REGEX REPLACE "^version-([1-9][0-9]*|0)[.]([1-9][0-9]*|0)-(.*)$"
73+
"\\3"
74+
GIT_VERSION_PATCHLEVEL
75+
${GIT_VERSION_INFO}
76+
)
77+
78+
set (
79+
USER_SUPPLIED_PATCHLEVEL
80+
"${GIT_VERSION_PATCHLEVEL}"
81+
CACHE STRING "User-override for patch level under ${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}"
82+
)
83+
84+
else()
85+
86+
exec_program (
87+
date
88+
ARGS '+%Y%m%d-%H%M%S'
89+
OUTPUT_VARIABLE GIT_CHANGES_TIMESTAMP
90+
)
91+
set (GIT_VERSION_PATCHLEVEL "local-${GIT_CHANGES_TIMESTAMP}")
92+
message (" Git reports local changes, fixing patch level to local-${GIT_CHANGES_TIMESTAMP}")
93+
94+
unset (USER_SUPPLIED_PATCHLEVEL CACHE)
95+
96+
endif()
97+
98+
set(${_appname}_VERSION_MAJOR ${GIT_VERSION_MAJOR})
99+
set(${_appname}_VERSION_MINOR ${GIT_VERSION_MINOR})
100+
set(${_appname}_VERSION_PATCHLEVEL ${GIT_VERSION_PATCHLEVEL})
101+
set(${_appname}_VERSION ${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_PATCHLEVEL})
102+
103+
if(Git_FOUND)
104+
message(" Got version ${${_appname}_VERSION}")
105+
endif()
106+
endmacro()

cmake/PackAllPossible.cmake

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# PackAllPossible.cmake -- find what target package formats can be made locally
2+
#
3+
# This package creates package formats for a maximum number of target formats:
4+
# - .tar.bz2 for source code
5+
# - .deb for Debian / Ubuntu / Mint Linux
6+
# - .rpm for RedHat / Fedora / SuSe Linux
7+
# - .pkg for Mac OS X
8+
#
9+
# The main output from this script is setting up the CPACK_GENERATOR list.
10+
#
11+
# The code below detects the available options automatically, by looking at
12+
# their CPack generator support and the availability of the main driving
13+
# program. There are no warnings for missing out on options, so you simply
14+
# may have to add such drivers if you intend to package for a wider range
15+
# of target platforms.
16+
#
17+
# No notion is taken of machine formats, also because CMake might be used for
18+
# cross-compiling. Please do not forget to think for yourself. Sure you can
19+
# build a Windows package filled with Linux executables, but it is not going
20+
# to be as useful as building a FreeBSD package with Linux executables.
21+
#
22+
#
23+
# Copyright 2017, Rick van Rein <rick@openfortress.nl>
24+
#
25+
# Redistribution and use is allowed according to the terms of the two-clause BSD license.
26+
# https://opensource.org/licenses/BSD-2-Clause
27+
# SPDX short identifier: BSD-2-Clause
28+
29+
30+
# Always produce a source tar ball
31+
set (CPACK_GENERATOR TGZ;TBZ2)
32+
33+
# Support DEB packaging for Debian / Ubuntu / Mint Linux
34+
find_program (PROGRAM_LINUX_DEBBUILD dpkg-buildpackage)
35+
if (NOT ${PROGRAM_LINUX_DEBBUILD} STREQUAL "PROGRAM_LINUX_DEBBUILD-NOTFOUND")
36+
list (APPEND CPACK_GENERATOR DEB)
37+
endif ()
38+
unset (PROGRAM_LINUX_DEBBUILD CACHE)
39+
40+
# Support RPM packaging for RedHat / Fedora / SuSe Linux
41+
find_program (PROGRAM_LINUX_RPMBUILD rpmbuild)
42+
if (NOT ${PROGRAM_LINUX_RPMBUILD} STREQUAL "PROGRAM_LINUX_RPMBUILD-NOTFOUND")
43+
list (APPEND CPACK_GENERATOR RPM)
44+
endif ()
45+
unset (PROGRAM_LINUX_RPMBUILD CACHE)
46+
47+
# Support PackageMaker packaging for Mac OS X
48+
find_program (PROGRAM_MACOSX_PKGBUILD pkgbuild)
49+
if (NOT ${PROGRAM_MACOSX_PKGBUILD} STREQUAL "PROGRAM_MACOSX_PKGBUILD-NOTFOUND")
50+
list (APPEND CPACK_GENERATOR PackageMaker)
51+
endif ()
52+
unset (PROGRAM_MACOSX_PKGBUILD CACHE)
53+
54+
# Support NSIS packaging for Windows
55+
find_program (PROGRAM_WINDOWS_NSISBUILD makensis)
56+
if (NOT ${PROGRAM_WINDOWS_NSISBUILD} STREQUAL "PROGRAM_WINDOWS_NSISBUILD-NOTFOUND")
57+
list (APPEND CPACK_GENERATOR NSIS)
58+
endif ()
59+
unset (PROGRAM_WINDOWS_NSISBUILD CACHE)
60+
61+
# Publish the results in the global cached scope
62+
set (CPACK_GENERATOR "${CPACK_GENERATOR}" CACHE STRING "CPack generators that will be run")

cmake/cmake_uninstall.cmake.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# From the CMake wiki; see MacroAddUninstallTarget.cmake
2+
3+
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
4+
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
5+
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
6+
7+
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
8+
string(REGEX REPLACE "\n" ";" files "${files}")
9+
foreach(file ${files})
10+
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
11+
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
12+
exec_program(
13+
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
14+
OUTPUT_VARIABLE rm_out
15+
RETURN_VALUE rm_retval
16+
)
17+
if(NOT "${rm_retval}" STREQUAL 0)
18+
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
19+
endif(NOT "${rm_retval}" STREQUAL 0)
20+
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
21+
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
22+
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
23+
endforeach(file)

0 commit comments

Comments
 (0)