Cleanup main CMake file
This commit is contained in:
parent
adf051a354
commit
7f0f3123c5
138
CMakeLists.txt
138
CMakeLists.txt
|
@ -1,4 +1,4 @@
|
||||||
# synergy -- mouse and keyboard sharing utility
|
# Synergy -- mouse and keyboard sharing utility
|
||||||
# Copyright (C) 2012-2016 Symless Ltd.
|
# Copyright (C) 2012-2016 Symless Ltd.
|
||||||
# Copyright (C) 2009 Nick Bolton
|
# Copyright (C) 2009 Nick Bolton
|
||||||
#
|
#
|
||||||
|
@ -15,8 +15,15 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
cmake_minimum_required (VERSION 3.4)
|
cmake_minimum_required (VERSION 3.4)
|
||||||
|
project (synergy C CXX)
|
||||||
|
|
||||||
# Version number for Synergy
|
option (SYNERGY_BUILD_LEGACY_SERVICE "Build the legacy service (synergyd)" ON)
|
||||||
|
|
||||||
|
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||||
|
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Eliminate variables not prefixed with SYNERGY_
|
||||||
if (DEFINED ENV{SYNERGY_VERSION_MAJOR})
|
if (DEFINED ENV{SYNERGY_VERSION_MAJOR})
|
||||||
set (VERSION_MAJOR $ENV{SYNERGY_VERSION_MAJOR})
|
set (VERSION_MAJOR $ENV{SYNERGY_VERSION_MAJOR})
|
||||||
set (VERSION_MINOR $ENV{SYNERGY_VERSION_MINOR})
|
set (VERSION_MINOR $ENV{SYNERGY_VERSION_MINOR})
|
||||||
|
@ -30,49 +37,29 @@ else()
|
||||||
set (VERSION_STAGE git)
|
set (VERSION_STAGE git)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV}")
|
|
||||||
set(SYNERGY_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV}")
|
|
||||||
|
|
||||||
# CMake complains if we don't have this.
|
set (SYNERGY_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV}")
|
||||||
|
set (VERSION $SYNERGY_VERSION)
|
||||||
|
message (STATUS "Synergy version is " $SYNERGY_VERSION)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Find out why we need these, and remove them
|
||||||
if (COMMAND cmake_policy)
|
if (COMMAND cmake_policy)
|
||||||
cmake_policy (SET CMP0003 NEW)
|
cmake_policy (SET CMP0003 NEW)
|
||||||
endif()
|
|
||||||
|
|
||||||
# We're escaping quotes in the Windows version number, because
|
|
||||||
# for some reason CMake won't do it at config version 2.4.7
|
|
||||||
# It seems that this restores the newer behaviour where define
|
|
||||||
# args are not auto-escaped.
|
|
||||||
if (COMMAND cmake_policy)
|
|
||||||
cmake_policy (SET CMP0005 NEW)
|
cmake_policy (SET CMP0005 NEW)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# First, declare project (important for prerequisite checks).
|
|
||||||
project(synergy C CXX)
|
|
||||||
|
|
||||||
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
# Add headers to source list
|
||||||
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
||||||
|
|
||||||
# Set some easy to type variables.
|
|
||||||
set(root_dir ${CMAKE_SOURCE_DIR})
|
|
||||||
set(cmake_dir ${root_dir}/res)
|
|
||||||
set(bin_dir ${root_dir}/bin)
|
|
||||||
set(doc_dir ${root_dir}/doc)
|
|
||||||
set(doc_dir ${root_dir}/doc)
|
|
||||||
|
|
||||||
# Declare libs, so we can use list in linker later. There's probably
|
|
||||||
# a more elegant way of doing this; with SCons, when you check for the
|
|
||||||
# lib, it is automatically passed to the linker.
|
|
||||||
set(libs)
|
|
||||||
|
|
||||||
# only include headers as "source" if not unix makefiles,
|
|
||||||
# which is useful when using an IDE.
|
|
||||||
if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
|
if (${CMAKE_GENERATOR} STREQUAL "Unix Makefiles")
|
||||||
set (SYNERGY_ADD_HEADERS FALSE)
|
set (SYNERGY_ADD_HEADERS FALSE)
|
||||||
else()
|
else()
|
||||||
set (SYNERGY_ADD_HEADERS TRUE)
|
set (SYNERGY_ADD_HEADERS TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Depending on the platform, pass in the required defines.
|
|
||||||
|
set (libs)
|
||||||
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
if (NOT APPLE)
|
if (NOT APPLE)
|
||||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||||
|
@ -118,15 +105,15 @@ if (UNIX)
|
||||||
# the inet_aton on some pure Unix platforms (e.g. sunos5). So we
|
# the inet_aton on some pure Unix platforms (e.g. sunos5). So we
|
||||||
# need to do a more detailed check and also include some extra libs.
|
# need to do a more detailed check and also include some extra libs.
|
||||||
if (NOT HAVE_INET_ATON)
|
if (NOT HAVE_INET_ATON)
|
||||||
|
|
||||||
set (CMAKE_REQUIRED_LIBRARIES nsl)
|
set (CMAKE_REQUIRED_LIBRARIES nsl)
|
||||||
|
|
||||||
check_c_source_compiles (
|
check_c_source_compiles (
|
||||||
"#include <arpa/inet.h>\n int main() { inet_aton (0, 0); }"
|
"#include <arpa/inet.h>\n int main() { inet_aton (0, 0); }"
|
||||||
HAVE_INET_ATON_ADV)
|
HAVE_INET_ATON_ADV)
|
||||||
|
|
||||||
set (CMAKE_REQUIRED_LIBRARIES)
|
set (CMAKE_REQUIRED_LIBRARIES)
|
||||||
|
|
||||||
if (HAVE_INET_ATON_ADV)
|
if (HAVE_INET_ATON_ADV)
|
||||||
|
|
||||||
# Override the previous fail.
|
# Override the previous fail.
|
||||||
set (HAVE_INET_ATON 1)
|
set (HAVE_INET_ATON 1)
|
||||||
|
|
||||||
|
@ -134,7 +121,6 @@ if (UNIX)
|
||||||
# it seems safe to add socket on the back of nsl,
|
# it seems safe to add socket on the back of nsl,
|
||||||
# since socket only ever needed when nsl is needed.
|
# since socket only ever needed when nsl is needed.
|
||||||
list (APPEND libs nsl socket)
|
list (APPEND libs nsl socket)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
@ -280,11 +266,13 @@ if (UNIX)
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
add_definitions (-DWINAPI_CARBON=1 -D_THREAD_SAFE)
|
add_definitions (-DWINAPI_CARBON=1 -D_THREAD_SAFE)
|
||||||
else (APPLE)
|
else()
|
||||||
add_definitions (-DWINAPI_XWINDOWS=1)
|
add_definitions (-DWINAPI_XWINDOWS=1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
else() # not-unix
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||||
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /D _BIND_TO_CURRENT_VCLIBS_VERSION=1")
|
||||||
|
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2 /Ob2")
|
||||||
|
|
||||||
list (APPEND libs Wtsapi32 Userenv Wininet comsuppw Shlwapi)
|
list (APPEND libs Wtsapi32 Userenv Wininet comsuppw Shlwapi)
|
||||||
|
|
||||||
|
@ -295,57 +283,44 @@ else() # not-unix
|
||||||
/DVERSION=\"${VERSION}\"
|
/DVERSION=\"${VERSION}\"
|
||||||
/D_XKEYCHECK_H
|
/D_XKEYCHECK_H
|
||||||
)
|
)
|
||||||
|
|
||||||
if (MSVC_VERSION EQUAL 1600)
|
|
||||||
set(SLN_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/synergy.sln")
|
|
||||||
if (EXISTS "${SLN_FILENAME}" )
|
|
||||||
file(APPEND "${SLN_FILENAME}" "\n# This should be regenerated!\n")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endif()
|
#
|
||||||
|
# OpenSSL
|
||||||
|
#
|
||||||
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||||
|
set (OPENSSL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/ext/openssl/windows)
|
||||||
|
|
||||||
if (WIN32)
|
|
||||||
set(OPENSSL_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/openssl/windows)
|
|
||||||
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
set(OPENSSL_BASE_DIR "${OPENSSL_BASE_DIR}/x64")
|
set (OPENSSL_ROOT "${OPENSSL_ROOT}/x64")
|
||||||
else()
|
else()
|
||||||
set(OPENSSL_BASE_DIR "${OPENSSL_BASE_DIR}/x86")
|
set (OPENSSL_ROOT "${OPENSSL_ROOT}/x86")
|
||||||
endif()
|
|
||||||
set(OPENSSL_LIBS
|
|
||||||
${OPENSSL_BASE_DIR}/lib/libeay32.lib
|
|
||||||
${OPENSSL_BASE_DIR}/lib/ssleay32.lib
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (UNIX)
|
|
||||||
if (APPLE)
|
|
||||||
set(OPENSSL_BASE_DIR /usr/local/opt/openssl)
|
|
||||||
set (OPENSSL_LIBS
|
set (OPENSSL_LIBS
|
||||||
${OPENSSL_BASE_DIR}/lib/libssl.a
|
${OPENSSL_ROOT}/lib/libeay32.lib
|
||||||
${OPENSSL_BASE_DIR}/lib/libcrypto.a
|
${OPENSSL_ROOT}/lib/ssleay32.lib
|
||||||
)
|
)
|
||||||
else()
|
|
||||||
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
set (OPENSSL_ROOT /usr/local/opt/openssl)
|
||||||
|
|
||||||
|
set (OPENSSL_LIBS
|
||||||
|
${OPENSSL_ROOT}/lib/libssl.a
|
||||||
|
${OPENSSL_ROOT}/lib/libcrypto.a
|
||||||
|
)
|
||||||
|
|
||||||
|
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
set (OPENSSL_LIBS ssl crypto)
|
set (OPENSSL_LIBS ssl crypto)
|
||||||
endif()
|
else()
|
||||||
|
message (FATAL_ERROR "Couldn't find OpenSSL")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(OPENSSL_INCLUDE ${OPENSSL_BASE_DIR}/include)
|
set (OPENSSL_INCLUDE ${OPENSSL_ROOT}/include)
|
||||||
|
|
||||||
if (WIN32)
|
|
||||||
# TODO: consider using /analyze to uncover potential bugs in the source code.
|
|
||||||
|
|
||||||
# /MP - use multi cores to compile.
|
|
||||||
# /D _BIND_TO_CURRENT_VCLIBS_VERSION - TODO: explain why.
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /D _BIND_TO_CURRENT_VCLIBS_VERSION=1")
|
|
||||||
|
|
||||||
# /MD - use multi-core libraries.
|
|
||||||
# /O2 - get the fastest code.
|
|
||||||
# /Ob2 - expand inline functions (auto-inlining).
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2 /Ob2")
|
|
||||||
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Configure_file... but for directories, recursively.
|
||||||
|
#
|
||||||
macro (configure_files srcDir destDir)
|
macro (configure_files srcDir destDir)
|
||||||
message (STATUS "Configuring directory ${destDir}")
|
message (STATUS "Configuring directory ${destDir}")
|
||||||
make_directory (${destDir})
|
make_directory (${destDir})
|
||||||
|
@ -373,18 +348,25 @@ macro(configure_files srcDir destDir)
|
||||||
endforeach (templateFile)
|
endforeach (templateFile)
|
||||||
endmacro (configure_files)
|
endmacro (configure_files)
|
||||||
|
|
||||||
|
#
|
||||||
|
# macOS app Bundle
|
||||||
|
#
|
||||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
set (CMAKE_INSTALL_RPATH "@loader_path/../Libraries;@loader_path/../Frameworks")
|
set (CMAKE_INSTALL_RPATH "@loader_path/../Libraries;@loader_path/../Frameworks")
|
||||||
|
|
||||||
set (SYNERGY_BUNDLE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dist/macos/bundle)
|
set (SYNERGY_BUNDLE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dist/macos/bundle)
|
||||||
set (SYNERGY_BUNDLE_DIR ${CMAKE_BINARY_DIR}/bundle)
|
set (SYNERGY_BUNDLE_DIR ${CMAKE_BINARY_DIR}/bundle)
|
||||||
set (SYNERGY_BUNDLE_APP_DIR ${SYNERGY_BUNDLE_DIR}/Synergy.app)
|
set (SYNERGY_BUNDLE_APP_DIR ${SYNERGY_BUNDLE_DIR}/Synergy.app)
|
||||||
set (SYNERGY_BUNDLE_BINARY_DIR ${SYNERGY_BUNDLE_APP_DIR}/Contents/MacOS)
|
set (SYNERGY_BUNDLE_BINARY_DIR ${SYNERGY_BUNDLE_APP_DIR}/Contents/MacOS)
|
||||||
|
|
||||||
configure_files (${SYNERGY_BUNDLE_SOURCE_DIR} ${SYNERGY_BUNDLE_DIR})
|
configure_files (${SYNERGY_BUNDLE_SOURCE_DIR} ${SYNERGY_BUNDLE_DIR})
|
||||||
elseif(WIN32 AND NOT UNIX)
|
endif()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Windows installer
|
||||||
|
#
|
||||||
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||||
configure_files (${CMAKE_CURRENT_SOURCE_DIR}/dist/wix ${CMAKE_BINARY_DIR}/installer)
|
configure_files (${CMAKE_CURRENT_SOURCE_DIR}/dist/wix ${CMAKE_BINARY_DIR}/installer)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(SYNERGY_BUILD_LEGACY_SERVICE "Build the legacy service (synergyd)" ON)
|
|
||||||
add_subdirectory (src)
|
add_subdirectory (src)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue