Skip to content

Commit d2c9ea8

Browse files
authored
Detect bash instead of relying on MSVC detection. (simdjson#894)
1 parent 40d57da commit d2c9ea8

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

singleheader/CMakeLists.txt

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#
22
# Amalgamation
33
#
4-
# We should check whether bash is available here and avoid failures on systems where
5-
# bash is unavailable.
4+
65
set(SINGLEHEADER_FILES
76
${CMAKE_CURRENT_BINARY_DIR}/simdjson.cpp
87
${CMAKE_CURRENT_BINARY_DIR}/simdjson.h
@@ -17,32 +16,16 @@ set(SINGLEHEADER_REPO_FILES
1716
)
1817
set_source_files_properties(${SINGLEHEADER_FILES} PROPERTIES GENERATED TRUE)
1918

20-
if (MSVC)
21-
# MSVC doesn't have bash, so we use existing amalgamated files instead of generating them ...
22-
# (Do not do this if the source and destination are the same!)
23-
if (NOT (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}))
24-
add_custom_command(
25-
OUTPUT ${SINGLEHEADER_FILES}
26-
COMMAND ${CMAKE_COMMAND} -E copy
27-
${SINGLEHEADER_REPO_FILES}
28-
${CMAKE_CURRENT_BINARY_DIR}
29-
DEPENDS ${SINGLEHEADER_REPO_FILES}
30-
)
31-
endif()
32-
33-
else(MSVC)
19+
find_program(BASH bash)
3420

35-
##
36-
# Important! The script amalgamate.sh is not generally executable. It
37-
# assumes that bash is at /bin/bash which may not be true.
38-
###
21+
if (BASH)
3922
add_custom_command(
4023
OUTPUT ${SINGLEHEADER_FILES}
4124
COMMAND ${CMAKE_COMMAND} -E env
4225
AMALGAMATE_SOURCE_PATH=${PROJECT_SOURCE_DIR}/src
4326
AMALGAMATE_INPUT_PATH=${PROJECT_SOURCE_DIR}/include
4427
AMALGAMATE_OUTPUT_PATH=${CMAKE_CURRENT_BINARY_DIR}
45-
bash ${CMAKE_CURRENT_SOURCE_DIR}/amalgamate.sh
28+
${BASH} ${CMAKE_CURRENT_SOURCE_DIR}/amalgamate.sh
4629
#
4730
# This is the best way I could find to make amalgamation trigger whenever source files or
4831
# header files change: since the "simdjson" library has to get rebuilt when that happens, we
@@ -72,7 +55,22 @@ else(MSVC)
7255
# "make amalgamate" to generate the header files directly and update the original source
7356
#
7457
add_custom_target(amalgamate DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/simdjson.cpp ${CMAKE_CURRENT_SOURCE_DIR}/simdjson.h ${CMAKE_CURRENT_SOURCE_DIR}/amalgamate_demo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
75-
endif(MSVC)
58+
59+
else(BASH)
60+
61+
# We do not have bash, so we use existing amalgamated files instead of generating them ...
62+
# (Do not do this if the source and destination are the same!)
63+
if (NOT (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}))
64+
add_custom_command(
65+
OUTPUT ${SINGLEHEADER_FILES}
66+
COMMAND ${CMAKE_COMMAND} -E copy
67+
${SINGLEHEADER_REPO_FILES}
68+
${CMAKE_CURRENT_BINARY_DIR}
69+
DEPENDS ${SINGLEHEADER_REPO_FILES}
70+
)
71+
endif()
72+
73+
endif(BASH)
7674

7775

7876
#

tests/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ add_cpp_test(jsoncheck LABELS acceptance per_implementation)
5858
add_cpp_test(parse_many_test LABELS acceptance per_implementation)
5959
add_cpp_test(pointercheck LABELS acceptance per_implementation)
6060
add_cpp_test(extracting_values_example LABELS acceptance per_implementation)
61+
find_program(BASH bash)
62+
6163

6264
# Script tests
63-
if (NOT MSVC) # Can't run .sh on windows
65+
if (BASH AND (NOT MSVC)) # The scripts are not robust enough to run under Windows even if bash is available
6466
#
6567
# json2json test
6668
#
6769
add_test(
6870
NAME testjson2json
69-
COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/testjson2json.sh
71+
COMMAND ${BASH} ${CMAKE_CURRENT_SOURCE_DIR}/testjson2json.sh
7072
WORKING_DIRECTORY $<TARGET_FILE_DIR:minify>
7173
)
7274
set_property(TEST testjson2json APPEND PROPERTY DEPENDS minify json2json)
@@ -79,14 +81,11 @@ if (NOT MSVC) # Can't run .sh on windows
7981
add_executable(allparserscheckfile allparserscheckfile.cpp)
8082
target_link_libraries(allparserscheckfile competition-all)
8183

82-
add_test(issue150 bash ${CMAKE_CURRENT_SOURCE_DIR}/issue150.sh)
84+
add_test(issue150 ${BASH} ${CMAKE_CURRENT_SOURCE_DIR}/issue150.sh)
8385
set_property(TEST issue150 APPEND PROPERTY DEPENDS allparserscheckfile)
8486
set_property(TEST issue150 APPEND PROPERTY LABELS per_implementation)
8587
endif()
86-
endif()
8788

88-
# This should really test whether bash is available.
89-
if (NOT MSVC)
9089
#
9190
# json2json tool test: check that json2json can parse twitter.json
9291
#

0 commit comments

Comments
 (0)