Commit 631ce6f5 authored by Philipp Götze's avatar Philipp Götze
Browse files

🔨 Changed build system

parent 6f717551
# We download some 3rdparty modules from github.com via DownloadProject
include(DownloadProject)
set(THIRD_PARTY_DIR "${PROJECT_BINARY_DIR}/3rdparty")
#--------------------------------------------------------------------------------
# the Catch framework for testing
download_project(PROJ Catch
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG master
UPDATE_DISCONNECTED 1
QUIET
)
add_custom_command(
OUTPUT ${THIRD_PARTY_DIR}/catch
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${Catch_SOURCE_DIR}/single_include/catch2/catch.hpp
${PROJECT_SOURCE_DIR}/test)
add_custom_target(catch_target DEPENDS ${THIRD_PARTY_DIR}/catch)
#--------------------------------------------------------------------------------
# the format library
download_project(PROJ Format
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG master
UPDATE_DISCONNECTED 1
QUIET
)
add_custom_command(
OUTPUT ${THIRD_PARTY_DIR}/fmt
COMMAND ${CMAKE_COMMAND} -E make_directory ${THIRD_PARTY_DIR}/fmt
COMMAND ${CMAKE_COMMAND} -E copy
${Format_SOURCE_DIR}/include/fmt/format.h
${THIRD_PARTY_DIR}/fmt
COMMAND ${CMAKE_COMMAND} -E copy
${Format_SOURCE_DIR}/include/fmt/format-inl.h
${THIRD_PARTY_DIR}/fmt
COMMAND ${CMAKE_COMMAND} -E copy
${Format_SOURCE_DIR}/include/fmt/core.h
${THIRD_PARTY_DIR}/fmt)
add_custom_target(fmt_target DEPENDS ${THIRD_PARTY_DIR}/fmt)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFMT_HEADER_ONLY=1")
include_directories("${THIRD_PARTY_DIR}/fmt")
#--------------------------------------------------------------------------------
if (BUILD_GOOGLE_BENCH)
# Google Benchmark framework
download_project(PROJ benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG master
UPDATE_DISCONNECTED 1
QUIET
)
download_project(PROJ googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
UPDATE_DISCONNECTED 1
QUIET
)
add_custom_command(
OUTPUT ${THIRD_PARTY_DIR}/benchmark
COMMAND ${CMAKE_COMMAND} -E copy_directory
${googletest_SOURCE_DIR}
${benchmark_SOURCE_DIR}/googletest
COMMAND ${CMAKE_COMMAND} -E chdir ${benchmark_SOURCE_DIR} cmake -DCMAKE_BUILD_TYPE=Release
COMMAND ${CMAKE_COMMAND} -E chdir ${benchmark_SOURCE_DIR} $(MAKE)
COMMAND ${CMAKE_COMMAND} -E make_directory ${THIRD_PARTY_DIR}/benchmark/include
COMMAND ${CMAKE_COMMAND} -E make_directory ${THIRD_PARTY_DIR}/benchmark/lib
COMMAND ${CMAKE_COMMAND} -E copy_directory
${benchmark_SOURCE_DIR}/include
${THIRD_PARTY_DIR}/benchmark/include
COMMAND ${CMAKE_COMMAND} -E copy
${benchmark_SOURCE_DIR}/src/libbenchmark.a
${THIRD_PARTY_DIR}/benchmark/lib
)
add_custom_target(benchmark_target DEPENDS ${THIRD_PARTY_DIR}/benchmark)
endif()
#--------------------------------------------------------------------------------
# Peristent Memory Development Kit (pmem.io)
download_project(PROJ pmdk
GIT_REPOSITORY https://github.com/pmem/pmdk.git
GIT_TAG master
UPDATE_DISCONNECTED 1
QUIET
)
add_custom_command(
OUTPUT ${THIRD_PARTY_DIR}/pmdk
COMMAND ${CMAKE_COMMAND} -E chdir ${pmdk_SOURCE_DIR} $(MAKE)
COMMAND ${CMAKE_COMMAND} -E chdir ${pmdk_SOURCE_DIR} $(MAKE) install prefix=${THIRD_PARTY_DIR}/pmdk
)
###
download_project(PROJ pmdk-cpp
GIT_REPOSITORY https://github.com/pmem/libpmemobj-cpp
GIT_TAG master
UPDATE_DISCONNECTED 1
QUIET
)
add_custom_command(
OUTPUT ${THIRD_PARTY_DIR}/pmdk-cpp
COMMAND ${CMAKE_COMMAND} -E copy_directory
${pmdk-cpp_SOURCE_DIR}/include
${THIRD_PARTY_DIR}/pmdk/include
)
add_custom_target(pmdk_target DEPENDS ${THIRD_PARTY_DIR}/pmdk ${THIRD_PARTY_DIR}/pmdk-cpp)
cmake_minimum_required(VERSION 2.8.2)
project(${DL_ARGS_PROJ}-download NONE)
include(ExternalProject)
ExternalProject_Add(${DL_ARGS_PROJ}-download
${DL_ARGS_UNPARSED_ARGUMENTS}
SOURCE_DIR "${DL_ARGS_SOURCE_DIR}"
BINARY_DIR "${DL_ARGS_BINARY_DIR}"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
# MODULE: DownloadProject (from https://github.com/Crascit/DownloadProject)
#
# PROVIDES:
# download_project( PROJ projectName
# [PREFIX prefixDir]
# [DOWNLOAD_DIR downloadDir]
# [SOURCE_DIR srcDir]
# [BINARY_DIR binDir]
# [QUIET]
# ...
# )
#
# Provides the ability to download and unpack a tarball, zip file, git repository,
# etc. at configure time (i.e. when the cmake command is run). How the downloaded
# and unpacked contents are used is up to the caller, but the motivating case is
# to download source code which can then be included directly in the build with
# add_subdirectory() after the call to download_project(). Source and build
# directories are set up with this in mind.
#
# The PROJ argument is required. The projectName value will be used to construct
# the following variables upon exit (obviously replace projectName with its actual
# value):
#
# projectName_SOURCE_DIR
# projectName_BINARY_DIR
#
# The SOURCE_DIR and BINARY_DIR arguments are optional and would not typically
# need to be provided. They can be specified if you want the downloaded source
# and build directories to be located in a specific place. The contents of
# projectName_SOURCE_DIR and projectName_BINARY_DIR will be populated with the
# locations used whether you provide SOURCE_DIR/BINARY_DIR or not.
#
# The DOWNLOAD_DIR argument does not normally need to be set. It controls the
# location of the temporary CMake build used to perform the download.
#
# The PREFIX argument can be provided to change the base location of the default
# values of DOWNLOAD_DIR, SOURCE_DIR and BINARY_DIR. If all of those three arguments
# are provided, then PREFIX will have no effect. The default value for PREFIX is
# CMAKE_BINARY_DIR.
#
# The QUIET option can be given if you do not want to show the output associated
# with downloading the specified project.
#
# In addition to the above, any other options are passed through unmodified to
# ExternalProject_Add() to perform the actual download, patch and update steps.
# The following ExternalProject_Add() options are explicitly prohibited (they
# are reserved for use by the download_project() command):
#
# CONFIGURE_COMMAND
# BUILD_COMMAND
# INSTALL_COMMAND
# TEST_COMMAND
#
# Only those ExternalProject_Add() arguments which relate to downloading, patching
# and updating of the project sources are intended to be used. Also note that at
# least one set of download-related arguments are required.
#
# If using CMake 3.2 or later, the UPDATE_DISCONNECTED option can be used to
# prevent a check at the remote end for changes every time CMake is run
# after the first successful download. See the documentation of the ExternalProject
# module for more information. It is likely you will want to use this option if it
# is available to you.
#
# EXAMPLE USAGE:
#
# include(download_project.cmake)
# download_project(PROJ googletest
# GIT_REPOSITORY https://github.com/google/googletest.git
# GIT_TAG master
# UPDATE_DISCONNECTED 1
# QUIET
# )
#
# add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
#
#========================================================================================
set(_DownloadProjectDir "${CMAKE_CURRENT_LIST_DIR}")
include(CMakeParseArguments)
function(download_project)
set(options QUIET)
set(oneValueArgs
PROJ
PREFIX
DOWNLOAD_DIR
SOURCE_DIR
BINARY_DIR
# Prevent the following from being passed through
CONFIGURE_COMMAND
BUILD_COMMAND
INSTALL_COMMAND
TEST_COMMAND
)
set(multiValueArgs "")
cmake_parse_arguments(DL_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Hide output if requested
if (DL_ARGS_QUIET)
set(OUTPUT_QUIET "OUTPUT_QUIET")
else()
unset(OUTPUT_QUIET)
message(STATUS "Downloading/updating ${DL_ARGS_PROJ}")
endif()
# Set up where we will put our temporary CMakeLists.txt file and also
# the base point below which the default source and binary dirs will be
if (NOT DL_ARGS_PREFIX)
set(DL_ARGS_PREFIX "${CMAKE_BINARY_DIR}")
endif()
if (NOT DL_ARGS_DOWNLOAD_DIR)
set(DL_ARGS_DOWNLOAD_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-download")
endif()
# Ensure the caller can know where to find the source and build directories
if (NOT DL_ARGS_SOURCE_DIR)
set(DL_ARGS_SOURCE_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-src")
endif()
if (NOT DL_ARGS_BINARY_DIR)
set(DL_ARGS_BINARY_DIR "${DL_ARGS_PREFIX}/${DL_ARGS_PROJ}-build")
endif()
set(${DL_ARGS_PROJ}_SOURCE_DIR "${DL_ARGS_SOURCE_DIR}" PARENT_SCOPE)
set(${DL_ARGS_PROJ}_BINARY_DIR "${DL_ARGS_BINARY_DIR}" PARENT_SCOPE)
# Create and build a separate CMake project to carry out the download.
# If we've already previously done these steps, they will not cause
# anything to be updated, so extra rebuilds of the project won't occur.
configure_file("${_DownloadProjectDir}/DownloadProject.CMakeLists.cmake.in"
"${DL_ARGS_DOWNLOAD_DIR}/CMakeLists.txt")
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
${OUTPUT_QUIET}
WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}"
)
execute_process(COMMAND ${CMAKE_COMMAND} --build .
${OUTPUT_QUIET}
WORKING_DIRECTORY "${DL_ARGS_DOWNLOAD_DIR}"
)
endfunction()
message("===== Fetching 3rd Party Dependencies ================================")
include(FetchContent REQUIRED)
find_package(PkgConfig REQUIRED)
set(THIRD_PARTY_DIR "${PROJECT_BINARY_DIR}/_deps")
# Searching for PMDK ======================================================== #
message(STATUS "Searching for PMDK")
pkg_check_modules(PMDK QUIET REQUIRED libpmemobj>=1.5)
mark_as_advanced(PMDK_LIBRARIES PMDK_INCLUDE_DIRS)
# Format ==================================================================== #
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 5.3.0
)
FetchContent_GetProperties(fmt)
if(NOT fmt_POPULATED)
message(STATUS "Populating fmt (Format)")
FetchContent_Populate(fmt)
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
if(BUILD_TEST_CASES)
# Catch =================================================================== #
FetchContent_Declare(
catch
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.9.1
)
FetchContent_GetProperties(catch)
if(NOT catch_POPULATED)
message(STATUS "Populating catch")
FetchContent_Populate(catch)
set(CATCH_INCLUDE_DIR ${catch_SOURCE_DIR}/single_include/catch2)
add_library(Catch2::Catch IMPORTED INTERFACE)
set_property(TARGET Catch2::Catch PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CATCH_INCLUDE_DIR}")
endif()
endif()
if(BUILD_BENCHMARKS)
# Google Test ============================================================= #
#[[
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
message(STATUS "Populating googletest")
FetchContent_Populate(googletest)
# add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
]]
# Google Benchmark ======================================================== #
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.5.0
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(benchmark)
if(NOT benchmark_POPULATED)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
message(STATUS "Populating benchmark (google)")
FetchContent_Populate(benchmark)
add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif()
message("===== Finished fetching 3rd Party Dependencies =======================")
......@@ -17,8 +17,7 @@ macro( build_bench path)
string(REGEX REPLACE ".*/([a-zA-Z0-9_]+)$" "\\1" name "${path}")
include_directories(${TEST_INCLUDE_DIRS})
add_executable( ${name} "${path}.cpp")
add_dependencies(${name} benchmark_target)
set(DEPS nvmDS_deps ${BENCHMARK_LIB})
set(DEPS nvmDS_deps benchmark)
if (${ARGC} GREATER 1) # extra dependencies
set(DEPS ${DEPS} ${ARGV1})
endif()
......@@ -46,7 +45,8 @@ macro (do_bench path)
string(REGEX REPLACE ".*/([a-zA-Z0-9_]+)$" "\\1" name "${path}")
add_test(
NAME ${name}
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${path}"
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/${name}"
--benchmark_min_time=0.01
)
if (${ARGC} GREATER 1) # extra dependencies
build_bench( ${path} ${ARGV1})
......@@ -54,7 +54,3 @@ macro (do_bench path)
build_bench( ${path})
endif()
endmacro(do_bench)
set (CTEST_ENVIRONMENT
"DYLD_FALLBACK_LIBRARY_PATH=${DYLD_LIBRARY_PATH}"
)
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project (nvm-DS)
################################################################################
......@@ -44,21 +44,14 @@ endif()
# show used compiler
message("Using Compiler: ${CMAKE_CXX_COMPILER_ID}.")
set(CMAKE_MACOSX_RPATH 1)
# Add our CMake directory to CMake's module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/")
# We download some 3rdparty modules from github.com before building the project.
include(Download3rdParty)
# We fetch some 3rdparty modules from github.com before building the project.
include(Fetch3rdParty)
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
set(DYLIB_LIBRARY "-ldl")
else()
set(DYLIB_LIBRARY "")
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
############################
# Google benchmark library #
......@@ -70,32 +63,22 @@ if (BUILD_GOOGLE_BENCH)
set (BENCHMARK_LIB "${THIRD_PARTY_DIR}/benchmark/lib/libbenchmark.a")
endif()
#####################################
# Persistent Memory Development Kit #
#####################################
#
set (PMDK_LIBRARIES
${THIRD_PARTY_DIR}/pmdk/lib/libpmemblk.a
${THIRD_PARTY_DIR}/pmdk/lib/libpmemlog.a
${THIRD_PARTY_DIR}/pmdk/lib/libpmemobj.a
${THIRD_PARTY_DIR}/pmdk/lib/libpmempool.a
${THIRD_PARTY_DIR}/pmdk/lib/libpmem.a
${DYLIB_LIBRARY}
)
#################################
# Pre-built common dependencies #
#################################
#
configure_file(config.h.in ${CMAKE_BINARY_DIR}/generated/config.h)
configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/config.h)
include_directories(${PROJECT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/generated
${THIRD_PARTY_DIR}
${THIRD_PARTY_DIR}/pmdk/include)
add_library(nvmDS_deps STATIC ${THIRD_PARTY_DIR}/pmdk)
add_dependencies(nvmDS_deps fmt_target catch_target pmdk_target) #< executes custom commands
target_link_libraries(nvmDS_deps ${PMDK_LIBRARIES} stdc++fs ndctl daxctl)
${CMAKE_CURRENT_BINARY_DIR}/generated
)
add_library(nvmDS_deps STATIC ${PMDK_INCLUDE_DIRS})
target_link_libraries(nvmDS_deps
Threads::Threads
stdc++fs
${PMDK_LIBRARIES} ndctl daxctl
fmt
)
set_target_properties(nvmDS_deps PROPERTIES LINKER_LANGUAGE CXX)
#################
......@@ -104,9 +87,9 @@ set_target_properties(nvmDS_deps PROPERTIES LINKER_LANGUAGE CXX)
#
#set(PROJECT_LIBS ${PROJECT_LIBS})
set(PROJECT_INCLUDES_D ${PROJECT_INCLUDES_D}
${CMAKE_CURRENT_SOURCE_DIR}/utils)
${CMAKE_CURRENT_SOURCE_DIR}/utils)
set(PROJECT_INCLUDES_F ${PROJECT_INCLUDES_F}
${CMAKE_BINARY_DIR}/generated/config.h)
${CMAKE_CURRENT_BINARY_DIR}/generated/config.h)
set(PROJECT_LIB_DIR ${PROJECT_INSTALL_DIR}/lib)
set(PROJECT_INCLUDE_DIR ${PROJECT_INSTALL_DIR}/include)
......@@ -124,16 +107,18 @@ add_subdirectory(ptable) # BDCC-based analytical table structure
# Unit test using Catch #
#########################
#
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE test)
enable_testing()
add_subdirectory(test)
if(BUILD_TEST_CASES)
enable_testing()
add_subdirectory(test)
endif()
#############################################
# Micro-benchmarking using Google Benchmark #
#############################################
#
add_subdirectory(bench)
if(BUILD_BENCHMARKS)
add_subdirectory(bench)
endif()
###################
# Install Process #
......
......@@ -4,23 +4,24 @@ include(../../cmake/Testing.cmake.in)
# define the test data directory for the input and output
#add_definitions(-DTEST_DATA_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}/test_data/")
if (BUILD_TEST_CASES)
add_library(MainTest OBJECT MainTest.cpp)
# PBPTree
do_test(PBPTreeTest)
do_test(UnsortedPBPTreeTest)
do_test(BitPBPTreeTest)
# FPTree
do_test(PTreeTest)
do_test(FPTreeTest)
# wBPTree
do_test(wBPTreeTest)
do_test(wHBPTreeTest)
# PTable
do_test(VTableInfoTest ptable)
do_test(BDCCInfoTest ptable)
do_test(DataNodeTest ptable)
do_test(PTableInfoTest ptable)
do_test(PTupleTest ptable)
do_test(PTableTest ptable)
endif ()
include_directories(${CATCH_INCLUDE_DIR})
add_library(MainTest OBJECT MainTest.cpp)
target_link_libraries(MainTest INTERFACE Catch2::Catch)
# PBPTree
do_test(PBPTreeTest)
do_test(UnsortedPBPTreeTest)
do_test(BitPBPTreeTest)
# FPTree
do_test(PTreeTest)
do_test(FPTreeTest)
# wBPTree
do_test(wBPTreeTest)
do_test(wHBPTreeTest)
# PTable
do_test(VTableInfoTest ptable)
do_test(BDCCInfoTest ptable)
do_test(DataNodeTest ptable)
do_test(PTableInfoTest ptable)
do_test(PTupleTest ptable)
do_test(PTableTest ptable)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment