Create simdjson-windows-headers interface library

This commit is contained in:
John Keiser 2020-04-06 11:58:26 -07:00
parent a9c8224f40
commit beaa6a9a7a
6 changed files with 62 additions and 39 deletions

View File

@ -2,28 +2,41 @@ version: '{build}'
branches:
only:
- master
image:
- Visual Studio 2017
clone_folder: c:\projects\simdjson
platform:
- x64
platform: x64
image:
- Visual Studio 2019
- Visual Studio 2017
configuration: Release
environment:
matrix:
- SIMDJSON_BUILD_STATIC: "OFF"
THREADS: "ON"
- SIMDJSON_BUILD_STATIC: "OFF"
THREADS: "OFF"
- SIMDJSON_BUILD_STATIC: "ON"
THREADS: "ON"
# - SIMDJSON_BUILD_STATIC: "ON"
# THREADS: "OFF"
- SIMDJSON_BUILD_STATIC: ON
SIMDJSON_ENABLE_THREADS: OFF
- SIMDJSON_BUILD_STATIC: OFF
SIMDJSON_ENABLE_THREADS: ON
build_script:
- set
- mkdir build
- cd build
- ps: cmake -DSIMDJSON_BUILD_STATIC="$env:SIMDJSON_BUILD_STATIC" -DSIMDJSON_ENABLE_THREADS="$env:THREADS" -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=x64 -DSIMDJSON_GOOGLE_BENCHMARKS=OFF ..
- cmake --build .
- ctest --verbose --output-on-failure
- cmake -DSIMDJSON_BUILD_STATIC=%SIMDJSON_BUILD_STATIC% -DSIMDJSON_ENABLE_THREADS=%SIMDJSON_ENABLE_THREADS% -DCMAKE_BUILD_TYPE=%Configuration% -DCMAKE_GENERATOR_PLATFORM=x64 -DSIMDJSON_GOOGLE_BENCHMARKS=OFF ..
- cmake --build . --config %Configuration%
test_script:
- ctest --verbose --output-on-failure -C %Configuration%
# VS 2017 only: readme examples don't presently succeed, exclude
for:
- matrix:
only:
- image: Visual Studio 2017
test_script:
- ctest --verbose --output-on-failure -C %Configuration% -E readme
matrix:
fast_finish: true
exclude:
# Don't build all variants on 2019, just running it to make sure readme_tests succeed
- image: Visual Studio 2019
SIMDJSON_BUILD_STATIC: ON
SIMDJSON_ENABLE_THREADS: OFF

View File

@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.9) # CMP0069 NEW
message(STATUS "cmake version ${CMAKE_VERSION}")
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)
@ -52,6 +53,7 @@ find_package(Options)
# Create the top level simdjson library (must be done at this level to use both src/ and include/
# directories)
#
add_subdirectory(windows)
add_subdirectory(include)
add_subdirectory(src)

View File

