diff --git a/CMakeLists.txt b/CMakeLists.txt index 8acff8a8..7acc5ac8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,13 +25,27 @@ 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}") + +option(BUILD_SHARED_LIBS "Build shared libraries" OFF) + +IF(MSVC) + add_definitions(-DNOMINMAX) +ENDIF() + +if(CMAKE_BUILD_TYPE STREQUAL "Release") + option(INSTALL_HEADERS "Install header files" ON) +else() + option(INSTALL_HEADERS "Install header files" OFF) +endif() + +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) + +find_package(googletest REQUIRED) +find_package(abseil REQUIRED) include(CTest) # Defines option BUILD_TESTING. enable_testing() -list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -include(OpenCensusDeps) include(OpenCensusHelpers) # OpenCensus code. @@ -41,3 +55,10 @@ add_subdirectory(opencensus) if(BUILD_TESTING) add_subdirectory(examples) endif() + +install( + EXPORT opencensus-targets + FILE opencensus-config.cmake + NAMESPACE opencensus:: + DESTINATION share/opencensus +) \ No newline at end of file diff --git a/cmake/Findabseil.cmake b/cmake/Findabseil.cmake new file mode 100644 index 00000000..fd1a1f3b --- /dev/null +++ b/cmake/Findabseil.cmake @@ -0,0 +1,278 @@ +# Copyright 2018 The Cartographer 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.2) + +if(NOT TARGET absl_base) + set(prefix ${CMAKE_STATIC_LIBRARY_PREFIX}) + set(suffix ${CMAKE_STATIC_LIBRARY_SUFFIX}) + include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) + set(ABSEIL_PROJECT_NAME abseil) + set(ABSEIL_PROJECT_SRC_DIR + ${CMAKE_CURRENT_BINARY_DIR}/${ABSEIL_PROJECT_NAME}/src/${ABSEIL_PROJECT_NAME}) + set(ABSEIL_PROJECT_BUILD_DIR + ${CMAKE_CURRENT_BINARY_DIR}/${ABSEIL_PROJECT_NAME}/src/${ABSEIL_PROJECT_NAME}-build) + set(ABSEIL_INCLUDE_DIRS ${ABSEIL_PROJECT_SRC_DIR}) + + ExternalProject_Add(${ABSEIL_PROJECT_NAME} + PREFIX ${ABSEIL_PROJECT_NAME} + GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git + GIT_TAG 5441bbe1db5d0f2ca24b5b60166367b0966790af + INSTALL_COMMAND "" + BUILD_COMMAND ${CMAKE_COMMAND} --build "${ABSEIL_PROJECT_BUILD_DIR}" + CMAKE_CACHE_ARGS "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON;-DBUILD_TESTING:BOOL=OFF" + BUILD_BYPRODUCTS "${ABSEIL_LIBRARY_PATH};${ABSEIL_DEPENDENT_LIBRARIES}" + ) + + # absl_algorithm + + add_library(absl_algorithm STATIC IMPORTED GLOBAL) + set_target_properties(absl_algorithm + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/algorithm/${prefix}absl_algorithm${suffix} + ) + + # absl_base + + add_library(absl_base STATIC IMPORTED GLOBAL) + set_target_properties(absl_base + PROPERTIES IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/base/${prefix}absl_base${suffix} + INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_PROJECT_SRC_DIR} + ) + + set_property(TARGET absl_base + PROPERTY INTERFACE_LINK_LIBRARIES + ${ABSEIL_PROJECT_BUILD_DIR}/absl/base/${prefix}absl_dynamic_annotations${suffix} + ${ABSEIL_PROJECT_BUILD_DIR}/absl/base/${prefix}absl_malloc_internal${suffix} + ${ABSEIL_PROJECT_BUILD_DIR}/absl/base/${prefix}absl_spinlock_wait${suffix} + ${ABSEIL_PROJECT_BUILD_DIR}/absl/base/${prefix}absl_throw_delegate${suffix} + ) + + # absl_container + + add_library(absl_container STATIC IMPORTED GLOBAL) + set_target_properties(absl_container + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/container/${prefix}absl_container${suffix} + ) + set_property(TARGET absl_container + PROPERTY INTERFACE_LINK_LIBRARIES + ${ABSEIL_PROJECT_BUILD_DIR}/absl/container/${prefix}test_instance_tracker_lib${suffix} + ) + + # absl_debugging + + add_library(absl_debugging STATIC IMPORTED GLOBAL) + set_target_properties(absl_debugging + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/debugging/${prefix}absl_debugging${suffix} + ) + set_property(TARGET absl_debugging + PROPERTY INTERFACE_LINK_LIBRARIES + ${ABSEIL_PROJECT_BUILD_DIR}/absl/debugging/${prefix}absl_symbolize${suffix} + ${ABSEIL_PROJECT_BUILD_DIR}/absl/debugging/${prefix}absl_examine_stack${suffix} + ${ABSEIL_PROJECT_BUILD_DIR}/absl/debugging/${prefix}absl_failure_signal_handler${suffix} + ${ABSEIL_PROJECT_BUILD_DIR}/absl/debugging/${prefix}absl_leak_check${suffix} + ${ABSEIL_PROJECT_BUILD_DIR}/absl/debugging/${prefix}absl_stack_consumption${suffix} + ${ABSEIL_PROJECT_BUILD_DIR}/absl/debugging/${prefix}absl_stacktrace${suffix} + ) + + # absl_memory + + add_library(absl_memory STATIC IMPORTED GLOBAL) + set_target_properties(absl_memory + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/memory/${prefix}absl_memory${suffix} + ) + + # absl_meta + + add_library(absl_meta STATIC IMPORTED GLOBAL) + set_target_properties(absl_meta + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/meta/${prefix}absl_meta${suffix} + ) + + # absl_numeric + + add_library(absl_numeric STATIC IMPORTED GLOBAL) + set_target_properties(absl_numeric + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/numeric/${prefix}absl_numeric${suffix} + ) + set_property(TARGET absl_numeric + PROPERTY INTERFACE_LINK_LIBRARIES + ${ABSEIL_PROJECT_BUILD_DIR}/absl/numeric/${prefix}absl_int128${suffix} + ) + + # absl_strings + + add_library(absl_strings STATIC IMPORTED GLOBAL) + set_target_properties(absl_strings + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/strings/${prefix}absl_strings${suffix} + ) + set_property(TARGET absl_strings + PROPERTY INTERFACE_LINK_LIBRARIES + ${ABSEIL_PROJECT_BUILD_DIR}/absl/strings/${prefix}str_format_internal${suffix} + ${ABSEIL_PROJECT_BUILD_DIR}/absl/strings/${prefix}str_format_extension_internal${suffix} + ${ABSEIL_PROJECT_BUILD_DIR}/absl/strings/${prefix}absl_str_format${suffix} + ) + + # absl_synchronization + + add_library(absl_synchronization STATIC IMPORTED GLOBAL) + set_target_properties(absl_synchronization + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/synchronization/${prefix}absl_synchronization${suffix} + ) + + # absl_time + + add_library(absl_time STATIC IMPORTED GLOBAL) + set_target_properties(absl_time + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/time/${prefix}absl_time${suffix} + ) + + # absl_utility + + add_library(absl_utility STATIC IMPORTED GLOBAL) + set_target_properties(absl_utility + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/utility/${prefix}absl_utility${suffix} + ) + + # absl_span + + add_library(absl_span STATIC IMPORTED GLOBAL) + set_target_properties(absl_span + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/types/${prefix}absl_span${suffix} + ) + + # absl_optional + + add_library(absl_optional STATIC IMPORTED GLOBAL) + set_target_properties(absl_optional + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/types/${prefix}absl_optional${suffix} + ) + + # absl_variant + + add_library(absl_variant STATIC IMPORTED GLOBAL) + set_target_properties(absl_variant + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + ${ABSEIL_INCLUDE_DIRS} + IMPORTED_LOCATION + ${ABSEIL_PROJECT_BUILD_DIR}/absl/types/${prefix}absl_variant${suffix} + ) + + + # missing: absl_hash "${ABSEIL_PROJECT_BUILD_DIR}/absl/hash/${prefix}absl_hash${suffix}" + + # absl_types + + #add_library(absl_types STATIC IMPORTED GLOBAL) + #set_target_properties(absl_types + # PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + # ${ABSEIL_INCLUDE_DIRS} + #) + #set_target_properties(absl_types + # PROPERTIES INTERFACE_LINK_LIBRRARIES + # "${ABSEIL_PROJECT_BUILD_DIR}/absl/types/${prefix}absl_any${suffix} + # ${ABSEIL_PROJECT_BUILD_DIR}/absl/types/${prefix}absl_bad_any_cast${suffix} + # ${ABSEIL_PROJECT_BUILD_DIR}/absl/types/${prefix}absl_bad_optional_access${suffix} + # + # + # " + #) + #add_dependencies(absl_types ${ABSEIL_PROJECT_NAME}) + #add_library(absl::types ALIAS absl_types) + + target_link_libraries(absl_algorithm INTERFACE absl_base absl_meta) + target_link_libraries(absl_container INTERFACE absl_algorithm absl_base absl_memory) + target_link_libraries(absl_debugging INTERFACE absl_base) + target_link_libraries(absl_memory INTERFACE absl_meta) + target_link_libraries(absl_meta INTERFACE absl_base) + target_link_libraries(absl_numeric INTERFACE absl_base) + target_link_libraries(absl_strings INTERFACE absl_base absl_memory absl_meta absl_numeric) + target_link_libraries(absl_synchronization INTERFACE absl_base absl_time absl_debugging) + target_link_libraries(absl_time INTERFACE absl_base absl_numeric) + target_link_libraries(absl_utility INTERFACE absl_base absl_meta) + target_link_libraries(absl_span INTERFACE absl_base absl_utility absl_meta absl_algorithm absl_strings) + target_link_libraries(absl_optional INTERFACE absl_utility absl_meta absl_algorithm absl_strings) + target_link_libraries(absl_variant INTERFACE absl_utility absl_meta absl_algorithm absl_strings) + + add_dependencies(absl_algorithm ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_base ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_container ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_debugging ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_memory ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_meta ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_numeric ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_strings ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_synchronization ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_time ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_utility ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_span ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_optional ${ABSEIL_PROJECT_NAME}) + add_dependencies(absl_variant ${ABSEIL_PROJECT_NAME}) + + add_library(absl::algorithm ALIAS absl_algorithm) + add_library(absl::base ALIAS absl_base) + add_library(absl::container ALIAS absl_container) + add_library(absl::debugging ALIAS absl_debugging) + add_library(absl::memory ALIAS absl_memory) + add_library(absl::meta ALIAS absl_meta) + add_library(absl::numeric ALIAS absl_numeric) + add_library(absl::strings ALIAS absl_strings) + add_library(absl::synchronization ALIAS absl_synchronization) + add_library(absl::time ALIAS absl_time) + add_library(absl::utility ALIAS absl_utility) + add_library(absl::span ALIAS absl_span) + add_library(absl::optional ALIAS absl_optional) + add_library(absl::variant ALIAS absl_variant) + + unset(prefix) + unset(suffix) +endif() diff --git a/cmake/Findgoogletest.cmake b/cmake/Findgoogletest.cmake new file mode 100644 index 00000000..379b948f --- /dev/null +++ b/cmake/Findgoogletest.cmake @@ -0,0 +1,74 @@ +# Copyright 2018 The Cartographer 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.2) + +if(NOT TARGET gtest) + set(prefix ${CMAKE_STATIC_LIBRARY_PREFIX}) + set(suffix ${CMAKE_STATIC_LIBRARY_SUFFIX}) + include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) + set(GOOGLETEST_PROJECT_NAME googletest) + set(GOOGLETEST_PROJECT_SRC_DIR + "${CMAKE_CURRENT_BINARY_DIR}/${GOOGLETEST_PROJECT_NAME}-prefix/src/${GOOGLETEST_PROJECT_NAME}") + set(GOOGLETEST_PROJECT_BUILD_DIR + "${CMAKE_CURRENT_BINARY_DIR}/${GOOGLETEST_PROJECT_NAME}-prefix/src/${GOOGLETEST_PROJECT_NAME}-build") + set(GOOGLETEST_INCLUDE_DIRS ${GOOGLETEST_PROJECT_SRC_DIR}) + + include(ExternalProject) + ExternalProject_Add(${GOOGLETEST_PROJECT_NAME} + GIT_REPOSITORY https://github.com/abseil/googletest + GIT_TAG "master" + INSTALL_COMMAND "" + BUILD_COMMAND ${CMAKE_COMMAND} --build "${GOOGLETEST_PROJECT_BUILD_DIR}" + CMAKE_CACHE_ARGS "-Dgtest_force_shared_crt:BOOL=ON" + ) + + file(MAKE_DIRECTORY ${GOOGLETEST_PROJECT_SRC_DIR}/googletest/include) + file(MAKE_DIRECTORY ${GOOGLETEST_PROJECT_SRC_DIR}/googlemock/include) + + add_library(gtest STATIC IMPORTED) + set_target_properties(gtest PROPERTIES + IMPORTED_LOCATION_DEBUG ${GOOGLETEST_PROJECT_BUILD_DIR}/lib/${prefix}gtest${suffix} + IMPORTED_LOCATION_RELEASE ${GOOGLETEST_PROJECT_BUILD_DIR}/lib/${prefix}gtestd${suffix} + IMPORTED_LINK_INTERFACE_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}" + INTERFACE_INCLUDE_DIRECTORIES ${GOOGLETEST_PROJECT_SRC_DIR}/googletest/include) + add_dependencies(gtest googletest) + + add_library(gtest_main STATIC IMPORTED) + set_target_properties(gtest_main PROPERTIES + IMPORTED_LOCATION_DEBUG ${GOOGLETEST_PROJECT_BUILD_DIR}/lib/${prefix}gtest_maind${suffix} + IMPORTED_LOCATION_RELEASE ${GOOGLETEST_PROJECT_BUILD_DIR}/lib/${prefix}gtest_main${suffix} + IMPORTED_LINK_INTERFACE_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}" + INTERFACE_INCLUDE_DIRECTORIES ${GOOGLETEST_PROJECT_SRC_DIR}/googletest/include) + add_dependencies(gtest_main googletest) + + add_library(gmock STATIC IMPORTED) + set_target_properties(gmock PROPERTIES + IMPORTED_LOCATION_DEBUG ${GOOGLETEST_PROJECT_BUILD_DIR}/lib/${prefix}gmockd${suffix} + IMPORTED_LOCATION_RELEASE ${GOOGLETEST_PROJECT_BUILD_DIR}/lib/${prefix}gmock${suffix} + IMPORTED_LINK_INTERFACE_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}" + INTERFACE_INCLUDE_DIRECTORIES ${GOOGLETEST_PROJECT_SRC_DIR}/googlemock/include) + add_dependencies(gmock googletest) + + add_library(gmock_main STATIC IMPORTED) + set_target_properties(gmock_main PROPERTIES + IMPORTED_LOCATION_DEBUG ${GOOGLETEST_PROJECT_BUILD_DIR}/lib/${prefix}gmock_maind${suffix} + IMPORTED_LOCATION_RELEASE ${GOOGLETEST_PROJECT_BUILD_DIR}/lib/${prefix}gmock_main${suffix} + IMPORTED_LINK_INTERFACE_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}" + INTERFACE_INCLUDE_DIRECTORIES ${GOOGLETEST_PROJECT_SRC_DIR}/googlemock/include) + add_dependencies(gmock_main googletest) + + unset(prefix) + unset(suffix) +endif() diff --git a/cmake/OpenCensusDeps.cmake b/cmake/OpenCensusDeps.cmake deleted file mode 100644 index 4c49f167..00000000 --- a/cmake/OpenCensusDeps.cmake +++ /dev/null @@ -1,60 +0,0 @@ -# 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() diff --git a/cmake/OpenCensusHelpers.cmake b/cmake/OpenCensusHelpers.cmake index 70ca202e..259bb976 100644 --- a/cmake/OpenCensusHelpers.cmake +++ b/cmake/OpenCensusHelpers.cmake @@ -1,59 +1,78 @@ -# 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() +# 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} PRIVATE "${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" "" "HDRS;SRCS;DEPS;PRIVATE_DEPS" ${ARGN}) + set(_NAME "opencensus_${NAME}") + prepend_opencensus(ARG_DEPS "${ARG_DEPS}") + + if(ARG_SRCS) + add_library(${_NAME} ${ARG_SRCS}) + if(ARG_DEPS) + target_link_libraries(${_NAME} PUBLIC ${ARG_DEPS}) + endif() + if(ARG_PRIVATE_DEPS) + target_link_libraries(${_NAME} PRIVATE ${ARG_PRIVATE_DEPS}) + endif() + target_include_directories(${_NAME} PUBLIC $ $) + else() + add_library(${_NAME} INTERFACE) + target_link_libraries(${_NAME} INTERFACE ${ARG_DEPS}) + target_include_directories(${_NAME} INTERFACE $ $) + endif() + + if(INSTALL_HEADERS) + if(ARG_HEADERS) + message(STATUS "Arg_headers: ${ARG_HEADERS}") + foreach(header_file IN LISTS ARG_HEADERS) + get_filename_component(dir ${header_file} DIRECTORY) + install(FILES ${CMAKE_SOURCE_DIR}/${header_file} DESTINATION "include/${dir}") + endforeach() + endif() + endif() + + install(TARGETS ${_NAME} EXPORT opencensus-targets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) +endfunction() diff --git a/cmake/abseil.CMakeLists.txt b/cmake/abseil.CMakeLists.txt deleted file mode 100644 index 01e90b78..00000000 --- a/cmake/abseil.CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# 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 -) diff --git a/cmake/googletest.CMakeLists.txt b/cmake/googletest.CMakeLists.txt deleted file mode 100644 index f69cb120..00000000 --- a/cmake/googletest.CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# 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 -) diff --git a/examples/helloworld/CMakeLists.txt b/examples/helloworld/CMakeLists.txt index 456169f2..de4f36e3 100644 --- a/examples/helloworld/CMakeLists.txt +++ b/examples/helloworld/CMakeLists.txt @@ -17,8 +17,8 @@ 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 + opencensus_exporters_stats_stdout + opencensus_exporters_trace_stdout + opencensus_stats + opencensus_trace Threads::Threads) diff --git a/opencensus/stats/CMakeLists.txt b/opencensus/stats/CMakeLists.txt index 53ab1ad9..a01a1aae 100644 --- a/opencensus/stats/CMakeLists.txt +++ b/opencensus/stats/CMakeLists.txt @@ -12,10 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -opencensus_lib(stats PUBLIC DEPS stats_core stats_recording) +opencensus_lib(stats + PUBLIC + HDRS + internal/aggregation_window.h + internal/set_aggregation_window.h + stats.h + stats_exporter.h + DEPS + stats_core + stats_recording) opencensus_lib(stats_test_utils PUBLIC + HDRS + testing/test_utils.h SRCS testing/test_utils.cc DEPS