Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Add CMake build. #396

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ 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
- python python/gumbo/html5lib_adapter_test.py
Expand Down
126 changes: 126 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
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/parser.h
src/string_buffer.h
src/string_piece.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)

add_library(gumbo ${SRC})
target_include_directories(gumbo PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)

if(WIN32)
Copy link

@NikitaFeodonit NikitaFeodonit Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be so:

if(MSVC)

For example, MinGW is GNU compiler with WIN32=true, and it does not need the file 'visualc/include/strings.h'.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thank you.

list(APPEND HEADERS visualc/include/strings.h)
target_include_directories(gumbo PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/visualc/include>)
endif()

# Installation (https://github.com/forexample/package-example)

# Layout. This works for all platforms:
# * <prefix>/lib/cmake/<PROJECT-NAME>
# * <prefix>/lib/
# * <prefix>/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 '<PROJECT-NAME>ConfigVersion.cmake'
# Use:
# * PROJECT_VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)

# Configure '<PROJECT-NAME>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:
# * <prefix>/lib/libgumbo.a
# * header location after install: <prefix>/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 -> <prefix>/include/gumbo.h
install(
FILES ${HEADERS}
DESTINATION "${include_install_dir}"
)

# Config
# * <prefix>/lib/cmake/gumbo/gumboConfig.cmake
# * <prefix>/lib/cmake/gumbo/gumboConfigVersion.cmake
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)

# Config
# * <prefix>/lib/cmake/gumbo/gumboTargets.cmake
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)

include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
4 changes: 4 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
19 changes: 19 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set(GTEST_ROOT "${PROJECT_SOURCE_DIR}/third_party/gtest")
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)