1# HawkTracer requires threads 2find_package(Threads REQUIRED) 3# include ExternalProject module 4include(ExternalProject) 5 6# This is optonal, only if you want to build HawkTracer as static lib 7set(HT_BUILD_STATIC ON) 8 9# Add new project. You can find more options in CMake documentation: 10# https://cmake.org/cmake/help/v3.0/module/ExternalProject.html 11ExternalProject_Add(HawkTracerExt 12 GIT_REPOSITORY https://github.com/amzn/hawktracer.git 13 GIT_TAG master # Git ref of the project. It could be commit hash, branch name or tag. 14 INSTALL_COMMAND "" # we don't want to install the library, just build it 15 CMAKE_ARGS "-DBUILD_STATIC_LIB=${HT_BUILD_STATIC}" 16 ) 17 18# If we build library statically, the output file has different name 19if(HT_BUILD_STATIC) 20 set(HT_LIB_FILE_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}hawktracer${CMAKE_STATIC_LIBRARY_SUFFIX}") 21else() 22 set(HT_LIB_FILE_NAME "${CMAKE_SHARED_LIBRARY_PREFIX}hawktracer${CMAKE_SHARED_LIBRARY_SUFFIX}") 23endif() 24 25# Get some properties from the project 26ExternalProject_Get_Property(HawkTracerExt source_dir) 27ExternalProject_Get_Property(HawkTracerExt binary_dir) 28 29# This is workaround for CMake error - included directories must exist during 30# the configuration step. But CMake downloads external projects on build step, 31# so we need to create empty directories manually to trick CMake. 32set(HAWKTRACER_INCLUDE_DIRS ${source_dir}/lib/include ${binary_dir}/lib/include/) 33file(MAKE_DIRECTORY ${HAWKTRACER_INCLUDE_DIRS}) 34 35# Set library path - MSVC is slightly different here. Let us know if there are 36# other special cases. 37set(HAWKTRACER_LIBS_DIRS ${binary_dir}/lib) 38if(MSVC) 39 set(HAWKTRACER_LIBRARY_PATH "${HAWKTRACER_LIBS_DIRS}/$(Configuration)/${HT_LIB_FILE_NAME}") 40else() 41 set(HAWKTRACER_LIBRARY_PATH "${HAWKTRACER_LIBS_DIRS}/${HT_LIB_FILE_NAME}") 42endif() 43 44add_library(hawktracer UNKNOWN IMPORTED) 45set_target_properties(hawktracer PROPERTIES 46 IMPORTED_LOCATION ${HAWKTRACER_LIBRARY_PATH} 47 INTERFACE_INCLUDE_DIRECTORIES "${HAWKTRACER_INCLUDE_DIRS}" 48 INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") 49 50add_dependencies(hawktracer HawkTracerExt) 51