diff --git a/.github/workflows/visual_studio.yml b/.github/workflows/visual_studio.yml index 0f9233409..e0b3a51c2 100644 --- a/.github/workflows/visual_studio.yml +++ b/.github/workflows/visual_studio.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 20a30bb3a..8f32ba462 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 30183a27c..886ce52f5 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -35,7 +35,13 @@ add_executable(percent_encode percent_encode.cpp) target_link_libraries(percent_encode PRIVATE ada) target_include_directories(percent_encode PUBLIC "$") target_include_directories(percent_encode PUBLIC "$") - +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..." + "$" # <--this is in-file + "$") # <--this is out-file path +endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux") # The model_bench program requires accurate/low-overhead performance counters. diff --git a/singleheader/CMakeLists.txt b/singleheader/CMakeLists.txt index a4312f9b0..a0afcde89 100644 --- a/singleheader/CMakeLists.txt +++ b/singleheader/CMakeLists.txt @@ -49,6 +49,8 @@ if (Python3_Interpreter_FOUND) add_library(ada-singleheader-source INTERFACE) target_sources(ada-singleheader-source INTERFACE $) target_link_libraries(ada-singleheader-source INTERFACE ada-singleheader-include-source) + add_library(ada-singleheader-lib STATIC $) + if (BUILD_TESTING) add_executable(demo $) target_link_libraries(demo ada-singleheader-include-source) @@ -56,8 +58,7 @@ if (Python3_Interpreter_FOUND) add_test(demo demo) add_executable(cdemo $) - target_link_libraries(cdemo ada) - + target_link_libraries(cdemo ada-singleheader-lib) add_test(cdemo cdemo) endif() else() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2a1ebd61b..a1f21f403 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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..." + "$" # <--this is in-file + "$") # <--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() diff --git a/tests/basic_fuzzer.cpp b/tests/basic_fuzzer.cpp index c3635ee26..a64698acf 100644 --- a/tests/basic_fuzzer.cpp +++ b/tests/basic_fuzzer.cpp @@ -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); diff --git a/tools/cli/CMakeLists.txt b/tools/cli/CMakeLists.txt index 5d0ca8029..ff57220b5 100644 --- a/tools/cli/CMakeLists.txt +++ b/tools/cli/CMakeLists.txt @@ -1,7 +1,13 @@ add_executable(adaparse adaparse.cpp line_iterator.h) target_link_libraries(adaparse PRIVATE ada) target_include_directories(adaparse PUBLIC "$") - +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..." + "$" # <--this is in-file + "$") # <--this is out-file path +endif() CPMAddPackage("gh:fmtlib/fmt#7.1.3") CPMAddPackage( GITHUB_REPOSITORY jarro2783/cxxopts