Clean up Travis CI build and add FindPoco cmake module from libsourcey project

This commit is contained in:
Tristan Penman 2017-05-31 15:53:42 +10:00
parent f68ea9b6b9
commit 37173c0947
6 changed files with 802 additions and 57 deletions

View File

@ -9,7 +9,7 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: ['g++-5', 'qtbase5-dev']
packages: ['g++-5', 'qtbase5-dev', 'libboost1.55-dev', 'libssl-dev']
env:
- CXX_COMPILER=g++-5
- C_COMPILER=gcc-5
@ -19,41 +19,49 @@ matrix:
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
packages: ['clang-3.6', 'qtbase5-dev']
packages: ['clang-3.6', 'qtbase5-dev', 'libboost1.55-dev', 'libssl-dev']
env:
- CXX_COMPILER=clang++-3.6
- C_COMPILER=clang-3.6
- CMAKE_FLAGS="-DCMAKE_CXX_FLAGS=-DBOOST_NO_CXX11_ALLOCATOR"
- os: linux
compiler: clang
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
packages: ['clang-3.7', 'qtbase5-dev']
packages: ['clang-3.7', 'qtbase5-dev', 'libboost1.55-dev', 'libssl-dev']
env:
- CXX_COMPILER=clang++-3.7
- C_COMPILER=clang-3.7
- CMAKE_FLAGS="-DCMAKE_CXX_FLAGS=-DBOOST_NO_CXX11_ALLOCATOR"
- os: linux
compiler: clang
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.8']
packages: ['clang-3.8', 'libc++-dev', 'libc++abi-dev', 'qtbase5-dev']
packages: ['clang-3.8', 'libc++-dev', 'libc++abi-dev', 'qtbase5-dev', 'libboost1.55-dev', 'libssl-dev']
env:
- CXX_COMPILER=clang++-3.8
- C_COMPILER=clang-3.8
- CMAKE_FLAGS="-DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_EXE_LINKER_FLAGS=-lc++"
- CMAKE_CXX_FLAGS="-stdlib=libc++"
- CMAKE_EXE_LINKER_FLAGS="-lc++"
before_install:
- sudo add-apt-repository -y ppa:frodo-vdr/unstable-main
- sudo apt-get update -qq
- sudo apt-get install -y --force-yes libboost1.55-dev libpocojson42 libpoco-dev
- pushd ~
- wget https://github.com/pocoproject/poco/archive/poco-1.7.8p2-release.tar.gz
- tar -xf poco-1.7.8p2-release.tar.gz
- cd poco-poco-1.7.8p2-release
- mkdir cmake_build
- cd cmake_build
- export POCO_OPTS="-DENABLE_CRYPTO=off -DENABLE_DATA=off -DENABLE_DATA_MYSQL=off -DENABLE_DATA_ODBC=off -DENABLE_DATA_SQLITE=off"
- export POCO_OPTS="$POCO_OPTS -DENABLE_MONGODB=off -DENABLE_NET=off -DENABLE_NETSSL=off -DENABLE_PAGECOMPILER=off"
- export POCO_OPTS="$POCO_OPTS -DENABLE_PAGECOMPILER_FILE2PAGE=off -DENABLE_PDF=off -DENABLE_UTIL=off -DENABLE_XML=off -DENABLE_ZIP=off"
- cmake -D CMAKE_CXX_COMPILER=`which ${CXX_COMPILER}` -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" -DCMAKE_EXE_LINKER_FLAGS="$CMAKE_EXE_LINKER_FLAGS" $POCO_OPTS ..
- sudo make install
- popd
script:
- mkdir build && cd build
- cmake $CMAKE_FLAGS -DCMAKE_CXX_COMPILER=$CXX_COMPILER -DCMAKE_C_COMPILER=$C_COMPILER ..
- cmake -D CMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" -D CMAKE_EXE_LINKER_FLAGS="$CMAKE_EXE_LINKER_FLAGS" -D CMAKE_CXX_COMPILER="$CXX_COMPILER" -D CMAKE_C_COMPILER="$C_COMPILER" ..
- VERBOSE=1 make
- ./test_suite

View File

