2016-06-05 20:30:40 +08:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2016-05-16 04:43:42 +08:00
|
|
|
|
|
|
|
# get directory name
|
|
|
|
get_filename_component(ProjectId ${CMAKE_SOURCE_DIR} NAME)
|
|
|
|
# replace whitespaces with underscores
|
|
|
|
string(REPLACE " " "_" ProjectId ${ProjectId})
|
|
|
|
# set project name
|
|
|
|
project(${ProjectId})
|
|
|
|
|
2016-06-26 00:26:26 +08:00
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
2016-05-25 06:37:14 +08:00
|
|
|
# c++14
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
|
|
|
|
|
|
|
|
# functions
|
|
|
|
|
2016-06-07 05:57:16 +08:00
|
|
|
# prints all included directories
|
2016-05-25 06:37:14 +08:00
|
|
|
function(list_includes)
|
2016-06-07 05:57:16 +08:00
|
|
|
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
PROPERTY INCLUDE_DIRECTORIES)
|
2016-05-25 06:37:14 +08:00
|
|
|
foreach(dir ${dirs})
|
|
|
|
message(STATUS "dir='${dir}'")
|
|
|
|
endforeach()
|
|
|
|
endfunction(list_includes)
|
|
|
|
|
2016-06-07 05:57:16 +08:00
|
|
|
# get file names from list of file paths
|
|
|
|
function(get_file_names file_paths file_names)
|
|
|
|
set(file_names "")
|
|
|
|
foreach(file_path ${file_paths})
|
|
|
|
get_filename_component (file_name ${file_path} NAME_WE)
|
|
|
|
list(APPEND file_names ${file_name})
|
|
|
|
endforeach()
|
|
|
|
set(file_names "${file_names}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2016-05-29 03:18:26 +08:00
|
|
|
# custom targets
|
|
|
|
|
2016-06-03 22:48:23 +08:00
|
|
|
# move test data data to the build directory
|
2016-05-29 03:18:26 +08:00
|
|
|
if (UNIX)
|
2016-06-03 22:48:23 +08:00
|
|
|
set(test_data "tests/data")
|
|
|
|
set(test_data_src "${CMAKE_SOURCE_DIR}/${test_data}")
|
|
|
|
set(test_data_dst "${CMAKE_BINARY_DIR}/${test_data}")
|
2016-05-29 03:18:26 +08:00
|
|
|
add_custom_target (test_data
|
|
|
|
COMMAND rm -rf ${test_data_dst}
|
|
|
|
COMMAND cp -r ${test_data_src} ${test_data_dst}
|
|
|
|
)
|
|
|
|
endif (UNIX)
|
|
|
|
|
2016-05-23 13:51:36 +08:00
|
|
|
# external dependencies
|
|
|
|
|
2016-05-29 03:18:26 +08:00
|
|
|
set(build_include_dir ${CMAKE_BINARY_DIR}/include)
|
|
|
|
set(src_dir ${CMAKE_SOURCE_DIR}/src)
|
|
|
|
set(libs_dir ${CMAKE_SOURCE_DIR}/libs)
|
2016-05-23 13:51:36 +08:00
|
|
|
|
2016-06-26 00:26:26 +08:00
|
|
|
# setup external dependencies
|
2016-05-23 13:51:36 +08:00
|
|
|
|
2016-06-26 00:26:26 +08:00
|
|
|
# !! IMPORTANT !! run ./libs/setup.sh before cmake command
|
|
|
|
# TODO: run from execute_process
|
|
|
|
|
|
|
|
# lemon & lempar
|
|
|
|
set(lemon_dir ${libs_dir}/lemon)
|
|
|
|
# lexertl
|
|
|
|
set(lexertl_dir ${libs_dir}/lexertl)
|
|
|
|
# fmt
|
|
|
|
set(fmt_source_dir ${libs_dir}/fmt)
|
|
|
|
set(fmt_static_lib ${fmt_source_dir}/fmt/libfmt.a)
|
|
|
|
# r3
|
|
|
|
set(r3_source_dir ${libs_dir}/r3)
|
|
|
|
set(r3_static_lib ${r3_source_dir}/.libs/libr3.a)
|
|
|
|
# http-parser
|
|
|
|
set(http_parser_source_dir "${libs_dir}/http-parser")
|
|
|
|
set(http_parser_static_lib ${http_parser_source_dir}/libhttp_parser.a)
|
|
|
|
# libuv
|
|
|
|
set(libuv_source_dir ${libs_dir}/libuv)
|
|
|
|
set(libuv_static_lib ${libuv_source_dir}/.libs/libuv.a)
|
|
|
|
# rapidjson (C++ JSON encoder/decoder)
|
|
|
|
set(rapidjson_source_dir "${libs_dir}/rapidjson")
|
|
|
|
# Catch (C++ Automated Test Cases in Headers)
|
|
|
|
set(catch_source_dir "${libs_dir}/Catch")
|
2016-05-23 13:51:36 +08:00
|
|
|
|
2016-05-25 06:37:14 +08:00
|
|
|
# build memgraph's cypher grammar
|
2016-05-29 03:18:26 +08:00
|
|
|
# copy grammar file to the build directory
|
2016-05-25 06:37:14 +08:00
|
|
|
FILE(COPY ${src_dir}/cypher/cypher.y DESTINATION ${CMAKE_BINARY_DIR})
|
2016-05-29 03:18:26 +08:00
|
|
|
# build cypher parser (only c file - cypher.c)
|
2016-05-23 13:51:36 +08:00
|
|
|
EXECUTE_PROCESS(
|
|
|
|
COMMAND ${lemon_dir}/lemon ${CMAKE_BINARY_DIR}/cypher.y -s
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
|
|
)
|
2016-05-29 03:18:26 +08:00
|
|
|
# change cypher parser c extension to cpp (cypher.c -> cypher.cpp)
|
2016-05-23 13:51:36 +08:00
|
|
|
FILE(RENAME ${CMAKE_BINARY_DIR}/cypher.c ${CMAKE_BINARY_DIR}/cypher.cpp)
|
2016-05-29 03:18:26 +08:00
|
|
|
# add include file (cypher.h) to build include dir
|
|
|
|
SET(cypher_build_include_dir ${build_include_dir}/cypher)
|
|
|
|
FILE(MAKE_DIRECTORY ${cypher_build_include_dir})
|
|
|
|
FILE(RENAME ${CMAKE_BINARY_DIR}/cypher.h ${cypher_build_include_dir}/cypher.h)
|
2016-05-23 13:51:36 +08:00
|
|
|
|
2016-05-16 04:43:42 +08:00
|
|
|
# compiler options
|
|
|
|
SET(COMPILE_OPTIONS "-O0 -g3 -Wall -Werror -fmessage-length=0")
|
|
|
|
|
|
|
|
# add all cpp file recursive into sourceFiles varibale
|
2016-06-26 00:26:26 +08:00
|
|
|
# FILE(GLOB_RECURSE sourceFiles ${src_dir}/*.cpp)
|
2016-05-16 04:43:42 +08:00
|
|
|
# print list of source files
|
|
|
|
# MESSAGE(STATUS "All source files are: ${sourceFiles}")
|
|
|
|
|
2016-06-15 06:06:21 +08:00
|
|
|
# defines
|
|
|
|
option(RUNTIME_ASSERT "Enable runtime assertions" OFF)
|
|
|
|
if(RUNTIME_ASSERT)
|
|
|
|
add_definitions( -DRUNTIME_ASSERT_ON )
|
|
|
|
endif()
|
|
|
|
|
|
|
|
option(THROW_EXCEPTION_ON_ERROR "Throw exception on error" OFF)
|
|
|
|
if(THROW_EXCEPTION_ON_ERROR)
|
|
|
|
add_definitions( -DTHROW_EXCEPTION_ON_ERROR )
|
|
|
|
endif()
|
|
|
|
|
|
|
|
option(NDEBUG "No debug" OFF)
|
|
|
|
if(NDEBUG)
|
|
|
|
add_definitions( -DNDEBUG )
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# includes
|
2016-05-25 06:37:14 +08:00
|
|
|
include_directories(${src_dir})
|
2016-05-29 03:18:26 +08:00
|
|
|
include_directories(${build_include_dir})
|
2016-06-26 00:26:26 +08:00
|
|
|
include_directories(${fmt_source_dir})
|
|
|
|
include_directories(${http_parser_source_dir})
|
|
|
|
include_directories(${lexertl_dir})
|
|
|
|
include_directories(${libuv_source_dir}/include)
|
|
|
|
include_directories(${rapidjson_source_dir}/include)
|
|
|
|
include_directories(${r3_source_dir}/include)
|
2016-05-25 06:37:14 +08:00
|
|
|
|
2016-05-29 03:18:26 +08:00
|
|
|
# creates build/libcypher_lib.a
|
|
|
|
add_library(cypher_lib STATIC ${CMAKE_BINARY_DIR}/cypher.cpp)
|
2016-05-25 06:37:14 +08:00
|
|
|
|
2016-06-15 06:06:21 +08:00
|
|
|
# tests
|
2016-05-25 06:37:14 +08:00
|
|
|
enable_testing()
|
|
|
|
add_subdirectory(tests)
|
2016-06-26 00:26:26 +08:00
|
|
|
|
|
|
|
EXECUTE_PROCESS(
|
|
|
|
COMMAND python link_resources.py
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/api
|
|
|
|
)
|
|
|
|
|
|
|
|
# add main executable
|
|
|
|
add_executable(memgraph src/memgraph.cpp)
|
2016-06-26 19:27:26 +08:00
|
|
|
add_dependencies(memgraph cypher_lib)
|
2016-06-26 00:26:26 +08:00
|
|
|
|
|
|
|
# link libraries
|
|
|
|
target_link_libraries(memgraph Threads::Threads)
|
|
|
|
target_link_libraries(memgraph pcre)
|
|
|
|
target_link_libraries(memgraph ${libuv_static_lib})
|
|
|
|
target_link_libraries(memgraph ${r3_static_lib})
|
|
|
|
target_link_libraries(memgraph ${http_parser_static_lib})
|