From ffca0f80d6d8a21f5ef398327631dc1b7e93f5ba Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Tue, 26 Sep 2017 07:02:32 -0400 Subject: [PATCH 1/7] Add CMake build. --- CMakeLists.txt | 111 ++++++++++++++++++++++++++++++++++++++++++ cmake/Config.cmake.in | 4 ++ 2 files changed, 115 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..01625619 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,111 @@ +cmake_minimum_required(VERSION 3.1) + +project(gumbo VERSION 0.10.1) + +set(CMAKE_C_STANDARD_REQUIRED true) +set(CMAKE_C_STANDARD 99) + +set(SRC + src/attribute.c + src/char_ref.c + src/error.c + src/parser.c + src/string_buffer.c + src/string_piece.c + src/tag.c + src/tokenizer.c + src/utf8.c + src/util.c + src/vector.c) + +set(HEADERS + src/attribute.h + src/char_ref.h + src/error.h + src/gumbo.h + src/insertion_mode.h + src/string_buffer.h + src/string_piece.h + src/parser.h + src/token_type.h + src/tokenizer.h + src/tokenizer_states.h + src/utf8.h + src/util.h + src/vector.h) + +add_library(gumbo ${SRC}) +target_include_directories(gumbo PUBLIC + $) + +# Installation (https://github.com/forexample/package-example) + +# Layout. This works for all platforms: +# * /lib/cmake/ +# * /lib/ +# * /include/ +set(config_install_dir "lib/cmake/${PROJECT_NAME}") +set(include_install_dir "include") + +set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") + +# Configuration +set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") +set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") +set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") +set(namespace "${PROJECT_NAME}::") + +# Include module with fuction 'write_basic_package_version_file' +include(CMakePackageConfigHelpers) + +# Configure 'ConfigVersion.cmake' +# Use: +# * PROJECT_VERSION +write_basic_package_version_file( + "${version_config}" COMPATIBILITY SameMajorVersion +) + +# Configure 'Config.cmake' +# Use variables: +# * TARGETS_EXPORT_NAME +# * PROJECT_NAME +configure_package_config_file( + "cmake/Config.cmake.in" + "${project_config}" + INSTALL_DESTINATION "${config_install_dir}" +) + +# Targets: +# * /lib/libgumbo.a +# * header location after install: /include/gumbo.h +install( + TARGETS gumbo + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "${include_install_dir}" +) + +# Headers: +# * src/gumbo.h -> /include/gumbo.h +install( + FILES ${HEADERS} + DESTINATION "${include_install_dir}" +) + +# Config +# * /lib/cmake/gumbo/gumboConfig.cmake +# * /lib/cmake/gumbo/gumboConfigVersion.cmake +install( + FILES "${project_config}" "${version_config}" + DESTINATION "${config_install_dir}" +) + +# Config +# * /lib/cmake/gumbo/gumboTargets.cmake +install( + EXPORT "${TARGETS_EXPORT_NAME}" + NAMESPACE "${namespace}" + DESTINATION "${config_install_dir}" +) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 00000000..38bbde7b --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +check_required_components("@PROJECT_NAME@") From e925588809b88812533298bfc4f55da5124a2daa Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Tue, 26 Sep 2017 07:19:39 -0400 Subject: [PATCH 2/7] Add CMake support for test cases. --- .travis.yml | 1 + CMakeLists.txt | 5 +++++ tests/CMakeLists.txt | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/CMakeLists.txt diff --git a/.travis.yml b/.travis.yml index d76208f5..f9bd0edc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ install: - sudo pip install html5lib==0.95 script: + - mkdir build && cmake .. && make && make test - ./autogen.sh && ./configure && make && make check - python python/gumbo/gumboc_test.py - python python/gumbo/html5lib_adapter_test.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 01625619..f70de538 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,3 +109,8 @@ install( NAMESPACE "${namespace}" DESTINATION "${config_install_dir}" ) + +include(CTest) +if(BUILD_TESTING) + add_subdirectory(tests) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..ba78e052 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,17 @@ +enable_testing() +find_package(GTest REQUIRED) + +add_executable(gumbo_parser_unittests + attribute.cc + char_ref.cc + parser.cc + string_buffer.cc + string_piece.cc + test_utils.cc + tokenizer.cc + utf8.cc + vector.cc) +target_include_directories(gumbo_parser_unittests + PUBLIC "${PROJECT_SOURCE_DIR}/src" ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(gumbo_parser_unittests gumbo GTest::GTest GTest::Main) +add_test(gumbo_parser_unittests gumbo_parser_unittests) From 48cc5b3ebda05aab99d2f9203b00faf94d471349 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Tue, 26 Sep 2017 07:44:53 -0400 Subject: [PATCH 3/7] Fix headers list. --- CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f70de538..3c1e8dce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,12 +24,16 @@ set(HEADERS src/error.h src/gumbo.h src/insertion_mode.h + src/parser.h src/string_buffer.h src/string_piece.h - src/parser.h - src/token_type.h + src/tag_enum.h + src/tag_gperf.h + src/tag_sizes.h + src/tag_strings.h src/tokenizer.h src/tokenizer_states.h + src/token_type.h src/utf8.h src/util.h src/vector.h) From 79ba38bd5fabff04f3cb419d61938e2664a4c268 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Tue, 26 Sep 2017 12:12:55 -0400 Subject: [PATCH 4/7] Fix Windows build and gtest usage. --- .travis.yml | 4 +--- CMakeLists.txt | 6 ++++++ tests/CMakeLists.txt | 6 ++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index f9bd0edc..6b92868f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,13 +9,11 @@ os: - osx install: - - wget 'https://googletest.googlecode.com/files/gtest-1.7.0.zip' - - unzip gtest-1.7.0.zip - - ln -s gtest-1.7.0 gtest - sudo pip install BeautifulSoup - sudo pip install html5lib==0.95 script: + - cd third_party/gtest && cmake . && make - mkdir build && cmake .. && make && make test - ./autogen.sh && ./configure && make && make check - python python/gumbo/gumboc_test.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c1e8dce..20e3bbaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,12 @@ add_library(gumbo ${SRC}) target_include_directories(gumbo PUBLIC $) +if(WIN32) + list(APPEND HEADERS visualc/include/strings.h) + target_include_directories(gumbo PUBLIC + $) +endif() + # Installation (https://github.com/forexample/package-example) # Layout. This works for all platforms: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ba78e052..49a60a7e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -enable_testing() +set(GTEST_ROOT "${PROJECT_SOURCE_DIR}/third_party/gtest") find_package(GTest REQUIRED) add_executable(gumbo_parser_unittests @@ -11,7 +11,9 @@ add_executable(gumbo_parser_unittests tokenizer.cc utf8.cc vector.cc) + target_include_directories(gumbo_parser_unittests - PUBLIC "${PROJECT_SOURCE_DIR}/src" ${CMAKE_CURRENT_SOURCE_DIR}) + PUBLIC "${PROJECT_SOURCE_DIR}/src" + ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(gumbo_parser_unittests gumbo GTest::GTest GTest::Main) add_test(gumbo_parser_unittests gumbo_parser_unittests) From d93da3ded7d9b5013d6f3259aa463e2dbb224e81 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Tue, 26 Sep 2017 12:23:52 -0400 Subject: [PATCH 5/7] Fix Windows include directory path. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20e3bbaf..aa483ff1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ target_include_directories(gumbo PUBLIC if(WIN32) list(APPEND HEADERS visualc/include/strings.h) target_include_directories(gumbo PUBLIC - $) + $) endif() # Installation (https://github.com/forexample/package-example) From 748829a23d2beac16496e548bea4dc7b1520daa5 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Tue, 26 Sep 2017 12:45:42 -0400 Subject: [PATCH 6/7] Fix Travis CMake build. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6b92868f..ee084237 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,8 +13,8 @@ install: - sudo pip install html5lib==0.95 script: - - cd third_party/gtest && cmake . && make - - mkdir build && cmake .. && make && make test + - cd third_party/gtest && cmake . && make && cd ../../ + - mkdir build && cd build && cmake .. && make && make test && cd .. - ./autogen.sh && ./configure && make && make check - python python/gumbo/gumboc_test.py - python python/gumbo/html5lib_adapter_test.py From e46ac843e20a9b517312bdef393210761cc7bbad Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Tue, 20 Mar 2018 07:00:56 -0400 Subject: [PATCH 7/7] Change WIN32 to MSVC --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa483ff1..133758d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ add_library(gumbo ${SRC}) target_include_directories(gumbo PUBLIC $) -if(WIN32) +if(MSVC) list(APPEND HEADERS visualc/include/strings.h) target_include_directories(gumbo PUBLIC $)