Adding cmake
This commit is contained in:
parent
41b916e97f
commit
3b24ba9043
|
@ -0,0 +1,33 @@
|
|||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
|
||||
set(CMAKE_MACOSX_RPATH OFF)
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
message(STATUS "No build type selected, default to Release")
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
||||
endif()
|
||||
|
||||
project(simdjson)
|
||||
set(SIMDJSON_LIB_NAME simdjson)
|
||||
|
||||
|
||||
option(SIMDJSON_BUILD_STATIC "Build a static library" OFF) # turning it on disables the production of a dynamic library
|
||||
option(SIMDJSON_BUILD_LTO "Build library with Link Time Optimization" OFF)
|
||||
option(SIMDJSON_SANITIZE "Sanitize addresses" OFF)
|
||||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
|
||||
|
||||
find_package(CTargets)
|
||||
find_package(Options)
|
||||
find_package(LTO)
|
||||
|
||||
install(DIRECTORY include/${SIMDJSON_LIB_NAME} DESTINATION include)
|
||||
set (TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/jsonchecker/")
|
||||
set (BENCHMARK_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/jsonexamples/")
|
||||
add_definitions(-DSIMDJSON_TEST_DATA_DIR="${TEST_DATA_DIR}")
|
||||
add_definitions(-DSIMDJSON_BENCHMARK_DATA_DIR="${TEST_DATA_DIR}")
|
||||
enable_testing()
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(tools)
|
||||
add_subdirectory(tests)
|
||||
add_subdirectory(benchmark)
|
|
@ -0,0 +1,10 @@
|
|||
target_include_directories(${SIMDJSON_LIB_NAME}
|
||||
PUBLIC ${PROJECT_SOURCE_DIR}/benchmark
|
||||
)
|
||||
|
||||
target_include_directories(${SIMDJSON_LIB_NAME}
|
||||
PUBLIC ${PROJECT_SOURCE_DIR}/benchmark/linux
|
||||
)
|
||||
|
||||
add_cpp_benchmark(parse)
|
||||
add_cpp_benchmark(statisticalmodel)
|
|
@ -0,0 +1,47 @@
|
|||
if(${CMAKE_C_COMPILER_ID} MATCHES "Intel") # icc / icpc
|
||||
# prevent shared libraries from depending on Intel provided libraries
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel")
|
||||
endif()
|
||||
|
||||
|
||||
# we default on a shared library.
|
||||
if(SIMDJSON_BUILD_STATIC)
|
||||
set(SIMDJSON_LIB_TYPE STATIC)
|
||||
MESSAGE( STATUS "Building a static library." )
|
||||
else()
|
||||
MESSAGE( STATUS "Building a dynamic library (default)." )
|
||||
set(SIMDJSON_LIB_TYPE SHARED)
|
||||
endif()
|
||||
|
||||
MESSAGE( STATUS "SIMDJSON_LIB_TYPE: " ${SIMDJSON_LIB_TYPE})
|
||||
set(SIMDJSON_SRC
|
||||
jsonioutil.cpp
|
||||
jsonminifier.cpp
|
||||
jsonparser.cpp
|
||||
stage1_find_marks.cpp
|
||||
stage2_flatten.cpp
|
||||
stage34_unified.cpp)
|
||||
|
||||
add_library(${SIMDJSON_LIB_NAME} ${SIMDJSON_LIB_TYPE} ${SIMDJSON_SRC})
|
||||
target_include_directories(${SIMDJSON_LIB_NAME}
|
||||
PUBLIC ${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
install(TARGETS ${SIMDJSON_LIB_NAME} DESTINATION lib)
|
||||
|
||||
if(NOT MSVC)
|
||||
## We output the library at the root of the current directory where cmake is invoked
|
||||
## This is handy but Visual Studio will happily ignore us
|
||||
set_target_properties(${SIMDJSON_LIB_NAME} PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
MESSAGE( STATUS "Library output directory (does not apply to Visual Studio): " ${CMAKE_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
if(MSVC AND (SIMDJSON_LIB_TYPE STREQUAL "SHARED"))
|
||||
if (CMAKE_VERSION VERSION_LESS 3.4)
|
||||
MESSAGE( STATUS "To build a Windows DLL using Visual Studio, you may need cmake 3.4 or better." )
|
||||
endif()
|
||||
MESSAGE( STATUS "Building a Windows DLL using Visual Studio, exporting all symbols automatically." )
|
||||
set_target_properties(${SIMDJSON_LIB_NAME}
|
||||
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
|
||||
endif()
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
add_cpp_test(jsoncheck)
|
||||
add_test(jsoncheck jsoncheck)
|
|
@ -29,7 +29,6 @@ bool contains(const char *pre, const char *str) {
|
|||
|
||||
bool validate(const char *dirname) {
|
||||
bool everythingfine = true;
|
||||
// init_state_machine(); // no longer necessary
|
||||
const char *extension = ".json";
|
||||
size_t dirlen = strlen(dirname);
|
||||
struct dirent **entry_list;
|
||||
|
@ -117,10 +116,17 @@ int main(int argc, char *argv[]) {
|
|||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " <directorywithjsonfiles>"
|
||||
<< std::endl;
|
||||
#ifndef SIMDJSON_TEST_DATA_DIR
|
||||
std::cout
|
||||
<< "We are going to assume you mean to use the 'jsonchecker' directory."
|
||||
<< std::endl;
|
||||
return validate("jsonchecker/") ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
#else
|
||||
std::cout
|
||||
<< "We are going to assume you mean to use the '"<< SIMDJSON_TEST_DATA_DIR <<"' directory."
|
||||
<< std::endl;
|
||||
return validate(SIMDJSON_TEST_DATA_DIR) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
#endif
|
||||
}
|
||||
return validate(argv[1]) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
@ -173,11 +173,19 @@ int main(int argc, char *argv[]) {
|
|||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " <directorywithjsonfiles>"
|
||||
<< std::endl;
|
||||
#if defined(SIMDJSON_TEST_DATA_DIR) && defined(SIMDJSON_BENCHMARK_DATA_DIR)
|
||||
std::cout
|
||||
<< "We are going to assume you mean to use the '"<< SIMDJSON_TEST_DATA_DIR <<"' and '"<< SIMDJSON_BENCHMARK_DATA_DIR <<"'directories."
|
||||
<< std::endl;
|
||||
return validate(SIMDJSON_TEST_DATA_DIR) && validate(SIMDJSON_BENCHMARK_DATA_DIR) ? EXIT_SUCCESS
|
||||
: EXIT_FAILURE;
|
||||
#else
|
||||
std::cout << "We are going to assume you mean to use the 'jsonchecker' and "
|
||||
"'jsonexamples' directories."
|
||||
<< std::endl;
|
||||
return validate("jsonchecker/") && validate("jsonexamples/") ? EXIT_SUCCESS
|
||||
: EXIT_FAILURE;
|
||||
#endif
|
||||
}
|
||||
return validate(argv[1]) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
|
||||
#ifndef JSON_TEST_STRINGS
|
||||
#define JSON_TEST_STRINGS
|
||||
|
@ -381,11 +382,19 @@ int main(int argc, char *argv[]) {
|
|||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " <directorywithjsonfiles>"
|
||||
<< std::endl;
|
||||
#if defined(SIMDJSON_TEST_DATA_DIR) && defined(SIMDJSON_BENCHMARK_DATA_DIR)
|
||||
std::cout
|
||||
<< "We are going to assume you mean to use the '"<< SIMDJSON_TEST_DATA_DIR <<"' and '"<< SIMDJSON_BENCHMARK_DATA_DIR <<"'directories."
|
||||
<< std::endl;
|
||||
return validate(SIMDJSON_TEST_DATA_DIR) && validate(SIMDJSON_BENCHMARK_DATA_DIR) ? EXIT_SUCCESS
|
||||
: EXIT_FAILURE;
|
||||
#else
|
||||
std::cout << "We are going to assume you mean to use the 'jsonchecker' and "
|
||||
"'jsonexamples' directories."
|
||||
<< std::endl;
|
||||
return validate("jsonchecker/") && validate("jsonexamples/") ? EXIT_SUCCESS
|
||||
: EXIT_FAILURE;
|
||||
#endif
|
||||
}
|
||||
return validate(argv[1]) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
add_cpp_tool(json2json)
|
||||
add_cpp_tool(jsonstats)
|
||||
add_cpp_tool(minify)
|
|
@ -0,0 +1,20 @@
|
|||
if (CMAKE_VERSION VERSION_GREATER 3.0.0)
|
||||
cmake_policy(VERSION 3.0.0)
|
||||
endif ()
|
||||
|
||||
|
||||
function(add_cpp_test TEST_NAME)
|
||||
add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
|
||||
target_link_libraries(${TEST_NAME} ${SIMDJSON_LIB_NAME})
|
||||
add_test(${TEST_NAME} ${TEST_NAME})
|
||||
endfunction(add_cpp_test)
|
||||
|
||||
function(add_cpp_benchmark BENCH_NAME)
|
||||
add_executable(${BENCH_NAME} ${BENCH_NAME}.cpp)
|
||||
target_link_libraries(${BENCH_NAME} ${SIMDJSON_LIB_NAME})
|
||||
endfunction(add_cpp_benchmark)
|
||||
|
||||
function(add_cpp_tool TOOL_NAME)
|
||||
add_executable(${TOOL_NAME} ${TOOL_NAME}.cpp)
|
||||
target_link_libraries(${TOOL_NAME} ${SIMDJSON_LIB_NAME})
|
||||
endfunction(add_cpp_tool)
|
|
@ -0,0 +1,25 @@
|
|||
# gcc and clang require a special 'ar' and 'ranlib' to create a
|
||||
# static libX.a that allows for further inlining, but icc does not.
|
||||
|
||||
macro(append var string)
|
||||
set(${var} "${${var}} ${string}")
|
||||
endmacro(append)
|
||||
|
||||
if(BUILD_LTO)
|
||||
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Intel") # icc
|
||||
append(CMAKE_CXX_FLAGS "-ipo")
|
||||
elseif("${CMAKE_C_COMPILER_ID}" MATCHES "MSVC") # Microsoft
|
||||
# TODO
|
||||
elseif ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") # Clang or AppleClang
|
||||
append(CMAKE_CXX_FLAGS "-flto")
|
||||
append(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=gold -flto")
|
||||
append(CMAKE_SHARED_LINKER_FLAGS "-fuse-ld=gold -flto")
|
||||
set(_LLVM_VERSION_STRING "3.8") # FIXME: determine version automatically
|
||||
set(CMAKE_AR "llvm-ar-${_LLVM_VERSION_STRING}")
|
||||
set(CMAKE_RANLIB "llvm-ranlib-${_LLVM_VERSION_STRING}")
|
||||
else() # assume GCC compatible syntax if not matched
|
||||
append(CMAKE_CXX_FLAGS "-flto")
|
||||
set(CMAKE_AR "gcc-ar")
|
||||
set(CMAKE_RANLIB "gcc-ranlib")
|
||||
endif()
|
||||
endif(BUILD_LTO)
|
|
@ -0,0 +1,45 @@
|
|||
macro(append var string)
|
||||
set(${var} "${${var}} ${string}")
|
||||
endmacro(append)
|
||||
|
||||
set(SANITIZE_FLAGS "")
|
||||
if(SIMDJSON_SANITIZE)
|
||||
set(SIMDJSON_SANITIZE_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all")
|
||||
if (CMAKE_COMPILER_IS_GNUCC)
|
||||
# Ubuntu bug for GCC 5.0+ (safe for all versions)
|
||||
append(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=gold")
|
||||
append(CMAKE_SHARED_LINKER_FLAGS "-fuse-ld=gold")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
# some compilers like clang do not automagically define __AVX2__ and __BMI2__ even when the hardware supports it
|
||||
if(NOT MSVC)
|
||||
set (OPT_FLAGS "${OPT_FLAGS} -mavx2 -mbmi2 -mpclmul")
|
||||
else()
|
||||
set (OPT_FLAGS "${OPT_FLAGS} /arch:AVX2")
|
||||
endif()
|
||||
|
||||
if(NOT MSVC)
|
||||
set(CXXSTD_FLAGS "-std=c++17 -fPIC")
|
||||
endif()
|
||||
|
||||
set(WARNING_FLAGS "-Wall")
|
||||
if(NOT MSVC)
|
||||
set(WARNING_FLAGS "${WARNING_FLAGS} -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-ggdb")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS "${STD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ${SIMDJSON_SANITIZE_FLAGS} ")
|
||||
|
||||
if(NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS "${CXXSTD_FLAGS} ${OPT_FLAGS} ${INCLUDE_FLAGS} ${WARNING_FLAGS} ${SIMDJSON_SANITIZE_FLAGS} ")
|
||||
|
||||
if(MSVC)
|
||||
add_definitions( "/W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /wd4267 /wd4244 /wd4113 /nologo")
|
||||
endif()
|
Loading…
Reference in New Issue