Skip to content

Commit 07bdd2e

Browse files
committed
Move simdjson wrapper logic to cmake
- Check pre-downloaded simdjson existance and its applicability depends on system settings and simdjson support matrix - Moved simdjson wrapper-file logic to cmake configuration - Remove simdjson download from KW check
1 parent d1fc36d commit 07bdd2e

File tree

8 files changed

+50
-55
lines changed

8 files changed

+50
-55
lines changed

.github/workflows/ci-kw-linux.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ jobs:
1616
- uses: actions/checkout@v2
1717
- name: kw
1818
run: |
19-
cd src
20-
git clone https://github.com/simdjson/simdjson.git
21-
cd ..
2219
mkdir build
2320
cd build
2421
cmake ..

.github/workflows/ci-kw-windows.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ jobs:
2020

2121
- name: kw
2222
run: |
23-
cd ${{github.workspace}}\src
24-
git clone https://github.com/simdjson/simdjson.git
25-
cd ..
2623
mkdir build
2724
cd build
2825
cmake ..

CMakeLists.txt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,6 @@ if(UNIX) # APPLE, LINUX, FREE_BSD
6161

6262
endif(UNIX)
6363

64-
# interface library for simdjson
65-
add_library(PCM_SIMDJSON INTERFACE)
66-
find_package(simdjson QUIET)
67-
if(simdjson_FOUND)
68-
target_link_libraries(PCM_SIMDJSON INTERFACE simdjson::simdjson)
69-
target_compile_definitions(PCM_SIMDJSON INTERFACE SYSTEM_SIMDJSON)
70-
else()
71-
message("simdjson not found in system, falling back to wrapper")
72-
file(GLOB SIMDJSON_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/simdjson_wrapper.cpp)
73-
target_sources(PCM_SIMDJSON INTERFACE ${SIMDJSON_SOURCE})
74-
target_include_directories(PCM_SIMDJSON INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src)
75-
endif(simdjson_FOUND)
76-
7764
#######################
7865
# Install
7966
#######################

src/CMakeLists.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,50 @@ if(MSVC)
8585

8686
endif(MSVC)
8787

88+
#######################
89+
# SIMDJSON dependency
90+
#######################
91+
92+
add_library(PCM_SIMDJSON INTERFACE) # interface library for simdjson
93+
set(SIMDJSON_IS_APPLICABLE TRUE) # true if simdjson can be used, default - TRUE
94+
95+
# check simdjson support matrix - https://github.com/simdjson/simdjson/blob/master/doc/basics.md
96+
# > GCC 7.4, > Clang 6.0 , > MSVC 2017
97+
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.4) OR
98+
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6) OR
99+
(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_TOOLSET_VERSION VERSION_LESS 141)) # corresponds to VS2017
100+
message(WARNING
101+
" ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_VERSION} is incompartible with simdjson features' requirements.\n"
102+
" Refer to simdjson support matrix - https://github.com/simdjson/simdjson/blob/master/doc/basics.md .\n"
103+
" Parsing events from 01.org/perfmon won't be supported.")
104+
set(SIMDJSON_IS_APPLICABLE FALSE)
105+
endif()
106+
107+
if(SIMDJSON_IS_APPLICABLE)
108+
find_package(simdjson QUIET) # Working form Ububtu 22.04
109+
if(simdjson_FOUND)
110+
message(STATUS "System SIMDJSON is used")
111+
target_link_libraries(PCM_SIMDJSON INTERFACE simdjson::simdjson)
112+
target_compile_definitions(PCM_SIMDJSON INTERFACE SYSTEM_SIMDJSON)
113+
target_compile_definitions(PCM_SIMDJSON INTERFACE PCM_SIMDJSON_AVAILABLE)
114+
else()
115+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/simdjson/singleheader/simdjson.h")
116+
message(STATUS "Local SIMDJSON exists: ${CMAKE_CURRENT_SOURCE_DIR}/simdjson/singleheader/simdjson.h")
117+
file(GLOB SIMDJSON_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/simdjson/singleheader/simdjson.cpp)
118+
target_sources(PCM_SIMDJSON INTERFACE ${SIMDJSON_SOURCE})
119+
target_include_directories(PCM_SIMDJSON INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/simdjson/singleheader)
120+
target_compile_definitions(PCM_SIMDJSON INTERFACE PCM_SIMDJSON_AVAILABLE)
121+
else()
122+
message(WARNING
123+
" ${CMAKE_CURRENT_SOURCE_DIR}/simdjson/singleheader/simdjson.h doesn't exist\n"
124+
" Run 'git clone https://github.com/simdjson/simdjson.git' in 'src' directory to get simdjson library")
125+
endif()
126+
endif(simdjson_FOUND)
127+
endif(SIMDJSON_IS_APPLICABLE)
128+
129+
#######################
130+
# End of SIMDJSON dependency section
131+
#######################
88132

89133
foreach(PROJECT_NAME ${PROJECT_NAMES})
90134
file(GLOB PROJECT_FILE ${PROJECT_NAME}.cpp)

src/pcm-raw.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
#include <unordered_map>
3737
#include "cpucounters.h"
3838
#include "utils.h"
39-
#include "simdjson_wrapper.h"
39+
40+
#if PCM_SIMDJSON_AVAILABLE
41+
#include "simdjson.h"
42+
#endif
4043

4144
#ifdef _MSC_VER
4245
#include "freegetopt/getopt.h"

src/simdjson_wrapper.cpp

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/simdjson_wrapper.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ if(UNIX)
1818
add_executable(daemon_alignment_test ${TEST_FILE})
1919
target_link_libraries(daemon_alignment_test)
2020

21-
# PCM_STATIC + pcm_sensor + simdjson_obj = urltest
21+
# PCM_STATIC + pcm_sensor = urltest
2222
if(LINUX)
2323
add_executable(urltest urltest.cpp)
24-
target_link_libraries(urltest Threads::Threads PCM_SIMDJSON PCM_STATIC)
24+
target_link_libraries(urltest Threads::Threads PCM_STATIC)
2525
endif(LINUX)
2626

2727
endif(UNIX)

0 commit comments

Comments
 (0)