Skip to content

Commit

Permalink
Simplify CMake build for portability.
Browse files Browse the repository at this point in the history
Include http_parser in third_party since it does not
have a CMake buildfile.

Fetch abseil at build time since it's not in most third-party
repositories and we always link it statically as well, and because
the CMake build is the most usable.

Use the same mechanism to build gtest using CMake.
  • Loading branch information
gbrail committed Apr 15, 2020
1 parent 954618b commit 082f54b
Show file tree
Hide file tree
Showing 25 changed files with 8,714 additions and 31 deletions.
25 changes: 20 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
cmake_minimum_required(VERSION 3.13)
project(Forest)
include(ExternalProject)
include(FetchContent)
enable_testing()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS -Wall)

ExternalProject_Add(
FetchContent_Declare(
gtest
PREFIX gtest
URL https://github.com/google/googletest/archive/release-1.10.0.tar.gz
URL_HASH SHA256=9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb
INSTALL_COMMAND ""
)
FetchContent_GetProperties(gtest)
if (NOT gtest_POPULATED)
FetchContent_Populate(gtest)
add_subdirectory(${gtest_SOURCE_DIR} ${gtest_BINARY_DIR})
endif()

FetchContent_Declare(
absl
URL https://github.com/abseil/abseil-cpp/archive/20200225.1.tar.gz
URL_HASH SHA256=0db0d26f43ba6806a8a3338da3e646bb581f0ca5359b3a201d8fb8e4752fd5f8
)
FetchContent_GetProperties(absl)
if (NOT absl_POPULATED)
FetchContent_Populate(absl)
add_subdirectory(${absl_SOURCE_DIR} ${absl_BINARY_DIR})
endif()

include_directories(
${CMAKE_SOURCE_DIR}
Expand All @@ -37,5 +51,6 @@ if (DEFINED ENV{EXTRA_LIB_DIR})
endif()

add_subdirectory(apib)
add_subdirectory(third_party)
add_subdirectory(third_party/base64)
add_subdirectory(third_party/http_parser)
add_subdirectory(test)
22 changes: 10 additions & 12 deletions apib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library(
common OBJECT
common
addresses.cc
apib_lines.cc
apib_rand.cc
Expand All @@ -16,20 +16,18 @@ add_library(
apib_util.h
status.h
)
target_link_libraries(common PUBLIC -lhttp_parser
-labsl_strings -labsl_str_format_internal -labsl_strings_internal
-labsl_int128 -labsl_throw_delegate -labsl_raw_logging_internal -labsl_base)
target_link_libraries(common http_parser absl::strings absl::str_format)

add_library(
cpu OBJECT
cpu
apib_cpu_generic.cc
)
target_link_libraries(cpu PUBLIC common)
target_link_libraries(cpu common)

# TODO apib_cpu_bsd for bsd, apib_cpu_proc for linux

add_library(
io OBJECT
io
apib_commandqueue.cc
apib_io_basic.cc
apib_iothread.cc
Expand All @@ -44,24 +42,24 @@ add_library(
socket.h
tlssocket.h
)
target_link_libraries(io PUBLIC common base64 -lev -lssl.1.1 -lcrypto.1.1)
target_link_libraries(io cpu common base64 -lev -lssl -lcrypto)

add_library(
mon_lib OBJECT
mon_lib
apib_mon.cc
apib_mon.h
)
target_link_libraries(mon_lib PUBLIC io)
target_link_libraries(mon_lib io)

add_executable(
apib
apib_main.cc
)
target_link_libraries(apib io cpu common base64)
target_link_libraries(apib io)

add_executable(
apibmon
apib_mon_main.cc
)
target_link_libraries(apibmon mon_lib io cpu common base64)
target_link_libraries(apibmon mon_lib io)

2 changes: 1 addition & 1 deletion apib/apib_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ limitations under the License.
#include "apib/apib_reporting.h"
#include "apib/apib_url.h"
#include "apib/apib_util.h"
#include "third_party/base64.h"
#include "third_party/base64/base64.h"

static const std::string kApibVersion = "1.2";

Expand Down
2 changes: 1 addition & 1 deletion apib/apib_oauth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ limitations under the License.
#include "apib/apib_rand.h"
#include "apib/apib_time.h"
#include "apib/apib_url.h"
#include "third_party/base64.h"
#include "third_party/base64/base64.h"

#define MAX_NUM_SIZE 256

Expand Down
83 changes: 72 additions & 11 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,96 @@
add_library(
testserver_lib OBJECT
testserver_lib
test_server.cc
test_server.h
)
target_link_libraries(testserver_lib PUBLIC common -lev -lssl.1.1 -lcrypto.1.1 -lhttp_parser)
target_link_libraries(testserver_lib io)

add_executable(
testserver
test_server_main.cc
)
target_link_libraries(testserver testserver_lib)

add_library(
keygen_lib OBJECT
keygen_lib
test_keygen.cc
test_keygen.h
)
target_link_libraries(keygen_lib PUBLIC common -lssl.1.1 -lcrypto.1.1)
target_link_libraries(keygen_lib common -lcrypto)

add_executable(
testserver
test_server_main.cc
keygen_test
test_keygen_main.cc
)
target_link_libraries(keygen_test keygen_lib gtest)
add_test(keygen_test keygen_test)

add_executable(
commandqueue_test
commandqueue_test.cc
)
target_link_libraries(commandqueue_test io gtest gtest_main)
add_test(commandqueue_test commandqueue_test)

add_executable(
lines_test
lines_test.cc
)
target_link_libraries(lines_test common gtest gtest_main)
add_test(lines_test lines_test)

add_executable(
url_test
url_test.cc
)
target_link_libraries(url_test common gtest gtest_main)
add_test(url_test url_test)

add_executable(
cpu_test
cpu_test.cc
)
target_link_libraries(cpu_test common cpu gtest)
add_test(cpu_test cpu_test)

add_executable(
reporting_test
reporting_test.cc
)
target_link_libraries(reporting_test io gtest gtest_main)
add_test(reporting_test reporting_test)

add_executable(
oauth_test
oauth_test.cc
)
target_link_libraries(oauth_test io gtest gtest_main)
add_test(oauth_test oauth_test)

add_executable(
util_test
util_test.cc
)
target_link_libraries(util_test common gtest gtest_main)
add_test(util_test util_test)

add_executable(
mon_test
mon_test.cc
)
target_link_libraries(testserver testserver_lib common)
target_link_libraries(mon_test mon_lib gtest)
add_test(mon_test mon_test)

add_executable(
iotest
io_test.cc
)
add_dependencies(iotest gtest)
target_link_libraries(iotest testserver_lib io cpu common base64 -lgtest)
target_link_libraries(iotest testserver_lib gtest)
add_test(iotest iotest)

add_executable(
tlstest
tls_test.cc
)
add_dependencies(tlstest gtest)
target_link_libraries(tlstest testserver_lib io cpu common keygen_lib base64 -lgtest)
target_link_libraries(tlstest testserver_lib keygen_lib gtest)
add_test(tlstest tlstest)
4 changes: 3 additions & 1 deletion test/url_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ TEST(URL, ParseLocalhost) {

TEST(URL, ParseFile) {
apib::RandomGenerator rand;
EXPECT_TRUE(URLInfo::InitFile("test/data/urls.txt").ok());
if (!URLInfo::InitFile("test/data/urls.txt").ok()) {
ASSERT_TRUE(URLInfo::InitFile("../../test/data/urls.txt").ok());
}
for (int i = 0; i < 10000; i++) {
const URLInfo* u = URLInfo::GetNext(&rand);
ASSERT_NE(nullptr, u);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions third_party/http_parser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/out/
core
tags
*.o
test
test_g
test_fast
bench
url_parser
parsertrace
parsertrace_g
*.mk
*.Makefile
*.so.*
*.exe.*
*.exe
*.a


# Visual Studio uglies
*.suo
*.sln
*.vcxproj
*.vcxproj.filters
*.vcxproj.user
*.opensdf
*.ncrunchsolution*
*.sdf
*.vsp
*.psess
8 changes: 8 additions & 0 deletions third_party/http_parser/.mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# update AUTHORS with:
# git log --all --reverse --format='%aN <%aE>' | perl -ne 'BEGIN{print "# Authors ordered by first contribution.\n"} print unless $h{$_}; $h{$_} = 1' > AUTHORS
Ryan Dahl <[email protected]>
Salman Haq <[email protected]>
Simon Zimmermann <[email protected]>
Thomas LE ROUX <[email protected]> LE ROUX Thomas <[email protected]>
Thomas LE ROUX <[email protected]> Thomas LE ROUX <[email protected]>
Fedor Indutny <[email protected]>
13 changes: 13 additions & 0 deletions third_party/http_parser/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: c

compiler:
- clang
- gcc

script:
- "make"

notifications:
email: false
irc:
- "irc.freenode.net#node-ci"
68 changes: 68 additions & 0 deletions third_party/http_parser/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Authors ordered by first contribution.
Ryan Dahl <[email protected]>
Jeremy Hinegardner <[email protected]>
Sergey Shepelev <[email protected]>
Joe Damato <[email protected]>
tomika <[email protected]>
Phoenix Sol <[email protected]>
Cliff Frey <[email protected]>
Ewen Cheslack-Postava <[email protected]>
Santiago Gala <[email protected]>
Tim Becker <[email protected]>
Jeff Terrace <[email protected]>
Ben Noordhuis <[email protected]>
Nathan Rajlich <[email protected]>
Mark Nottingham <[email protected]>
Aman Gupta <[email protected]>
Tim Becker <[email protected]>
Sean Cunningham <[email protected]>
Peter Griess <[email protected]>
Salman Haq <[email protected]>
Cliff Frey <[email protected]>
Jon Kolb <[email protected]>
Fouad Mardini <[email protected]>
Paul Querna <[email protected]>
Felix Geisendörfer <[email protected]>
koichik <[email protected]>
Andre Caron <[email protected]>
Ivo Raisr <[email protected]>
James McLaughlin <[email protected]>
David Gwynne <[email protected]>
Thomas LE ROUX <[email protected]>
Randy Rizun <[email protected]>
Andre Louis Caron <[email protected]>
Simon Zimmermann <[email protected]>
Erik Dubbelboer <[email protected]>
Martell Malone <[email protected]>
Bertrand Paquet <[email protected]>
BogDan Vatra <[email protected]>
Peter Faiman <[email protected]>
Corey Richardson <[email protected]>
Tóth Tamás <[email protected]>
Cam Swords <[email protected]>
Chris Dickinson <[email protected]>
Uli Köhler <[email protected]>
Charlie Somerville <[email protected]>
Patrik Stutz <[email protected]>
Fedor Indutny <[email protected]>
runner <[email protected]>
Alexis Campailla <[email protected]>
David Wragg <[email protected]>
Vinnie Falco <[email protected]>
Alex Butum <[email protected]>
Rex Feng <[email protected]>
Alex Kocharin <[email protected]>
Mark Koopman <[email protected]>
Helge Heß <[email protected]>
Alexis La Goutte <[email protected]>
George Miroshnykov <[email protected]>
Maciej Małecki <[email protected]>
Marc O'Morain <[email protected]>
Jeff Pinner <[email protected]>
Timothy J Fontaine <[email protected]>
Akagi201 <[email protected]>
Romain Giraud <[email protected]>
Jay Satiro <[email protected]>
Arne Steen <[email protected]>
Kjell Schubert <[email protected]>
Olivier Mengué <[email protected]>
9 changes: 9 additions & 0 deletions third_party/http_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_library(
http_parser
http_parser.c
http_parser.h
)
target_compile_definitions(
http_parser PUBLIC
HTTP_PARSER_STRICT=0
)
19 changes: 19 additions & 0 deletions third_party/http_parser/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright Joyent, Inc. and other Node contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
Loading

0 comments on commit 082f54b

Please sign in to comment.