This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental CMake support (#238)
This addresses #86
- Loading branch information
Showing
23 changed files
with
869 additions
and
11 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Specify structure for custom cmake functions | ||
additional_commands = { | ||
"opencensus_lib": { | ||
"flags": [ | ||
"PUBLIC", | ||
], | ||
"kwargs": { | ||
"HEADERS": "*", | ||
"DEPENDS": "*", | ||
"SOURCES": "*" | ||
} | ||
} | ||
} | ||
|
||
# If comment markup is enabled, don't reflow the first comment block in | ||
# eachlistfile. Use this to preserve formatting of your | ||
# copyright/licensestatements. | ||
first_comment_is_literal = True |
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,43 @@ | ||
# Copyright 2018, OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
cmake_minimum_required(VERSION 3.5) | ||
|
||
# Use ccache if it's present. | ||
find_program(CCACHE_PROGRAM ccache) | ||
if(CCACHE_PROGRAM) | ||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") | ||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_PROGRAM}") | ||
endif() | ||
|
||
project(opencensus-cpp VERSION 0.3.0 LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(OPENCENSUS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") | ||
|
||
include(CTest) # Defines option BUILD_TESTING. | ||
enable_testing() | ||
|
||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) | ||
include(OpenCensusDeps) | ||
include(OpenCensusHelpers) | ||
|
||
# OpenCensus code. | ||
add_subdirectory(opencensus) | ||
|
||
# Example code only if testing is enabled. | ||
if(BUILD_TESTING) | ||
add_subdirectory(examples) | ||
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,60 @@ | ||
# Copyright 2018, OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
if(BUILD_TESTING) | ||
if(NOT TARGET gtest_main) | ||
message(STATUS "Dependency: googletest (BUILD_TESTING=${BUILD_TESTING})") | ||
|
||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/googletest.CMakeLists.txt | ||
${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt) | ||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . | ||
RESULT_VARIABLE result | ||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download) | ||
if(result) | ||
message(FATAL_ERROR "CMake step failed: ${result}") | ||
endif() | ||
execute_process(COMMAND ${CMAKE_COMMAND} --build . | ||
RESULT_VARIABLE result | ||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download) | ||
if(result) | ||
message(FATAL_ERROR "Build step failed: ${result}") | ||
endif() | ||
|
||
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src | ||
${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL) | ||
endif() | ||
endif() | ||
|
||
# Load abseil second, it depends on googletest. | ||
if(NOT TARGET absl::base) | ||
message(STATUS "Dependency: abseil") | ||
|
||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/abseil.CMakeLists.txt | ||
${CMAKE_BINARY_DIR}/abseil-download/CMakeLists.txt) | ||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . | ||
RESULT_VARIABLE result | ||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/abseil-download) | ||
if(result) | ||
message(FATAL_ERROR "CMake step failed: ${result}") | ||
endif() | ||
execute_process(COMMAND ${CMAKE_COMMAND} --build . | ||
RESULT_VARIABLE result | ||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/abseil-download) | ||
if(result) | ||
message(FATAL_ERROR "Build step failed: ${result}") | ||
endif() | ||
|
||
add_subdirectory(${CMAKE_BINARY_DIR}/abseil-src | ||
${CMAKE_BINARY_DIR}/abseil-build EXCLUDE_FROM_ALL) | ||
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,59 @@ | ||
# Copyright 2018, OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Prepends opencensus_ to all deps that aren't in a :: namespace. | ||
function(prepend_opencensus OUT DEPS) | ||
set(_DEPS "") | ||
foreach(dep ${DEPS}) | ||
if("${dep}" MATCHES "::") | ||
list(APPEND _DEPS "${dep}") | ||
else() | ||
list(APPEND _DEPS "opencensus_${dep}") | ||
endif() | ||
endforeach() | ||
set(${OUT} ${_DEPS} PARENT_SCOPE) | ||
endfunction() | ||
|
||
# Helper function like bazel's cc_test. Usage: | ||
# | ||
# opencensus_test(trace_some_test internal/some_test.cc dep1 dep2...) | ||
function(opencensus_test NAME SRC) | ||
if(BUILD_TESTING) | ||
set(_NAME "opencensus_${NAME}") | ||
add_executable(${_NAME} ${SRC}) | ||
prepend_opencensus(DEPS "${ARGN}") | ||
target_link_libraries(${_NAME} "${DEPS}" gmock gtest_main) | ||
add_test(NAME ${_NAME} COMMAND ${_NAME}) | ||
endif() | ||
endfunction() | ||
|
||
# Helper function like bazel's cc_library. Libraries are namespaced as | ||
# opencensus_* and public libraries are also aliased as opencensus-cpp::*. | ||
function(opencensus_lib NAME) | ||
cmake_parse_arguments(ARG "PUBLIC" "" "SRCS;DEPS" ${ARGN}) | ||
set(_NAME "opencensus_${NAME}") | ||
prepend_opencensus(ARG_DEPS "${ARG_DEPS}") | ||
if(ARG_SRCS) | ||
add_library(${_NAME} ${ARG_SRCS}) | ||
target_link_libraries(${_NAME} PUBLIC ${ARG_DEPS}) | ||
target_include_directories(${_NAME} PUBLIC ${OPENCENSUS_INCLUDE_DIR}) | ||
else() | ||
add_library(${_NAME} INTERFACE) | ||
target_link_libraries(${_NAME} INTERFACE ${ARG_DEPS}) | ||
target_include_directories(${_NAME} INTERFACE ${OPENCENSUS_INCLUDE_DIR}) | ||
endif() | ||
if(ARG_PUBLIC) | ||
add_library(${PROJECT_NAME}::${NAME} ALIAS ${_NAME}) | ||
endif() | ||
endfunction() |
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,27 @@ | ||
# Experimental CMake support | ||
|
||
The files in this directory are mostly for dealing with dependencies. | ||
|
||
We use | ||
[ExternalProject](https://cmake.org/cmake/help/latest/module/ExternalProject.html) | ||
to download and build missing dependencies, during CMake's configuration time. | ||
|
||
Still TODO for CMake support: | ||
- Benchmarks. | ||
- Top-level examples other than helloworld. | ||
- Leaf examples (e.g. trace/examples/ dir). | ||
- Exporters other than stdout. | ||
- CI (Travis) support. | ||
- No shared library for now. | ||
|
||
## Quickstart: | ||
|
||
```shell | ||
cmake -H. -B.build | ||
cmake --build .build | ||
(cd .build && ctest --output-on-failure) | ||
./.build/examples/helloworld/opencensus_examples_helloworld | ||
``` | ||
|
||
Using `.build` as the build dir so that it doesn't collide with the uppercase | ||
BUILD file on Windows. |
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,32 @@ | ||
# Copyright 2018, OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project(abseil-download NONE) | ||
|
||
include(ExternalProject) | ||
ExternalProject_Add(abseil_project | ||
GIT_REPOSITORY https://github.com/abseil/abseil-cpp | ||
GIT_TAG "master" | ||
SOURCE_DIR "${CMAKE_BINARY_DIR}/abseil-src" | ||
BINARY_DIR "${CMAKE_BINARY_DIR}/abseil-build" | ||
UPDATE_COMMAND "" | ||
PATCH_COMMAND "" | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
TEST_COMMAND "" | ||
LOG_DOWNLOAD ON | ||
) |
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,32 @@ | ||
# Copyright 2018, OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project(googletest-download NONE) | ||
|
||
include(ExternalProject) | ||
ExternalProject_Add(googletest_project | ||
GIT_REPOSITORY https://github.com/abseil/googletest | ||
GIT_TAG "master" | ||
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" | ||
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" | ||
UPDATE_COMMAND "" | ||
PATCH_COMMAND "" | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
TEST_COMMAND "" | ||
LOG_DOWNLOAD ON | ||
) |
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,17 @@ | ||
# Copyright 2018, OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# add_subdirectory(grpc) TODO | ||
|
||
add_subdirectory(helloworld) |
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,24 @@ | ||
# Copyright 2018, OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
find_package(Threads REQUIRED) | ||
|
||
add_executable(opencensus_examples_helloworld helloworld.cc) | ||
target_link_libraries(opencensus_examples_helloworld | ||
absl::strings | ||
opencensus-cpp::exporters_stats_stdout | ||
opencensus-cpp::exporters_trace_stdout | ||
opencensus-cpp::stats | ||
opencensus-cpp::trace | ||
Threads::Threads) |
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,20 @@ | ||
# Copyright 2018, OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
add_subdirectory(common) | ||
add_subdirectory(context) | ||
add_subdirectory(exporters) | ||
add_subdirectory(stats) | ||
add_subdirectory(tags) | ||
add_subdirectory(trace) |
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,15 @@ | ||
# Copyright 2018, OpenCensus Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
add_subdirectory(internal) |
Oops, something went wrong.