-
Notifications
You must be signed in to change notification settings - Fork 22
/
CMakeLists.txt
84 lines (71 loc) · 2.75 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
cmake_minimum_required(VERSION 3.14)
project(meojson CXX)
option(BUILD_SAMPLE "Build sample in sample/sample.cpp" ON)
option(BUILD_BENCHMARK "Build benchmark in benchmark/benchmark.cpp" OFF)
option(ENABLE_NEON "Enable ARM NEON" OFF)
option(BUILD_TESTING "Build testing" ON)
set(CMAKE_CXX_STANDARD 17)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
add_compile_options("/utf-8" "/W4")
else()
add_compile_options("-Wall;-Wextra;-Wpedantic;-mtune=native")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|EM64T|x86_64")
add_compile_options("-msse4.1")
endif()
endif()
if(ENABLE_NEON)
add_compile_definitions(MEOJSON_ENABLE_NEON)
endif()
file(GLOB_RECURSE json_headers
include/*.h
include/*.hpp
)
add_library(meojson INTERFACE ${json_headers})
target_include_directories(meojson INTERFACE include)
if (BUILD_SAMPLE)
file(GLOB sample_src
sample/*.cpp
sample/*.h
sample/*.hpp
)
add_executable(sample ${sample_src})
target_link_libraries(sample meojson)
if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC"))
target_compile_options(sample PRIVATE -Wno-unused-variable -Wno-unused-but-set-variable)
endif()
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${json_headers})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${sample_src})
endif()
if (BUILD_TESTING)
file(GLOB testing_src
test/*.cpp
test/*.h
test/*.hpp
)
add_executable(testing ${testing_src})
target_link_libraries(testing meojson)
if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC"))
target_compile_options(testing PRIVATE -Wno-unused-variable -Wno-unused-but-set-variable)
endif()
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${json_headers})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${testing_src})
endif()
if (BUILD_BENCHMARK)
SET(CMAKE_BUILD_TYPE "Release")
file(GLOB_RECURSE benchmark_src
benchmark/*.cpp
benchmark/*.h
benchmark/*.hpp
)
add_executable(benchmark ${benchmark_src})
target_link_libraries(benchmark meojson)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${json_headers})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${benchmark_src})
if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|EM64T|x86_64")
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
target_compile_options(benchmark PRIVATE "/arch:AVX2")
elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "GNU|Clang")
target_compile_options(benchmark PRIVATE "-mavx2")
endif()
endif()
endif()