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
Experimental CMake support #238
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3713b5a
Experimental CMake support.
g-easy 5a20ea1
Namespace all targets as opencensus_*.
g-easy c536c71
build -> .build so it doesn't collide with BUILD.
g-easy 8ffcd3f
Use CMAKE_CXX_STANDARD_REQUIRED.
g-easy 64a0a25
Split up cmake/CMakeLists.txt
g-easy d6f4b00
Remove guards, configure cmake-format instead.
g-easy 706c4df
Use ctest in quickstart.
g-easy 7c4c3ed
Merge branch 'master' into cmake
g-easy 8fb004e
Merge branch 'master' into cmake
g-easy 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
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. But this is I haven't gotten as far as adding the grpc integration yet. It will probably happen in a followup PR. |
||
|
||
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.
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.
Why not use
externalproject_add()
for googletest too?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.
I thought I was. If BUILD_TESTING is enabled, I do the usual dance starting on L19 with
configure_file
, which usescmake/googletest.CMakeLists.txt
which has theexternalproject_add()
call.