mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
CMake prebuild system: Initial commit that has most of the basics down. Only tested on windows atm. TODO: Properly support examples, tests and cpp11 defines to build websocketpp in different setups.
This commit is contained in:
19
.gitignore
vendored
19
.gitignore
vendored
@@ -14,6 +14,25 @@
|
||||
*.so.?.?.?
|
||||
*.a
|
||||
*.dylib
|
||||
lib/*
|
||||
|
||||
# CMake
|
||||
*.cmake
|
||||
*.dir
|
||||
CMakeFiles
|
||||
INSTALL.*
|
||||
ZERO_CHECK.*
|
||||
CMakeCache.txt
|
||||
install_manifest.txt
|
||||
|
||||
# Windows/Visual Studio
|
||||
*.vcproj*
|
||||
*.sln
|
||||
*.suo
|
||||
*.ncb
|
||||
*/Debug/*
|
||||
*/Release/*
|
||||
*/RelWithDebInfo/*
|
||||
|
||||
objs_shared/
|
||||
objs_static/
|
||||
|
||||
96
CMakeLists.txt
Normal file
96
CMakeLists.txt
Normal file
@@ -0,0 +1,96 @@
|
||||
|
||||
# Project name
|
||||
project (websocketpp)
|
||||
|
||||
# Minimum cmake requirement. We should require a quite recent
|
||||
# cmake for the dependency find macros etc. to be up to date.
|
||||
cmake_minimum_required (VERSION 2.5)
|
||||
|
||||
# Include our cmake macros
|
||||
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} cmake)
|
||||
include (CMakeHelpers)
|
||||
|
||||
# Build customization:
|
||||
# - Override from command line "CMake -D<OPTION>=TRUE/FALSE/0/1". Remove CMakeCache.txt before the run.
|
||||
option (ENABLE_CPP11 "Build websocketpp with CPP11 features enabled." FALSE) # todo
|
||||
option (BUILD_EXAMPLES "Build websocketpp examples." FALSE)
|
||||
option (BUILD_TESTS "Build websocketpp tests." FALSE) # todo
|
||||
|
||||
# Disable unnecessary build types
|
||||
set (CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug" CACHE STRING "Configurations" FORCE)
|
||||
|
||||
# Spesify useful paths
|
||||
set (WEBSOCKETPP_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set (WEBSOCKETPP_BIN ${WEBSOCKETPP_ROOT}/bin)
|
||||
set (WEBSOCKETPP_LIB ${WEBSOCKETPP_ROOT}/lib)
|
||||
set (WEBSOCKETPP_INCLUDE ${WEBSOCKETPP_ROOT}/websocketpp)
|
||||
set (WEBSOCKETPP_PREFIX ${WEBSOCKETPP_ROOT}/build)
|
||||
|
||||
# CMake install step prefix. I assume linux users want the prefix to
|
||||
# be the default usr so this is only adjusted on Windows.
|
||||
# How to invoke:
|
||||
# - Windows: Build the INSTALL project in your solution file.
|
||||
# - Linux/OSX: make install.
|
||||
if (MSVC)
|
||||
set (CMAKE_INSTALL_PREFIX ${WEBSOCKETPP_PREFIX})
|
||||
endif ()
|
||||
|
||||
# Find and configure Boost dependency. You should define BOOST_ROOT environment variable or
|
||||
# pass it to cmake with -DBOOST_ROOT=path. CMake variable BOOST_ROOT can be defined at this stage by -D or from cache.
|
||||
if ("${BOOST_ROOT}" STREQUAL "")
|
||||
file (TO_CMAKE_PATH "$ENV{BOOST_ROOT}" BOOST_ROOT)
|
||||
# Cache BOOST_ROOT for runs that do not define $ENV{BOOST_ROOT}.
|
||||
set (BOOST_ROOT ${BOOST_ROOT} CACHE PATH "BOOST_ROOT dependency path" FORCE)
|
||||
endif ()
|
||||
|
||||
message ("* Configuring Boost")
|
||||
message (STATUS "-- Using BOOST_ROOT")
|
||||
message (STATUS " " ${BOOST_ROOT})
|
||||
|
||||
if (MSVC)
|
||||
set (Boost_USE_MULTITHREADED TRUE)
|
||||
set (Boost_USE_STATIC_LIBS TRUE)
|
||||
else ()
|
||||
set (Boost_USE_MULTITHREADED FALSE)
|
||||
set (Boost_USE_STATIC_LIBS FALSE)
|
||||
endif ()
|
||||
|
||||
set (Boost_FIND_REQUIRED TRUE)
|
||||
set (Boost_FIND_QUIETLY TRUE)
|
||||
set (Boost_DEBUG FALSE)
|
||||
set (Boost_USE_MULTITHREADED TRUE)
|
||||
set (Boost_ADDITIONAL_VERSIONS "1.39.0" "1.40.0" "1.41.0" "1.42.0" "1.43.0" "1.44.0" "1.46.1") # todo: someone who knows better spesify these!
|
||||
|
||||
find_package (Boost 1.39.0 COMPONENTS system thread regex) # todo: What do we need for each platform?
|
||||
|
||||
if (Boost_FOUND)
|
||||
# Boost is a project wide global dependency.
|
||||
include_directories (${Boost_INCLUDE_DIRS})
|
||||
link_directories (${Boost_LIBRARY_DIRS})
|
||||
|
||||
# Pretty print status
|
||||
message (STATUS "-- Include Directories")
|
||||
foreach (include_dir ${Boost_INCLUDE_DIRS})
|
||||
message (STATUS " " ${include_dir})
|
||||
endforeach ()
|
||||
message (STATUS "-- Library Directories")
|
||||
foreach (library_dir ${Boost_LIBRARY_DIRS})
|
||||
message (STATUS " " ${library_dir})
|
||||
endforeach ()
|
||||
message ("")
|
||||
else ()
|
||||
message (FATAL_ERROR "Failed to find required dependency: boost")
|
||||
endif ()
|
||||
|
||||
# Add main library
|
||||
add_subdirectory (websocketpp)
|
||||
|
||||
# Add examples
|
||||
if (BUILD_EXAMPLES)
|
||||
add_subdirectory (examples)
|
||||
endif ()
|
||||
|
||||
# Add tests
|
||||
if (BUILD_TESTS)
|
||||
add_subdirectory (test)
|
||||
endif ()
|
||||
86
cmake/CMakeHelpers.cmake
Normal file
86
cmake/CMakeHelpers.cmake
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
# Lists all subdirectories to the RESULT variable.
|
||||
macro (list_subdirectories RESULT curdir)
|
||||
set (_TEMP_DIRLIST "")
|
||||
file (GLOB children RELATIVE ${curdir} ${curdir}/*)
|
||||
foreach (child ${children})
|
||||
if (IS_DIRECTORY ${curdir}/${child})
|
||||
set (_TEMP_DIRLIST ${_TEMP_DIRLIST} ${child})
|
||||
endif ()
|
||||
endforeach ()
|
||||
set (${RESULT} ${_TEMP_DIRLIST})
|
||||
endmacro ()
|
||||
|
||||
# Initialize target.
|
||||
macro (init_target NAME)
|
||||
set (TARGET_NAME ${NAME})
|
||||
message ("** " ${TARGET_NAME})
|
||||
|
||||
# Include our own module path. This makes #include "x.h"
|
||||
# work in project subfolders to include the main directory headers.
|
||||
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
|
||||
endmacro ()
|
||||
|
||||
macro (build_library TARGET_NAME LIB_TYPE)
|
||||
# STATIC or SHARED
|
||||
set (TARGET_LIB_TYPE ${LIB_TYPE})
|
||||
|
||||
message (STATUS "-- Build Type:")
|
||||
message (STATUS " " ${TARGET_LIB_TYPE} " library")
|
||||
|
||||
add_library (${TARGET_NAME} ${TARGET_LIB_TYPE} ${ARGN})
|
||||
|
||||
if (MSVC)
|
||||
if (${TARGET_LIB_TYPE} STREQUAL "SHARED")
|
||||
set_target_properties (${TARGET_NAME} PROPERTIES LINK_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
|
||||
else ()
|
||||
set_target_properties (${TARGET_NAME} PROPERTIES STATIC_LIBRARY_FLAGS_RELEASE "/LTCG")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (${TARGET_LIB_TYPE} STREQUAL "STATIC")
|
||||
message (STATUS "-- Build Destination:")
|
||||
message (STATUS " " ${WEBSOCKETPP_LIB})
|
||||
set_target_properties (${TARGET_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${WEBSOCKETPP_LIB})
|
||||
endif ()
|
||||
|
||||
set_target_properties (${TARGET_NAME} PROPERTIES DEBUG_POSTFIX d)
|
||||
endmacro (build_library)
|
||||
|
||||
macro (build_executable TARGET_NAME)
|
||||
set (TARGET_LIB_TYPE "EXECUTABLE")
|
||||
add_executable (${TARGET_NAME} ${ARGN})
|
||||
set_target_properties (${TARGET_NAME} PROPERTIES DEBUG_POSTFIX d)
|
||||
endmacro (build_executable)
|
||||
|
||||
macro (final_target)
|
||||
if (${TARGET_LIB_TYPE} STREQUAL "SHARED")
|
||||
install (TARGETS ${TARGET_NAME}
|
||||
LIBRARY DESTINATION "bin" # non DLL platforms shared libs are LIBRARY
|
||||
RUNTIME DESTINATION "bin" # DLL platforms shared libs are RUNTIME
|
||||
ARCHIVE DESTINATION "lib" # DLL platforms static link part of the shared lib are ARCHIVE
|
||||
CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES})
|
||||
endif ()
|
||||
if (${TARGET_LIB_TYPE} STREQUAL "STATIC")
|
||||
install (TARGETS ${TARGET_NAME}
|
||||
ARCHIVE DESTINATION "lib"
|
||||
CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES})
|
||||
endif ()
|
||||
if (${TARGET_LIB_TYPE} STREQUAL "EXECUTABLE")
|
||||
install (TARGETS ${TARGET_NAME}
|
||||
RUNTIME DESTINATION "bin"
|
||||
CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES})
|
||||
endif ()
|
||||
|
||||
# install headers, directly from current source dir and look for subfolders with headers
|
||||
file (GLOB TARGET_INSTALL_HEADERS *.hpp)
|
||||
install (FILES ${TARGET_INSTALL_HEADERS} DESTINATION "include/${TARGET_NAME}")
|
||||
list_subdirectories(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
foreach (SUBDIR ${SUBDIRS})
|
||||
file (GLOB TARGET_INSTALL_HEADERS_SUBDIR ${SUBDIR}/*.hpp)
|
||||
install (FILES ${TARGET_INSTALL_HEADERS_SUBDIR} DESTINATION "include/${TARGET_NAME}/${SUBDIR}")
|
||||
endforeach ()
|
||||
|
||||
# Pretty printing
|
||||
message ("")
|
||||
endmacro (final_target)
|
||||
17
examples/CMakeLists.txt
Normal file
17
examples/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
list_subdirectories(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
foreach (SUBDIR ${SUBDIRS})
|
||||
# Check if this folder has source/header files
|
||||
file (GLOB SOURCE_FILES ${SUBDIR}/*.cpp)
|
||||
file (GLOB HEADER_FILES ${SUBDIR}/*.hpp)
|
||||
list (LENGTH SOURCE_FILES SRC_LEN)
|
||||
list (LENGTH HEADER_FILES H_LEN)
|
||||
if (NOT SRC_LEN EQUAL 0 OR NOT H_LEN EQUAL 0)
|
||||
init_target (${SUBDIR})
|
||||
build_executable (${TARGET_NAME} ${SOURCE_FILES} ${HEADER_FILES})
|
||||
include_directories (${WEBSOCKETPP_ROOT} ${WEBSOCKETPP_INCLUDE})
|
||||
link_directories (${WEBSOCKETPP_LIB})
|
||||
target_link_libraries (${TARGET_NAME} optimized libwebsocketpp debug libwebsocketppd)
|
||||
final_target ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
28
websocketpp/CMakeLists.txt
Normal file
28
websocketpp/CMakeLists.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
init_target (libwebsocketpp)
|
||||
|
||||
# Sources from root dir
|
||||
file (GLOB SOURCE_FILES *.cpp)
|
||||
file (GLOB HEADER_FILES *.hpp)
|
||||
|
||||
# Sources from subdirectories.
|
||||
# todo: Make this generate source groups in visual
|
||||
# studio solutions for a cleaner looking project.
|
||||
list_subdirectories(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
foreach (SUBDIR ${SUBDIRS})
|
||||
file (GLOB SUBDIR_SOURCE_FILES ${SUBDIR}/*.cpp ${SUBDIR}/*.c)
|
||||
file (GLOB SUBDIR_HEADER_FILES ${SUBDIR}/*.hpp ${SUBDIR}/*.h)
|
||||
# Filter out certain files from 3rd party code
|
||||
if (NOT ${SUBDIR} STREQUAL "sha1" AND NOT ${SUBDIR} STREQUAL "md5")
|
||||
set (SOURCE_FILES ${SOURCE_FILES} ${SUBDIR_SOURCE_FILES})
|
||||
endif ()
|
||||
set (HEADER_FILES ${HEADER_FILES} ${SUBDIR_HEADER_FILES})
|
||||
endforeach ()
|
||||
|
||||
# In preparation for building as dynamic lib on windows.
|
||||
# This should probably be supported at some point.
|
||||
# add_definitions (-DWEBSOCKETPP_MODULE_EXPORTS)
|
||||
|
||||
build_library (${TARGET_NAME} STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
||||
|
||||
final_target ()
|
||||
Reference in New Issue
Block a user