Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving the support for DLLs. #543

Merged
merged 7 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/visual_studio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ jobs:
fail-fast: false
matrix:
include:
- {gen: Visual Studio 17 2022, arch: x64, devchecks: ON}
- {gen: Visual Studio 17 2022, arch: x64, devchecks: ON, shared: OFF}
- {gen: Visual Studio 17 2022, arch: x64, devchecks: ON, shared: ON}
- {gen: Visual Studio 17 2022, arch: Win32, devchecks: ON, shared: OFF}
- {gen: Visual Studio 17 2022, arch: Win32, devchecks: ON, shared: ON}
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v3.6.0
- name: Configure
run: |
cmake -DADA_DEVELOPMENT_CHECKS="${{matrix.devchecks}}" -G "${{matrix.gen}}" -A ${{matrix.arch}} -B build
cmake -DADA_DEVELOPMENT_CHECKS="${{matrix.devchecks}}" -G "${{matrix.gen}}" -A ${{matrix.arch}} -DBUILD_SHARED_LIBS=${{matrix.shared}} -B build
- name: Build Debug
run: cmake --build build --config Debug --verbose
- name: Run Debug tests
Expand Down
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ option(ADA_BENCHMARKS "Build benchmarks" OFF)
include(cmake/CPM.cmake)
# CPM requires git as an implicit dependency
find_package(Git QUIET)
# We use Google Benchmark, but it does not build under several 32-bit systems.
if(Git_FOUND AND (BUILD_TESTING OR ADA_BENCHMARKS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
CPMAddPackage("gh:simdjson/simdjson@3.3.0")
# We use googletest in the tests
if(Git_FOUND AND BUILD_TESTING)
CPMAddPackage(
NAME GTest
GITHUB_REPOSITORY google/googletest
VERSION 1.14.0
OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF"
)
endif()
# We use simdjson in both the benchmarks and tests
if(Git_FOUND AND (BUILD_TESTING OR ADA_BENCHMARKS))
CPMAddPackage("gh:simdjson/simdjson@3.3.0")
endif()
# We use Google Benchmark, but it does not build under several 32-bit systems.
if(Git_FOUND AND ADA_BENCHMARKS AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
CPMAddPackage(
NAME benchmark
GITHUB_REPOSITORY google/benchmark
Expand Down
8 changes: 7 additions & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ add_executable(percent_encode percent_encode.cpp)
target_link_libraries(percent_encode PRIVATE ada)
target_include_directories(percent_encode PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>")
target_include_directories(percent_encode PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/benchmarks>")

if(MSVC AND BUILD_SHARED_LIBS)
# Copy the ada dll into the directory
add_custom_command(TARGET percent_encode POST_BUILD # Adds a post-build event
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake -E copy_if_different..."
"$<TARGET_FILE:ada>" # <--this is in-file
"$<TARGET_FILE_DIR:percent_encode>") # <--this is out-file path
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
# The model_bench program requires accurate/low-overhead performance counters.
Expand Down
5 changes: 3 additions & 2 deletions singleheader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ if (Python3_Interpreter_FOUND)
add_library(ada-singleheader-source INTERFACE)
target_sources(ada-singleheader-source INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/ada.cpp>)
target_link_libraries(ada-singleheader-source INTERFACE ada-singleheader-include-source)
add_library(ada-singleheader-lib STATIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/ada.cpp>)

if (BUILD_TESTING)
add_executable(demo $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/demo.cpp>)
target_link_libraries(demo ada-singleheader-include-source)

add_test(demo demo)

add_executable(cdemo $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/demo.c>)
target_link_libraries(cdemo ada)

target_link_libraries(cdemo ada-singleheader-lib)
add_test(cdemo cdemo)
endif()
else()
Expand Down
85 changes: 49 additions & 36 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,57 @@ endif()
include(${PROJECT_SOURCE_DIR}/cmake/add-cpp-test.cmake)
link_libraries(ada)

include(GoogleTest)

add_executable(wpt_tests wpt_tests.cpp)
add_executable(url_components url_components.cpp)
add_executable(basic_tests basic_tests.cpp)
add_executable(from_file_tests from_file_tests.cpp)
add_executable(ada_c ada_c.cpp)
add_executable(url_search_params url_search_params.cpp)

target_link_libraries(wpt_tests PRIVATE simdjson GTest::gtest_main)
target_link_libraries(url_components PRIVATE simdjson GTest::gtest_main)
target_link_libraries(basic_tests PRIVATE simdjson GTest::gtest_main)
target_link_libraries(from_file_tests PRIVATE simdjson GTest::gtest_main)
target_link_libraries(ada_c PRIVATE simdjson GTest::gtest_main)
target_link_libraries(url_search_params PRIVATE simdjson GTest::gtest_main)

gtest_discover_tests(wpt_tests)
gtest_discover_tests(url_components)
gtest_discover_tests(basic_tests)
gtest_discover_tests(from_file_tests)
gtest_discover_tests(ada_c)
gtest_discover_tests(url_search_params)

add_cpp_test(basic_fuzzer)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
target_link_libraries(wpt_tests PUBLIC stdc++fs)
target_link_libraries(url_components PUBLIC stdc++fs)
target_link_libraries(url_search_params PUBLIC stdc++fs)
endif()
if(MSVC AND BUILD_SHARED_LIBS)
# Copy the ada dll into the directory
add_custom_command(TARGET basic_fuzzer PRE_BUILD # Adds a pre-build event
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake -E copy_if_different..."
"$<TARGET_FILE:ada>" # <--this is in-file
"$<TARGET_FILE_DIR:basic_fuzzer>") # <--this is out-file path
endif()

if(MSVC OR MINGW)
target_compile_definitions(wpt_tests PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(url_components PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(basic_fuzzer PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(from_file_tests PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(basic_tests PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(url_search_params PRIVATE _CRT_SECURE_NO_WARNINGS)
if(MSVC AND BUILD_SHARED_LIBS)
message(STATUS "For some tests we use Google Test and it fails when building a DLL.")
message(STATUS "Thus the tests are disabled. Sorry.")
else()
include(GoogleTest)
add_executable(wpt_tests wpt_tests.cpp)
add_executable(url_components url_components.cpp)
add_executable(basic_tests basic_tests.cpp)
add_executable(from_file_tests from_file_tests.cpp)
add_executable(ada_c ada_c.cpp)
add_executable(url_search_params url_search_params.cpp)

target_link_libraries(wpt_tests PRIVATE simdjson GTest::gtest_main)
target_link_libraries(url_components PRIVATE simdjson GTest::gtest_main)
target_link_libraries(basic_tests PRIVATE simdjson GTest::gtest_main)
target_link_libraries(from_file_tests PRIVATE simdjson GTest::gtest_main)
target_link_libraries(ada_c PRIVATE simdjson GTest::gtest_main)
target_link_libraries(url_search_params PRIVATE simdjson GTest::gtest_main)

gtest_discover_tests(wpt_tests)
gtest_discover_tests(url_components)
gtest_discover_tests(basic_tests)
gtest_discover_tests(from_file_tests)
gtest_discover_tests(ada_c)
gtest_discover_tests(url_search_params)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
target_link_libraries(wpt_tests PUBLIC stdc++fs)
target_link_libraries(url_components PUBLIC stdc++fs)
target_link_libraries(url_search_params PUBLIC stdc++fs)
endif()
endif()

if(MSVC OR MINGW)
target_compile_definitions(wpt_tests PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(url_components PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(basic_fuzzer PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(from_file_tests PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(basic_tests PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_definitions(url_search_params PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()

endif()
2 changes: 1 addition & 1 deletion tests/basic_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ size_t roller_fuzz(size_t N) {
size_t valid{};

for (std::string copy : url_examples) {
for (int index = 0; index < copy.size(); index++) {
for (size_t index = 0; index < copy.size(); index++) {
char orig = copy[index];
for (unsigned int value = 0; value < 255; value++) {
copy[index] = char(value);
Expand Down
8 changes: 7 additions & 1 deletion tools/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
add_executable(adaparse adaparse.cpp line_iterator.h)
target_link_libraries(adaparse PRIVATE ada)
target_include_directories(adaparse PUBLIC "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>")

if(MSVC AND BUILD_SHARED_LIBS)
# Copy the ada dll into the directory
add_custom_command(TARGET adaparse POST_BUILD # Adds a post-build event
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake -E copy_if_different..."
"$<TARGET_FILE:ada>" # <--this is in-file
"$<TARGET_FILE_DIR:adaparse>") # <--this is out-file path
endif()
CPMAddPackage("gh:fmtlib/fmt#7.1.3")
CPMAddPackage(
GITHUB_REPOSITORY jarro2783/cxxopts
Expand Down
Loading