summaryrefslogtreecommitdiff
path: root/infrastructure/cmake
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2016-09-01 20:22:12 +0100
committerChris Wilson <chris+github@qwirx.com>2016-08-28 22:09:26 +0100
commitb60edf758b1797a901dba9c151e5cb664c76b0a6 (patch)
tree58b2467564e6fda1362b06262cef4c7a60a7adf0 /infrastructure/cmake
parent0ebfa6464b9987b5bd2a084872f7511625647391 (diff)
Standardise dependent library location for CMake.
Add a CMake module to find readline libraries for us.
Diffstat (limited to 'infrastructure/cmake')
-rw-r--r--infrastructure/cmake/CMakeLists.txt86
-rw-r--r--infrastructure/cmake/FindReadline.cmake84
2 files changed, 150 insertions, 20 deletions
diff --git a/infrastructure/cmake/CMakeLists.txt b/infrastructure/cmake/CMakeLists.txt
index 1d28b313..41172296 100644
--- a/infrastructure/cmake/CMakeLists.txt
+++ b/infrastructure/cmake/CMakeLists.txt
@@ -242,10 +242,9 @@ foreach(module_dep ${module_deps})
endif()
endforeach()
-#include(ExternalProject)
-#ExternalProject_Add(pcre
-# PREFIX "../pcre"
-# BUILD_COMMAND "${CMAKE_EXECUTABLE
+# We can't do anything conditional on CMAKE_BUILD_TYPE because that's not valid for multi-configuration
+# generators such as MSVC. We need to use a generator expression instead.
+target_compile_definitions(lib_common PUBLIC $<$<CONFIG:Release>:-DBOX_RELEASE_BUILD>)
# Tell QDBM not to build itself as a DLL, because we want to link statically to it.
target_compile_definitions(qdbm PUBLIC -DQDBM_STATIC)
@@ -260,27 +259,74 @@ endif(MSVC)
target_link_libraries(lib_common PUBLIC ws2_32 gdi32)
# Link to ZLib
+# http://stackoverflow.com/a/6174604/648162
include_directories(${base_dir}/../zlib-win32/include)
-find_library(zlibstaticd_lib_path zlibstaticd ${base_dir}/../zlib-win32/lib)
-find_library(zlibstatic_lib_path zlibstatic ${base_dir}/../zlib-win32/lib)
-target_link_libraries(lib_compress PUBLIC debug ${zlibstaticd_lib_path})
-target_link_libraries(lib_compress PUBLIC optimized ${zlibstatic_lib_path})
+# On Windows we want to statically link zlib to make debugging and distribution easier,
+# but FindZLIB.cmake doesn't offer that as an option, so we have to go through some
+# contortions to "find" the correct library. ZLIB_ROOT is required in this case.
+if(WIN32)
+ if(NOT DEFINED ZLIB_ROOT)
+ message(FATAL_ERROR "You must set ZLIB_ROOT to point to include/zlib.h and lib/zlibstatic[d].lib on Windows")
+ endif()
+
+ message(STATUS "Searching for Zlib in: ${ZLIB_ROOT}")
+ find_path(ZLIB_INCLUDE_DIR zlib.h PATHS ${ZLIB_ROOT}/include NO_DEFAULT_PATH)
+ include_directories(${ZLIB_INCLUDE_DIR})
+ message(STATUS "Found Zlib headers: ${ZLIB_INCLUDE_DIR}")
+
+ # We must link against zlibstaticD if this is a debug build, otherwise
+ # we have a C runtime mismatch (/MD versus /MDd) and the application
+ # crashes at runtime.
+ find_library(ZLIB_LIBRARY_STATIC_DEBUG NAMES zlibstaticd
+ PATHS ${ZLIB_ROOT}/lib NO_DEFAULT_PATH)
+ find_library(ZLIB_LIBRARY_STATIC_RELEASE NAMES zlibstatic
+ PATHS ${ZLIB_ROOT}/lib NO_DEFAULT_PATH)
+
+ target_link_libraries(lib_compress PUBLIC
+ debug ${ZLIB_LIBRARY_STATIC_DEBUG}
+ optimized ${ZLIB_LIBRARY_STATIC_RELEASE})
+else()
+ find_package(ZLIB REQUIRED)
+ include_directories(${ZLIB_INCLUDE_DIRS})
+ target_link_libraries(lib_compress PUBLIC ${ZLIB_LIBRARIES})
+endif()
# Link to OpenSSL
-include_directories(${base_dir}/../openssl-win32/include)
-find_library(libeay32_lib_path libeay32 ${base_dir}/../openssl-win32/lib)
-find_library(ssleay32_lib_path ssleay32 ${base_dir}/../openssl-win32/lib)
-target_link_libraries(lib_crypto PUBLIC ${libeay32_lib_path} ${ssleay32_lib_path})
+find_package(OpenSSL REQUIRED)
+include_directories(${OPENSSL_INCLUDE_DIR})
+target_link_libraries(lib_crypto PUBLIC ${OPENSSL_LIBRARIES})
# Link to PCRE
-include_directories(${base_dir}/../pcre-win32/include)
-target_compile_definitions(lib_common PUBLIC -DPCRE_STATIC)
-find_library(pcreposix_lib_path pcreposix ${base_dir}/../pcre-win32/lib)
-find_library(pcreposixd_lib_path pcreposixd ${base_dir}/../pcre-win32/lib)
-find_library(pcre_lib_path pcre ${base_dir}/../pcre-win32/lib)
-find_library(pcred_lib_path pcred ${base_dir}/../pcre-win32/lib)
-target_link_libraries(lib_common PUBLIC debug "${pcreposixd_lib_path}" optimized "${pcreposix_lib_path}")
-target_link_libraries(lib_common PUBLIC debug "${pcred_lib_path}" optimized "${pcre_lib_path}")
+if (WIN32)
+ if(NOT DEFINED PCRE_ROOT)
+ message(FATAL_ERROR "You must set PCRE_ROOT to point to include/pcreposix.h and lib/pcreposix[d].lib on Windows")
+ endif()
+
+ target_compile_definitions(lib_common PUBLIC -DPCRE_STATIC)
+ find_library(pcreposix_lib_path pcreposix ${PCRE_ROOT}/lib)
+ find_library(pcreposixd_lib_path pcreposixd ${PCRE_ROOT}/lib)
+ find_library(pcre_lib_path pcre ${PCRE_ROOT}/lib)
+ find_library(pcred_lib_path pcred ${PCRE_ROOT}/lib)
+ target_link_libraries(lib_common PUBLIC debug "${pcreposixd_lib_path}" optimized "${pcreposix_lib_path}")
+ target_link_libraries(lib_common PUBLIC debug "${pcred_lib_path}" optimized "${pcre_lib_path}")
+ include_directories(${PCRE_ROOT}/include)
+else()
+ find_package(PkgConfig REQUIRED)
+ pkg_check_modules(PCRE REQUIRED libpcreposix)
+ include_directories(${PCRE_INCLUDE_DIRS})
+ target_link_libraries(lib_common PUBLIC ${PCRE_LIBRARIES})
+
+ if(DEBUG)
+ message(STATUS "Linking PCRE libraries from ${PCRE_LIBRARY_DIRS}: ${PCRE_LIBRARIES}")
+ endif()
+endif()
+
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
+find_package(Readline)
+if(READLINE_FOUND)
+ include_directories(${Readline_INCLUDE_DIR})
+ target_link_libraries(lib_common PUBLIC ${Readline_LIBRARY})
+endif()
# Define the location of the Perl executable, needed by testbackupstorefix
cmake_to_native_path("${PERL_EXECUTABLE}" perl_executable_native)
diff --git a/infrastructure/cmake/FindReadline.cmake b/infrastructure/cmake/FindReadline.cmake
new file mode 100644
index 00000000..3ba4d21d
--- /dev/null
+++ b/infrastructure/cmake/FindReadline.cmake
@@ -0,0 +1,84 @@
+# https://github.com/bro/cmake/blob/master/FindReadline.cmake
+#
+# Copyright (c) 1995-2015, The Regents of the University of California
+# through the Lawrence Berkeley National Laboratory and the
+# International Computer Science Institute. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# (1) Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# (2) Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# (3) Neither the name of the University of California, Lawrence Berkeley
+# National Laboratory, U.S. Dept. of Energy, International Computer
+# Science Institute, nor the names of contributors may be used to endorse
+# or promote products derived from this software without specific prior
+# written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# Note that some files in the distribution may carry their own copyright
+# notices.
+
+# - Try to find readline include dirs and libraries
+#
+# Usage of this module as follows:
+#
+# find_package(Readline)
+#
+# Variables used by this module, they can change the default behaviour and need
+# to be set before calling find_package:
+#
+# Readline_ROOT_DIR Set this variable to the root installation of
+# readline if the module has problems finding the
+# proper installation path.
+#
+# Variables defined by this module:
+#
+# READLINE_FOUND System has readline, include and lib dirs found
+# Readline_INCLUDE_DIR The readline include directories.
+# Readline_LIBRARY The readline library.
+
+find_path(Readline_ROOT_DIR
+ NAMES include/readline/readline.h
+)
+
+find_path(Readline_INCLUDE_DIR
+ NAMES readline/readline.h
+ HINTS ${Readline_ROOT_DIR}/include
+)
+
+find_library(Readline_LIBRARY
+ NAMES readline
+ HINTS ${Readline_ROOT_DIR}/lib
+)
+
+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_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)
+
+mark_as_advanced(
+ Readline_ROOT_DIR
+ Readline_INCLUDE_DIR
+ Readline_LIBRARY
+)