@ -55,16 +55,16 @@ set_target_properties(simdjson PROPERTIES
MESSAGE( STATUS "Library output directory (does not apply to Visual Studio): " ${CMAKE_BINARY_DIR})
endif()
if((SIMDJSON_LIB_TYPE STREQUAL "SHARED"))
target_compile_definitions(${SIMDJSON_LIB_NAME} INTERFACE SIMDJSON_USING_LIBRARY=1)
if(NOT SIMDJSON_BUILD_STATIC)
target_compile_definitions(simdjson INTERFACE SIMDJSON_USING_LIBRARY=1)
endif()
if(MSVC AND (SIMDJSON_LIB_TYPE STREQUAL "SHARED"))
if(MSVC AND (NOT SIMDJSON_BUILD_STATIC))
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." )
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
set_target_properties(simdjson
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
endif()

View File

@ -5,23 +5,28 @@ function(add_cpp_test TEST_NAME TEST_FILE)
endfunction(add_cpp_test)
# Sets a target to only build when you run the test, and expect failure
function(add_compile_fail_test TEST_NAME)
function(add_compile_test TEST_NAME TEST_FILE EXPECT_SUCCESS)
add_executable(${TEST_NAME} ${TEST_FILE})
set_target_properties(${TEST_NAME} PROPERTIES
EXCLUDE_FROM_ALL TRUE
EXCLUDE_FROM_DEFAULT_BUILD TRUE)
add_test(NAME ${TEST_NAME}
COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $<CONFIGURATION>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(${TEST_NAME} PROPERTIES WILL_FAIL TRUE)
endfunction(add_compile_fail_test)
COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $<CONFIGURATION>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
if(NOT ${EXPECT_SUCCESS})
set_tests_properties(${TEST_NAME} PROPERTIES WILL_FAIL TRUE)
endif()
endfunction(add_compile_test)
#
# These test explicitly do #include "simdjson.cpp"
#
add_cpp_test(numberparsingcheck numberparsingcheck.cpp)
target_link_libraries(numberparsingcheck simdjson-source)
add_cpp_test(stringparsingcheck stringparsingcheck.cpp)
target_link_libraries(stringparsingcheck simdjson-source)
if (NOT MSVC) # Can't get simdjson-source to compile on Windows for some reason.
add_cpp_test(numberparsingcheck numberparsingcheck.cpp)
target_link_libraries(numberparsingcheck simdjson-source simdjson-windows-headers)
add_cpp_test(stringparsingcheck stringparsingcheck.cpp)
target_link_libraries(stringparsingcheck simdjson-source simdjson-windows-headers)
endif()
#
# All remaining tests link with simdjson proper
@ -33,22 +38,19 @@ add_cpp_test(basictests basictests.cpp)
add_cpp_test(errortests errortests.cpp)
add_cpp_test(integer_tests integer_tests.cpp)
add_cpp_test(jsoncheck jsoncheck.cpp)
target_link_libraries(jsoncheck simdjson-windows-headers)
add_cpp_test(parse_many_test parse_many_test.cpp)
target_link_libraries(parse_many_test simdjson-windows-headers)
add_cpp_test(pointercheck pointercheck.cpp)
# Compile-only tests
add_executable(readme_examples readme_examples.cpp)
add_executable(readme_examples_noexceptions readme_examples_noexceptions.cpp)
target_compile_options(readme_examples_noexceptions PRIVATE -fno-exceptions)
add_compile_test(readme_examples readme_examples.cpp TRUE)
# Test that readme_examples does NOT compile when SIMDJSON_EXCEPTIONS=0 (i.e. test that the define
# works even if exceptions are on)
add_executable(readme_examples_will_fail_with_exceptions_off readme_examples.cpp)
add_compile_test(readme_examples_will_fail_with_exceptions_off readme_examples.cpp FALSE)
target_compile_definitions(readme_examples_will_fail_with_exceptions_off PRIVATE SIMDJSON_EXCEPTIONS=0)
add_compile_fail_test(readme_examples_will_fail_with_exceptions_off)
if(MSVC)
include_directories($<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/windows>)
add_custom_command(TARGET basictests POST_BUILD # Adds a post-build event
COMMAND ${CMAKE_COMMAND} -E echo "$<TARGET_FILE:simdjson>"
COMMAND ${CMAKE_COMMAND} -E echo "$<TARGET_FILE_DIR:basictests>"

View File

@ -1,4 +1,6 @@
link_libraries(simdjson)
link_libraries(simdjson-windows-headers)
add_executable(json2json json2json.cpp)
add_executable(jsonstats jsonstats.cpp)
add_executable(minify minify.cpp)

4
windows/CMakeLists.txt Normal file
View File

@ -0,0 +1,4 @@
add_library(simdjson-windows-headers INTERFACE)
if(MSVC)
target_include_directories(simdjson-windows-headers INTERFACE .)
endif()