This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 660
Add CMake build. #396
Open
isaachier
wants to merge
7
commits into
google:master
Choose a base branch
from
isaachier:cmake
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add CMake build. #396
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ffca0f8
Add CMake build.
isaachier e925588
Add CMake support for test cases.
isaachier 48cc5b3
Fix headers list.
isaachier 79ba38b
Fix Windows build and gtest usage.
d93da3d
Fix Windows include directory path.
748829a
Fix Travis CMake build.
e46ac84
Change WIN32 to MSVC
isaachier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be so:
For example, MinGW is GNU compiler with WIN32=true, and it does not need the file 'visualc/include/strings.h'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thank you.