Skip to content

Commit d1fc36d

Browse files
authored
Merge pull request #402 from hexchain/cmake-system-simdjson
CMake: Use system simdjson when available
2 parents 20f1915 + 97d365e commit d1fc36d

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed

.github/workflows/linux_make.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
1211
runs-on: ubuntu-latest
13-
1412
steps:
1513
- uses: actions/checkout@v2
1614
- name: cmake
@@ -21,4 +19,37 @@ jobs:
2119
run: |
2220
cd ${{ github.workspace }}/build
2321
make install -j
24-
22+
build-system-simdjson:
23+
runs-on: ubuntu-latest
24+
container: ubuntu:22.04
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: install dependencies
28+
run: |
29+
apt update
30+
apt -y --no-install-recommends install build-essential cmake libsimdjson-dev
31+
- name: cmake
32+
run: |
33+
rm -rf ${{ github.workspace }}/build
34+
cmake -B ${{ github.workspace }}/build -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}
35+
- name: make
36+
run: |
37+
cd ${{ github.workspace }}/build
38+
make install -j
39+
build-source-simdjson:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v2
43+
- name: install simdjson
44+
uses: actions/checkout@v2
45+
with:
46+
repository: simdjson/simdjson
47+
path: src/simdjson
48+
- name: cmake
49+
run: |
50+
rm -rf ${{ github.workspace }}/build
51+
cmake -B ${{ github.workspace }}/build -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}
52+
- name: make
53+
run: |
54+
cd ${{ github.workspace }}/build
55+
make install -j

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ 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+
6477
#######################
6578
# Install
6679
#######################

src/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,30 @@ endif(MSVC)
8888

8989
foreach(PROJECT_NAME ${PROJECT_NAMES})
9090
file(GLOB PROJECT_FILE ${PROJECT_NAME}.cpp)
91+
set(LIBS PCM_STATIC)
92+
93+
add_executable(${PROJECT_NAME} ${PROJECT_FILE})
9194

9295
# specific file for pcm-raw project
9396
if(${PROJECT_NAME} STREQUAL pcm-raw)
94-
file(GLOB SIMDJSON_SOURCE simdjson_wrapper.cpp)
95-
add_executable(${PROJECT_NAME} ${PROJECT_FILE} ${SIMDJSON_SOURCE})
96-
else()
97-
add_executable(${PROJECT_NAME} ${PROJECT_FILE})
97+
set(LIBS ${LIBS} PCM_SIMDJSON)
9898
endif(${PROJECT_NAME} STREQUAL pcm-raw)
9999

100100
if(LINUX OR FREE_BSD)
101-
target_link_libraries(${PROJECT_NAME} PRIVATE PCM_STATIC Threads::Threads)
101+
set(LIBS ${LIBS} Threads::Threads)
102102
install(TARGETS ${PROJECT_NAME} DESTINATION "sbin")
103103
endif(LINUX OR FREE_BSD)
104104

105105
if(APPLE)
106-
target_link_libraries(${PROJECT_NAME} PRIVATE PCM_STATIC Threads::Threads PcmMsr)
106+
set(LIBS ${LIBS} Threads::Threads PcmMsr)
107107
install(TARGETS ${PROJECT_NAME} DESTINATION "sbin")
108108
endif(APPLE)
109109

110110
if(MSVC)
111111
target_compile_definitions(${PROJECT_NAME} PRIVATE _UNICODE UNICODE _CONSOLE) # for all, except pcm-lib and pcm-service
112-
target_link_libraries(${PROJECT_NAME} PRIVATE PCM_STATIC)
113112
endif(MSVC)
114113

114+
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS})
115115
endforeach(PROJECT_NAME ${PROJECT_NAMES})
116116

117117
#######################

src/simdjson_wrapper.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
#endif
88

99
#ifndef PCM_GCC_6_OR_BELOW
10-
#if defined __has_include
10+
#if defined SYSTEM_SIMDJSON
11+
#include <simdjson.h>
12+
#define PCM_SIMDJSON_AVAILABLE
13+
#elif defined __has_include
1114
#if __has_include ("simdjson/singleheader/simdjson.h")
1215
#pragma warning(push, 0)
1316
#include "simdjson/singleheader/simdjson.h"

tests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ if(UNIX)
2020

2121
# PCM_STATIC + pcm_sensor + simdjson_obj = urltest
2222
if(LINUX)
23-
add_executable(urltest urltest.cpp ../src/simdjson_wrapper.cpp)
24-
target_link_libraries(urltest Threads::Threads PCM_STATIC)
23+
add_executable(urltest urltest.cpp)
24+
target_link_libraries(urltest Threads::Threads PCM_SIMDJSON PCM_STATIC)
2525
endif(LINUX)
2626

2727
endif(UNIX)

0 commit comments

Comments
 (0)