@ -1,11 +1,22 @@
cmake_minimum_required (VERSION 3.1)
project (valijson)
option (INSTALL_HEADERS "Install valijson Headers." FALSE)
option (BUILD_EXAMPLES "Build valijson Examples." FALSE)
option (BUILD_TESTS "Build valijson Tests." TRUE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ")
if (BUILD_TESTS OR BUILD_EXAMPLES)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
option(INSTALL_HEADERS "Install valijson Headers." FALSE)
option(BUILD_EXAMPLES "Build valijson Examples." FALSE)
option(BUILD_TESTS "Build valijson Tests." TRUE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
if(INSTALL_HEADERS)
install(DIRECTORY include/ DESTINATION include)
endif()
if(!BUILD_TESTS AND !BUILD_EXAMPLES)
return()
endif()
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
include(CheckCXXCompilerFlag)
@ -32,42 +43,31 @@ add_library(jsoncpp
thirdparty/jsoncpp-0.9.4/src/lib_json/json_writer.cpp
)
target_include_directories(jsoncpp SYSTEM PRIVATE
thirdparty/jsoncpp-0.9.4/include
)
set_target_properties(jsoncpp PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/thirdparty/jsoncpp-0.9.4)
target_include_directories(jsoncpp SYSTEM PRIVATE thirdparty/jsoncpp-0.9.4/include)
set_target_properties(jsoncpp PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/thirdparty/jsoncpp-0.9.4)
add_library(json11
thirdparty/json11-2016-01-26/json11.cpp
thirdparty/json11-2016-01-26/json11.cpp
)
target_include_directories(json11 SYSTEM PRIVATE
thirdparty/json11-2016-01-26
)
set_target_properties(json11 PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/thirdparty/json11-2016-01-26)
target_include_directories(json11 SYSTEM PRIVATE thirdparty/json11-2016-01-26)
set_target_properties(json11 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/thirdparty/json11-2016-01-26)
# Build local gtest
set(gtest_force_shared_crt ON)
add_subdirectory(thirdparty/gtest-1.7.0)
# Include path
include_directories(
include
)
include_directories(include)
include_directories(SYSTEM
thirdparty/gtest-1.7.0/include
thirdparty/json11-2016-01-26
thirdparty/jsoncpp-0.9.4/include
thirdparty/rapidjson-1.0.2/include
thirdparty/picojson-1.3.0
thirdparty/nlohmann-json-1.1.0
${Boost_INCLUDE_DIRS}
${Qt5Core_INCLUDE_DIRS}
thirdparty/gtest-1.7.0/include
thirdparty/json11-2016-01-26
thirdparty/jsoncpp-0.9.4/include
thirdparty/rapidjson-1.0.2/include
thirdparty/picojson-1.3.0
thirdparty/nlohmann-json-1.1.0
${Boost_INCLUDE_DIRS}
${Qt5Core_INCLUDE_DIRS}
)
# Custom schema validation example
@ -96,37 +96,28 @@ set(TEST_SOURCES
tests/test_poly_constraint.cpp
)
if (Qt5Core_FOUND)
list(APPEND TEST_SOURCES
tests/test_qtjson_adapter.cpp
)
if(Qt5Core_FOUND)
list(APPEND TEST_SOURCES tests/test_qtjson_adapter.cpp)
endif()
# Unit tests executable
add_executable(test_suite ${TEST_SOURCES})
# Definition for using picojson
set_target_properties(test_suite
PROPERTIES COMPILE_DEFINITIONS "PICOJSON_USE_INT64"
)
set_target_properties(test_suite PROPERTIES COMPILE_DEFINITIONS "PICOJSON_USE_INT64")
set(TEST_LIBS gtest gtest_main jsoncpp json11)
if (Qt5Core_FOUND)
list(APPEND TEST_LIBS Qt5::Core)
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTERS")
list(APPEND TEST_LIBS Qt5::Core)
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_QT_ADAPTERS")
endif()
if(Poco_FOUND)
list(APPEND TEST_LIBS ${Poco_LIBRARIES})
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTERS")
list(APPEND TEST_LIBS ${Poco_Foundation_LIBRARIES} ${Poco_JSON_LIBRARIES})
target_compile_definitions(test_suite PRIVATE "VALIJSON_BUILD_POCO_ADAPTERS")
endif()
target_link_libraries(test_suite ${TEST_LIBS} ${Boost_LIBRARIES})
target_link_libraries(custom_schema ${Boost_LIBRARIES})
target_link_libraries(external_schema ${Boost_LIBRARIES})
endif()
if (INSTALL_HEADERS )
install(DIRECTORY include/ DESTINATION include )
endif()

View File

@ -0,0 +1,375 @@
#
### Macro: find_library_extended
#
# Finds libraries with finer control over search paths
# for compilers with multiple configuration types.
#
macro(find_library_extended prefix)
include(CMakeParseArguments REQUIRED)
# cmake_parse_arguments(prefix options singleValueArgs multiValueArgs ${ARGN})
cmake_parse_arguments(${prefix} "" ""
"NAMES;NAMES_DEBUG;NAMES_RELEASE;PATHS_DEBUG;PATHS_RELEASE;PATHS"
${ARGN}
)
# Reloading to ensure build always passes and picks up changes
# This is more expensive but proves useful for fragmented libraries like WebRTC
unset(${prefix}_LIBRARY_DEBUG CACHE)
find_library(${prefix}_LIBRARY_DEBUG
NAMES
${${prefix}_NAMES_DEBUG}
${${prefix}_NAMES}
PATHS
${${prefix}_PATHS_DEBUG}
${${prefix}_PATHS}
)
#if(NOT ${prefix}_PATHS_RELEASE)
# list(APPEND ${prefix}_PATHS_RELEASE ${${prefix}_PATHS})
#endif()
unset(${prefix}_LIBRARY_RELEASE CACHE)
find_library(${prefix}_LIBRARY_RELEASE
NAMES
${${prefix}_NAMES_RELEASE}
${${prefix}_NAMES}
PATHS
${${prefix}_PATHS_RELEASE}
${${prefix}_PATHS}
)
include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake)
select_library_configurations(${prefix})
# print_module_variables(${prefix})
# message("*** Find library for ${prefix}")
# message("Debug Library: ${${prefix}_LIBRARY_DEBUG}")
# message("Release Library: ${${prefix}_LIBRARY_RELEASE}")
# message("Library: ${${prefix}_LIBRARY}")
# message("Debug Paths: ${${prefix}_PATHS_RELEASE}")
# message("Release Paths: ${${prefix}_PATHS_DEBUG}")
# message("Paths: ${${prefix}_PATHS}")
# message("Debug Names: ${${prefix}_NAMES_RELEASE}")
# message("Release Names: ${${prefix}_NAMES_DEBUG}")
# message("Names: ${${prefix}_NAMES}")
endmacro(find_library_extended)
#
### Macro: set_component_alias
#
# Sets the current module component alias variables.
#
macro(set_component_alias module component)
set(ALIAS ${module}_${component})
set(ALIAS_FOUND ${ALIAS}_FOUND)
set(ALIAS_LIBRARIES ${ALIAS}_LIBRARIES)
set(ALIAS_LIBRARY_RELEASE ${ALIAS}_LIBRARY_RELEASE)
set(ALIAS_LIBRARY_DEBUG ${ALIAS}_LIBRARY_DEBUG)
set(ALIAS_INCLUDE_DIRS ${ALIAS}_INCLUDE_DIRS)
set(ALIAS_LIBRARY_DIRS ${ALIAS}_LIBRARY_DIRS)
set(ALIAS_DEFINITIONS ${ALIAS}_CFLAGS_OTHER)
set(ALIAS_VERSION ${ALIAS}_VERSION)
string(TOUPPER ${ALIAS} ALIAS_UPPER)
endmacro()
#
### Macro: set_module_found
#
# Marks the given module as found if all required components are present.
#
macro(set_module_found module)
set(${module}_FOUND FALSE)
# Compile the list of required vars
set(_${module}_REQUIRED_VARS ${module}_LIBRARIES) # ${module}_INCLUDE_DIRS
foreach (component ${${module}_FIND_COMPONENTS})
# NOTE: Not including XXX_INCLUDE_DIRS as required var since it may be empty
list(APPEND _${module}_REQUIRED_VARS ${module}_${component}_LIBRARIES) # ${module}_${component}_INCLUDE_DIRS
if (NOT ${module}_${component}_FOUND)
if (${module}_FIND_REQUIRED)
message(FATAL_ERROR "Required ${module} component ${component} missing. Please recompile ${module} with ${component} enabled.")
endif()
else()
messageV(" - Required ${module} component ${component} found.")
endif()
endforeach()
# Cache the vars.
set(${module}_INCLUDE_DIRS ${${module}_INCLUDE_DIRS} CACHE STRING "The ${module} include directories." FORCE)
set(${module}_LIBRARY_DIRS ${${module}_LIBRARY_DIRS} CACHE STRING "The ${module} library directories." FORCE)
set(${module}_LIBRARIES ${${module}_LIBRARIES} CACHE STRING "The ${module} libraries." FORCE)
set(${module}_FOUND ${${module}_FOUND} CACHE BOOLEAN "The ${module} found status." FORCE)
# Ensure required variables have been set, or fail in error.
# NOTE: Disabling find_package_handle_standard_args check since it's always
# returning false even when variables are set. Maybe an internal CMake issue?
# if (${module}_FIND_REQUIRED)
#
# # Give a nice error message if some of the required vars are missing.
# include(FindPackageHandleStandardArgs)
# find_package_handle_standard_args(${module} DEFAULT_MSG ${_${module}_REQUIRED_VARS})
# endif()
# Set the module as found.
if (${module}_LIBRARIES)
set(${module}_FOUND TRUE)
else()
message(WARNING "Failed to locate ${module}. Please specify paths manually.")
endif()
mark_as_advanced(${module}_INCLUDE_DIRS
${module}_LIBRARY_DIRS
${module}_LIBRARIES
${module}_DEFINITIONS
${module}_FOUND)
endmacro()
#
### Macro: set_component_found
#
# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS are present.
#
macro(set_component_found module component)
set_component_alias(${module} ${component})
messageV("${ALIAS_LIBRARIES}=${${ALIAS_LIBRARIES}}")
messageV("${ALIAS_INCLUDE_DIRS}=${${ALIAS_INCLUDE_DIRS}}")
messageV("${ALIAS_LIBRARY_DIRS}=${${ALIAS_LIBRARY_DIRS}}")
#if (${module}_${component}_LIBRARIES AND ${module}_${component}_INCLUDE_DIRS)
if (${ALIAS_LIBRARIES}) # AND ${ALIAS_INCLUDE_DIRS} (XXX_INCLUDE_DIRS may be empty)
messageV(" - ${module} ${component} found.")
set(${ALIAS_FOUND} TRUE)
# set(${ALIAS_FOUND} TRUE PARENT_SCOPE)
# Add component vars to the parent module lists
append_unique_list(${module}_INCLUDE_DIRS ${ALIAS_INCLUDE_DIRS})
append_unique_list(${module}_LIBRARY_DIRS ${ALIAS_LIBRARY_DIRS})
append_unique_list(${module}_LIBRARIES ${ALIAS_LIBRARIES})
append_unique_list(${module}_DEFINITIONS ${ALIAS_DEFINITIONS})
# set(${module}_INCLUDE_DIRS ${${module}_INCLUDE_DIRS} PARENT_SCOPE)
# set(${module}_LIBRARY_DIRS ${${module}_LIBRARY_DIRS} PARENT_SCOPE)
# set(${module}_LIBRARIES ${${module}_LIBRARIES} PARENT_SCOPE)
# set(${module}_DEFINITIONS ${${module}_DEFINITIONS} PARENT_SCOPE)
# messageV("Find Component Paths=${module}:${component}:${library}:${header}")
# messageV("${ALIAS_INCLUDE_DIRS}=${${ALIAS_INCLUDE_DIRS}}")
# messageV("${ALIAS_LIBRARY_RELEASE}=${${ALIAS_LIBRARY_RELEASE}}")
# messageV("${ALIAS_LIBRARY_DEBUG}=${${ALIAS_LIBRARY_DEBUG}}")
# messageV("${ALIAS_LIBRARIES}=${${ALIAS_LIBRARIES}}")
# messageV("${module}_INCLUDE_DIRS=${${module}_INCLUDE_DIRS}")
# messageV("${module}_LIBRARIES=${${module}_LIBRARIES}")
# Only mark as advanced when found
mark_as_advanced(${ALIAS_INCLUDE_DIRS}
${ALIAS_LIBRARY_DIRS})
else()
# NOTE: an error message will be displayed in set_module_found
# if the module is REQUIRED
messageV(" - ${module} ${component} not found.")
endif()
set(HAVE_${ALIAS} ${${ALIAS_FOUND}})
set(HAVE_${ALIAS_UPPER} ${${ALIAS_FOUND}})
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(HAVE_${ALIAS} ${${ALIAS_FOUND}} PARENT_SCOPE)
set(HAVE_${ALIAS_UPPER} ${${ALIAS_FOUND}} PARENT_SCOPE)
endif()
mark_as_advanced(${ALIAS_FOUND}
${ALIAS_LIBRARY_DEBUG}
${ALIAS_LIBRARY_RELEASE}
${ALIAS_LIBRARIES}
${ALIAS_DEFINITIONS}
${ALIAS_VERSION})
endmacro()
#
### Macro: set_module_notfound
#
# Marks the given component as not found, and resets the cache for find_path and find_library results.
#
macro(set_module_notfound module)
#messageV(" - Setting ${module} not found.")
set(${module}_FOUND FALSE)
#set(${module}_FOUND FALSE PARENT_SCOPE)
if (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
set(${module}_LIBRARY_RELEASE "")
set(${module}_LIBRARY_DEBUG "")
set(${module}_LIBRARIES "")
#set(${module}_LIBRARY_RELEASE "" PARENT_SCOPE)
#set(${module}_LIBRARY_DEBUG "" PARENT_SCOPE)
#set(${module}_LIBRARIES "" PARENT_SCOPE)
else()
set(${module}_LIBRARIES ${ALIAS_LIBRARIES}-NOTFOUND)
#set(${module}_LIBRARIES ${ALIAS_LIBRARIES}-NOTFOUND PARENT_SCOPE)
endif()
endmacro()
#
### Macro: set_component_notfound
#
# Marks the given component as not found, and resets the cache for find_path and find_library results.
#
macro(set_component_notfound module component)
set_component_alias(${module} ${component})
#messageV(" - Setting ${module} ${component} not found.")
set(${ALIAS_FOUND} FALSE)
#set(${ALIAS_FOUND} FALSE PARENT_SCOPE)
set(${ALIAS_INCLUDE_DIRS} ${ALIAS_INCLUDE_DIRS}-NOTFOUND)
if (${module}_MULTI_CONFIGURATION AND (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE))
set(${ALIAS_LIBRARY_RELEASE} ${ALIAS_LIBRARY_RELEASE}-NOTFOUND)
set(${ALIAS_LIBRARY_DEBUG} ${ALIAS_LIBRARY_DEBUG}-NOTFOUND)
set(${ALIAS_LIBRARIES} "") #${module}_${component}_LIBRARIES-NOTFOUND)
#set(${ALIAS_LIBRARY_RELEASE} ${ALIAS_LIBRARY_RELEASE}-NOTFOUND PARENT_SCOPE)
#set(${ALIAS_LIBRARY_DEBUG} ${ALIAS_LIBRARY_DEBUG}-NOTFOUND PARENT_SCOPE)
#set(${ALIAS_LIBRARIES} "") #${module}_${component}_LIBRARIES-NOTFOUND PARENT_SCOPE)
else()
set(${ALIAS_LIBRARIES} ${ALIAS_LIBRARIES}-NOTFOUND)
#set(${ALIAS_LIBRARIES} ${ALIAS_LIBRARIES}-NOTFOUND PARENT_SCOPE)
endif()
endmacro()
#
### Macro: find_component_paths
#
# Finds the given component library and include paths.
#
macro(find_component_paths module component library header)
messageV("Find Component Paths=${module}:${component}:${library}:${header}")
messageV("INCLUDE_DIR: ${${module}_INCLUDE_DIR} HINTS: ${${module}_INCLUDE_HINTS}")
#unset(${ALIAS_LIBRARY} CACHE)
#unset(${ALIAS_LIBRARIES} CACHE)
#unset(${ALIAS_LIBRARY_RELEASE} CACHE)
#unset(${ALIAS_LIBRARY_DEBUG} CACHE)
# Reset alias namespace (force recheck)
#set_component_alias(${module} ${component})
#set_component_notfound(${module} ${component})
find_path(${ALIAS_INCLUDE_DIRS} ${header}
HINTS
${${module}_INCLUDE_HINTS}
PATHS
${${module}_INCLUDE_DIR}
PATH_SUFFIXES
${${module}_INCLUDE_SUFFIXES} # try find from root module include suffixes
)
# Create a Debug and a Release list for multi configuration builds.
# NOTE: <module>_CONFIGURATION_TYPES must be set to use this.
if (${module}_MULTI_CONFIGURATION AND (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE))
find_library(${ALIAS_LIBRARY_RELEASE}
NAMES
${library}
HINTS
${${module}_LIBRARY_HINTS}
PATHS
${${ALIAS_LIBRARY_DIRS}}
${${module}_LIBRARY_DIR}
PATH_SUFFIXES
${${module}_LIBRARY_SUFFIXES}
)
find_library(${ALIAS_LIBRARY_DEBUG}
NAMES
${library}d
HINTS
${${module}_LIBRARY_HINTS}
PATHS
${${ALIAS_LIBRARY_DIRS}}
${${module}_LIBRARY_DIR}
PATH_SUFFIXES
${${module}_LIBRARY_SUFFIXES}
)
if (${ALIAS_LIBRARY_RELEASE})
list(APPEND ${ALIAS_LIBRARIES} optimized ${${ALIAS_LIBRARY_RELEASE}})
endif()
if (${ALIAS_LIBRARY_DEBUG})
list(APPEND ${ALIAS_LIBRARIES} debug ${${ALIAS_LIBRARY_DEBUG}})
endif()
#include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake)
#select_library_configurations(${ALIAS})
# message(STATUS "ALIAS_INCLUDE_DIRS: ${${ALIAS_INCLUDE_DIRS}}")
# message(STATUS "ALIAS_LIBRARY_DEBUG: ${${ALIAS_LIBRARY_DEBUG}}")
# message(STATUS "ALIAS_LIBRARY_RELEASE: ${${ALIAS_LIBRARY_RELEASE}}")
# message(STATUS "ALIAS_LIBRARIES: ${ALIAS_LIBRARIES}: ${${ALIAS_LIBRARIES}}")
# message(STATUS "ALIAS_LIBRARY: ${${ALIAS_LIBRARY}}")
# message(STATUS "ALIAS_LIBRARY_DIRS: ${${ALIAS_LIBRARY_DIRS}}")
# message(STATUS "LIBRARY_HINTS: ${${module}_LIBRARY_DIR}")
# message(STATUS "INCLUDE_DIR: ${${module}_INCLUDE_DIR}")
# message(STATUS "LIBRARY_SUFFIXES: ${${module}_LIBRARY_SUFFIXES}")
else()
find_library(${ALIAS_LIBRARIES}
NAMES
${library}
${library}d
HINTS
${${module}_LIBRARY_HINTS}
PATHS
${${ALIAS_LIBRARY_DIRS}}
${${module}_LIBRARY_DIR}
PATH_SUFFIXES
${${module}_LIBRARY_SUFFIXES}
)
endif()
# print_module_variables(${module})
set_component_found(${module} ${component})
endmacro()
#
### Macro: find_component
#
# Checks for the given component by invoking pkg-config and then looking up the
# libraries and include directories.
#
macro(find_component module component pkgconfig library header)
messageV("Find Component=${module}:${component}:${pkgconfig}:${library}:${header}")
# Reset component alias values (force recheck)
set_component_alias(${module} ${component})
find_component_paths(${module} ${component} ${library} ${header})
if(NOT ${ALIAS_FOUND})
messageV(" - ${module} ${component} not found, searching with pkg-config...")
# Use pkg-config to obtain directories for the find_path() and find_library() calls.
find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_search_module(${ALIAS} ${pkgconfig} QUIET)
messageV("Find Component PkgConfig=${ALIAS}:${${ALIAS}_FOUND}:${${ALIAS}_LIBRARIES}:${${ALIAS}_INCLUDE_DIRS}:${${ALIAS}_LIBRARY_DIRS}:${${ALIAS}_LIBDIR}:${${ALIAS}_INCLUDEDIR}")
endif()
else()
messageV(" - ${module} ${component} found without pkg-config.")
endif()
# messageV("${ALIAS_FOUND}=${${ALIAS_FOUND}}")
# messageV("${ALIAS_LIBRARIES}=${${ALIAS_LIBRARIES}}")
# messageV("${ALIAS_INCLUDE_DIRS}=${${ALIAS_INCLUDE_DIRS}}")
if(${ALIAS_FOUND})
set_component_found(${module} ${component})
endif()
endmacro()

256
cmake/CMakeHelpers.cmake Normal file
View File

@ -0,0 +1,256 @@
#
### Macro: subdirlist
#
# Returns a list of subdirectories.
#
macro(subdirlist result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
set(dirlist ${dirlist} ${child})
endif()
endforeach()
set(${result} ${dirlist})
endmacro()
#
### Macro: join
#
# Joins a string array.
# Example:
# SET( letters "" "\;a" b c "d\;d" )
# JOIN("${letters}" ":" output)
# MESSAGE("${output}") # :;a:b:c:d;d
#
function(JOIN VALUES GLUE OUTPUT)
string (REPLACE ";" "${GLUE}" _TMP_STR "${VALUES}")
set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
endfunction()
#
### Macro: list_length
#
# Example:
# SET(MYLIST hello world foo bar)
# LIST_LENGTH(length ${MYLIST})
# MESSAGE("length: ${length}")
#
macro(LIST_LENGTH var)
set(entries)
foreach(e ${ARGN})
set(entries "${entries}.")
endforeach(e)
string(LENGTH ${entries} ${var})
endmacro()
#
### Function: append_unique_list
#
# Appends items from the source list to the given target list
# if they are not already contained within the target list
# in flattened string form.
#
function(append_unique_list target source)
if (NOT ${source})
return()
endif()
if (NOT ${target})
set(${target} ${${source}} PARENT_SCOPE)
else()
join("${${target}}" ":" target_str)
join("${${source}}" ":" source_str)
if (NOT ${target_str} MATCHES ${source_str})
set(${target} ${${target}} ${${source}} PARENT_SCOPE)
endif()
endif()
endfunction()
#
### Function: filter_list
#
function(filter_list result source regex)
set(items)
foreach(ITR ${source})
if(NOT ITR MATCHES ${regex})
list(APPEND items ${ITR})
endif()
endforeach()
set(${result} ${items} PARENT_SCOPE)
endfunction()
#
### Function: find_existing_directory
#
function(find_existing_directory result)
foreach(dir ${ARGN})
if(EXISTS ${dir})
get_filename_component(dir ${dir} ABSOLUTE)
set(${result} ${dir} PARENT_SCOPE)
return()
endif()
endforeach()
endfunction()
#
### Macro: print_module_variables
#
macro(print_module_variables name)
message(STATUS "${name} Variables:")
message(STATUS "-- Found: ${${name}_FOUND}")
if (${name}_INCLUDE_DIRS)
message(STATUS "-- Include Dirs: ${${name}_INCLUDE_DIRS}")
else()
message(STATUS "-- Include Dir: ${${name}_INCLUDE_DIR}")
endif()
if (${name}_LIBRARIES)
message(STATUS "-- Libraries: ${${name}_LIBRARIES}")
message(STATUS "-- Debug Libraries: ${${name}_LIBRARIES_DEBUG}")
message(STATUS "-- Release Libraries: ${${name}_LIBRARIES_RELEASE}")
else()
message(STATUS "-- Library: ${${name}_LIBRARY}")
message(STATUS "-- Debug Library: ${${name}_LIBRARY_DEBUG}")
message(STATUS "-- Release Library: ${${name}_LIBRARY_RELEASE}")
endif()
message(STATUS "-- Dependencies: ${${name}_DEPENDENCIES}")
# message("Paths: ${${prefix}_PATHS}")
# message("Debug Paths: ${${prefix}_PATHS_RELEASE}")
# message("Release Paths: ${${prefix}_PATHS_DEBUG}")
# message("Debug Names: ${${prefix}_NAMES_RELEASE}")
# message("Release Names: ${${prefix}_NAMES_DEBUG}")
# message("Names: ${${prefix}_NAMES}")
endmacro()
#
### Macro: set_option
#
# Provides an option that the user can optionally select.
# Can accept condition to control when option is available for user.
# Usage:
# option(<option_variable> "help string describing the option" <initial value or boolean expression> [IF <condition>])
#
macro(set_option variable description value)
set(__value ${value})
set(__condition "")
set(__varname "__value")
foreach(arg ${ARGN})
if(arg STREQUAL "IF" OR arg STREQUAL "if")
set(__varname "__condition")
else()
list(APPEND ${__varname} ${arg})
endif()
endforeach()
unset(__varname)
if(__condition STREQUAL "")
set(__condition 2 GREATER 1)
endif()
if(DEFINED ${variable})
# set the default option value from existing value or command line arguments
option(${variable} "${description}" ${${variable}})
else()
# if variable not defined set default from condition
if(${__condition})
if(${__value} MATCHES ";")
if(${__value})
option(${variable} "${description}" ON)
else()
option(${variable} "${description}" OFF)
endif()
elseif(DEFINED ${__value})
if(${__value})
option(${variable} "${description}" ON)
else()
option(${variable} "${description}" OFF)
endif()
else()
option(${variable} "${description}" ${__value})
endif()
else()
unset(${variable} CACHE)
endif()
endif()
unset(__condition)
unset(__value)
endmacro()
#
### Function: status
#
# Status report function.
# Automatically align right column and selects text based on condition.
# Usage:
# status(<text>)
# status(<heading> <value1> [<value2> ...])
# status(<heading> <condition> THEN <text for TRUE> ELSE <text for FALSE> )
#
function(status text)
set(status_cond)
set(status_then)
set(status_else)
set(status_current_name "cond")
foreach(arg ${ARGN})
if(arg STREQUAL "THEN")
set(status_current_name "then")
elseif(arg STREQUAL "ELSE")
set(status_current_name "else")
else()
list(APPEND status_${status_current_name} ${arg})
endif()
endforeach()
if(DEFINED status_cond)
set(status_placeholder_length 32)
string(RANDOM LENGTH ${status_placeholder_length} ALPHABET " " status_placeholder)
string(LENGTH "${text}" status_text_length)
if(status_text_length LESS status_placeholder_length)
string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text)
elseif(DEFINED status_then OR DEFINED status_else)
message(STATUS "${text}")
set(status_text "${status_placeholder}")
else()
set(status_text "${text}")
endif()
if(DEFINED status_then OR DEFINED status_else)
if(${status_cond})
string(REPLACE ";" " " status_then "${status_then}")
string(REGEX REPLACE "^[ \t]+" "" status_then "${status_then}")
message(STATUS "${status_text} ${status_then}")
else()
string(REPLACE ";" " " status_else "${status_else}")
string(REGEX REPLACE "^[ \t]+" "" status_else "${status_else}")
message(STATUS "${status_text} ${status_else}")
endif()
else()
string(REPLACE ";" " " status_cond "${status_cond}")
string(REGEX REPLACE "^[ \t]+" "" status_cond "${status_cond}")
message(STATUS "${status_text} ${status_cond}")
endif()
else()
message(STATUS "${text}")
endif()
endfunction()
#
### Macro: messageV
#
# Prints message only with MSG_VERBOSE=ON
# Usage:
# messageV(<msg>)
#
function(messageV text)
if(${MSG_VERBOSE})
message(STATUS "${text}")
endif()
endfunction()

111
cmake/FindPoco.cmake Normal file
View File

@ -0,0 +1,111 @@
# - Try to find the required Poco components (default: Zip Net NetSSL Crypto Util XML CppParser Foundation)
#
# Once done this will define
# Poco_FOUND - System has the all required components.
# Poco_INCLUDE_DIRS - Include directory necessary for using the required components headers.
# Poco_LIBRARY_DIRS - Library directories necessary for using the required components.
# Poco_LIBRARIES - Link these to use the required components.
# Poco_DEFINITIONS - Compiler switches required for using the required components.
#
# For each of the components it will additionally set.
# - Foundation
# - CppParser
# - CppUnit
# - Net
# - NetSSL
# - Crypto
# - Util
# - XML
# - Zip
# - Data
# - PageCompiler
#
# the following variables will be defined
# Poco_<component>_FOUND - System has <component>
# Poco_<component>_INCLUDE_DIRS - Include directories necessary for using the <component> headers
# Poco_<component>_LIBRARY_DIRS - Library directories necessary for using the <component>
# Poco_<component>_LIBRARIES - Link these to use <component>
# Poco_<component>_DEFINITIONS - Compiler switches required for using <component>
# Poco_<component>_VERSION - The components version
include(CMakeHelpers REQUIRED)
include(CMakeFindExtensions REQUIRED)
# The default components to find
if (NOT Poco_FIND_COMPONENTS)
set(Poco_FIND_COMPONENTS Zip Net NetSSL Crypto Util XML CppParser Foundation)
endif()
# Set required variables
set(Poco_ROOT_DIR "" CACHE STRING "Where is the Poco root directory located?")
set(Poco_INCLUDE_DIR "${Poco_ROOT_DIR}" CACHE STRING "Where are the Poco headers (.h) located?")
set(Poco_LIBRARY_DIR "${Poco_ROOT_DIR}/lib" CACHE STRING "Where are the Poco libraries (.dll/.so) located?")
set(Poco_LINK_SHARED_LIBS FALSE CACHE BOOL "Link with shared Poco libraries (.dll/.so) instead of static ones (.lib/.a)")
#message("Poco_ROOT_DIR=${Poco_ROOT_DIR}")
#message("Poco_INCLUDE_DIR=${Poco_INCLUDE_DIR}")
#message("Poco_LIBRARY_DIR=${Poco_LIBRARY_DIR}")
# Check for cached results. If there are then skip the costly part.
set_module_notfound(Poco)
if (NOT Poco_FOUND)
# Set the library suffix for our build type
set(Poco_LIB_SUFFIX "")
if(WIN32 AND MSVC)
set(Poco_MULTI_CONFIGURATION TRUE)
# add_definitions(-DPOCO_NO_AUTOMATIC_LIBS)
# add_definitions(-DPOCO_NO_UNWINDOWS)
if(Poco_LINK_SHARED_LIBS)
add_definitions(-DPOCO_DLL)
else()
add_definitions(-DPOCO_STATIC)
if(BUILD_WITH_STATIC_CRT)
set(Poco_LIB_SUFFIX "mt")
else()
set(Poco_LIB_SUFFIX "md")
endif()
endif()
endif()
# Set search path suffixes
set(Poco_INCLUDE_SUFFIXES
CppUnit/include
CppParser/include
Data/include
Data/ODBC/include
Foundation/include
Crypto/include
Net/include
NetSSL_OpenSSL/include
PageCompiler/include
Util/include
JSON/include
XML/include
Zip/include
)
set(Poco_LIBRARY_SUFFIXES
Linux/i686
Linux/x86_64
)
# Check for all available components
find_component(Poco CppParser CppParser PocoCppParser${Poco_LIB_SUFFIX} Poco/CppParser/CppParser.h)
find_component(Poco CppUnit CppUnit PocoCppUnit${Poco_LIB_SUFFIX} Poco/CppUnit/CppUnit.h)
find_component(Poco Net Net PocoNet${Poco_LIB_SUFFIX} Poco/Net/Net.h)
find_component(Poco NetSSL NetSSL PocoNetSSL${Poco_LIB_SUFFIX} Poco/Net/NetSSL.h)
find_component(Poco Crypto Crypto PocoCrypto${Poco_LIB_SUFFIX} Poco/Crypto/Crypto.h)
find_component(Poco Util Util PocoUtil${Poco_LIB_SUFFIX} Poco/Util/Util.h)
find_component(Poco JSON JSON PocoJSON${Poco_LIB_SUFFIX} Poco/JSON/JSON.h)
find_component(Poco XML XML PocoXML${Poco_LIB_SUFFIX} Poco/XML/XML.h)
find_component(Poco Zip Zip PocoZip${Poco_LIB_SUFFIX} Poco/Zip/Zip.h)
find_component(Poco Data Data PocoData${Poco_LIB_SUFFIX} Poco/Data/Data.h)
find_component(Poco ODBC ODBC PocoDataODBC${Poco_LIB_SUFFIX} Poco/Data/ODBC/Connector.h)
find_component(Poco PageCompiler PageCompiler PocoPageCompiler${Poco_LIB_SUFFIX} Poco/PageCompiler/PageCompiler.h)
find_component(Poco Foundation Foundation PocoFoundation${Poco_LIB_SUFFIX} Poco/Foundation.h)
# Set Poco as found or not
# print_module_variables(Poco)
set_module_found(Poco)
endif ()

4
cmake/README Normal file
View File

@ -0,0 +1,4 @@
CMake modules copied from:
https://github.com/sourcey/libsourcey