Move discovery of external dependencies to cmake/vendor.cmake.

Co-authored-by: Tom Atkinson <tja.atkinson@gmail.com>
This commit is contained in:
Bartosz Taudul 2024-03-16 14:29:39 +01:00
parent a5f256ca2d
commit ee81795f26
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 277 additions and 91 deletions

247
cmake/vendor.cmake Normal file
View File

@ -0,0 +1,247 @@
# Vendor Specific CMake
# The Tracy project keeps most vendor source locally
set (ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../")
if (EXISTS ${ROOT_DIR}/vcpkg_installed/x64-windows-static/lib/pkgconfig)
message(STATUS "Using vcpkg_installed/x64-windows-static/lib/pkgconfig")
set(ENV{PKG_CONFIG_PATH} "${ROOT_DIR}/vcpkg_installed/x64-windows-static/lib/pkgconfig")
endif()
# Dependencies are taken from the system first and if not found, they are pulled with CPM and built from source
include(FindPkgConfig)
include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake)
option(DOWNLOAD_CAPSTONE "Force download capstone" ON)
option(DOWNLOAD_GLFW "Force download glfw" OFF)
option(DOWNLOAD_FREETYPE "Force download freetype" OFF)
# capstone
pkg_check_modules(CAPSTONE capstone)
if(CAPSTONE_FOUND AND NOT DOWNLOAD_CAPSTONE)
message(STATUS "Capstone found: ${CAPSTONE}")
add_library(TracyCapstone INTERFACE)
target_include_directories(TracyCapstone INTERFACE ${CAPSTONE_INCLUDE_DIRS})
target_link_libraries(TracyCapstone INTERFACE ${CAPSTONE_LINK_LIBRARIES})
else()
CPMAddPackage(
NAME capstone
GITHUB_REPOSITORY capstone-engine/capstone
GIT_TAG 5.0.1
)
add_library(TracyCapstone INTERFACE)
target_include_directories(TracyCapstone INTERFACE ${capstone_SOURCE_DIR}/include/capstone)
target_link_libraries(TracyCapstone INTERFACE capstone)
endif()
# GLFW
if(NOT USE_WAYLAND)
pkg_check_modules(GLFW glfw3)
if (GLFW_FOUND AND NOT DOWNLOAD_GLFW)
add_library(TracyGlfw3 INTERFACE)
target_include_directories(TracyGlfw3 INTERFACE ${GLFW_INCLUDE_DIRS})
target_link_libraries(TracyGlfw3 INTERFACE ${GLFW_LINK_LIBRARIES})
else()
CPMAddPackage(
NAME glfw
GITHUB_REPOSITORY glfw/glfw
GIT_TAG 3.3.9
OPTIONS
"GLFW_BUILD_EXAMPLES OFF"
"GLFW_BUILD_TESTS OFF"
"GLFW_BUILD_DOCS OFF"
"GLFW_INSTALL OFF"
)
add_library(TracyGlfw3 INTERFACE)
target_link_libraries(TracyGlfw3 INTERFACE glfw)
endif()
endif()
# freetype
pkg_check_modules(FREETYPE freetype2)
if (FREETYPE_FOUND AND NOT DOWNLOAD_FREETYPE)
add_library(TracyFreetype INTERFACE)
target_include_directories(TracyFreetype INTERFACE ${FREETYPE_INCLUDE_DIRS})
target_link_libraries(TracyFreetype INTERFACE ${FREETYPE_LINK_LIBRARIES})
else()
CPMAddPackage(
NAME freetype
GITHUB_REPOSITORY freetype/freetype
GIT_TAG VER-2-10-0
OPTIONS
"FT_DISABLE_HARFBUZZ ON"
"FT_WITH_HARFBUZZ OFF"
)
add_library(TracyFreetype INTERFACE)
target_link_libraries(TracyFreetype INTERFACE freetype)
endif()
# zstd
set(ZSTD_DIR "${ROOT_DIR}/zstd")
set(ZSTD_SOURCES
decompress/zstd_ddict.c
decompress/zstd_decompress_block.c
decompress/huf_decompress.c
decompress/zstd_decompress.c
common/zstd_common.c
common/error_private.c
common/xxhash.c
common/entropy_common.c
common/debug.c
common/threading.c
common/pool.c
common/fse_decompress.c
compress/zstd_ldm.c
compress/zstd_compress_superblock.c
compress/zstd_opt.c
compress/zstd_compress_sequences.c
compress/fse_compress.c
compress/zstd_double_fast.c
compress/zstd_compress.c
compress/zstd_compress_literals.c
compress/hist.c
compress/zstdmt_compress.c
compress/zstd_lazy.c
compress/huf_compress.c
compress/zstd_fast.c
dictBuilder/zdict.c
dictBuilder/cover.c
dictBuilder/divsufsort.c
dictBuilder/fastcover.c
# Assembly
decompress/huf_decompress_amd64.S
)
list(TRANSFORM ZSTD_SOURCES PREPEND "${ZSTD_DIR}/")
set_property(SOURCE ${ZSTD_DIR}/decompress/huf_decompress_amd64.S APPEND PROPERTY COMPILE_OPTIONS "-x" "assembler-with-cpp")
add_library(TracyZstd STATIC ${ZSTD_SOURCES})
target_include_directories(TracyZstd PUBLIC ${ZSTD_DIR})
# Diff Template Library
set(DTL_DIR "${ROOT_DIR}/dtl")
file(GLOB_RECURSE DTL_HEADERS CONFIGURE_DEPENDS RELATIVE ${DTL_DIR} "*.hpp")
add_library(TracyDtl INTERFACE)
target_sources(TracyDtl INTERFACE ${DTL_HEADERS})
target_include_directories(TracyDtl INTERFACE ${DTL_DIR})
# Get Opt
set(GETOPT_DIR "${ROOT_DIR}/getopt")
set(GETOPT_SOURCES ${GETOPT_DIR}/getopt.c)
set(GETOPT_HEADERS ${GETOPT_DIR}/getopt.h)
add_library(TracyGetOpt STATIC ${GETOPT_SOURCES} ${GETOPT_HEADERS})
target_include_directories(TracyGetOpt PUBLIC ${GETOPT_DIR})
# ImGui
set(IMGUI_DIR "${ROOT_DIR}/imgui")
set(IMGUI_SOURCES
imgui_widgets.cpp
imgui_draw.cpp
imgui_demo.cpp
imgui.cpp
imgui_tables.cpp
misc/freetype/imgui_freetype.cpp
)
list(TRANSFORM IMGUI_SOURCES PREPEND "${IMGUI_DIR}/")
add_definitions(-DIMGUI_ENABLE_FREETYPE)
add_library(TracyImGui STATIC ${IMGUI_SOURCES})
target_include_directories(TracyImGui PUBLIC ${IMGUI_DIR})
target_link_libraries(TracyImGui PUBLIC TracyFreetype)
if (NOT USE_WAYLAND)
target_link_libraries(TracyImGui PUBLIC TracyGlfw3)
endif()
# NFD
if (NOT NO_FILESELECTOR)
set(NFD_DIR "${ROOT_DIR}/nfd")
if (WIN32)
set(NFD_SOURCES "${NFD_DIR}/nfd_win.cpp")
elseif (APPLE)
set(NFD_SOURCES "${NFD_DIR}/nfd_cocoa.m")
else()
if (GTK_FILESELECTOR)
set(NFD_SOURCES "${NFD_DIR}/nfd_gtk.cpp")
else()
set(NFD_SOURCES "${NFD_DIR}/nfd_portal.cpp")
endif()
endif()
file(GLOB_RECURSE NFD_HEADERS CONFIGURE_DEPENDS RELATIVE ${NFD_DIR} "*.h")
add_library(TracyNfd STATIC ${NFD_SOURCES} ${NFD_HEADERS})
target_include_directories(TracyNfd PUBLIC ${NFD_DIR})
if (APPLE)
find_library(APPKIT_LIBRARY AppKit)
find_library(UNIFORMTYPEIDENTIFIERS_LIBRARY UniformTypeIdentifiers)
target_link_libraries(TracyNfd PUBLIC ${APPKIT_LIBRARY} ${UNIFORMTYPEIDENTIFIERS_LIBRARY})
endif()
if (UNIX)
if (TRACY_GTK_FILESELECTOR)
pkg_check_modules(GTK3 gtk+-3.0)
if (NOT GTK3_FOUND)
message(FATAL_ERROR "GTK3 not found. Please install it or set TRACY_GTK_FILESELECTOR to OFF.")
endif()
add_library(TracyGtk3 INTERFACE)
target_include_directories(TracyGtk3 INTERFACE ${GTK3_INCLUDE_DIRS})
target_link_libraries(TracyGtk3 INTERFACE ${GTK3_LINK_LIBRARIES})
target_link_libraries(TracyNfd PUBLIC TracyGtk3)
else()
pkg_check_modules(DBUS dbus-1)
if (NOT DBUS_FOUND)
message(FATAL_ERROR "D-Bus not found. Please install it or set TRACY_GTK_FILESELECTOR to ON.")
endif()
add_library(TracyDbus INTERFACE)
target_include_directories(TracyDbus INTERFACE ${DBUS_INCLUDE_DIRS})
target_link_libraries(TracyDbus INTERFACE ${DBUS_LINK_LIBRARIES})
target_link_libraries(TracyNfd PUBLIC TracyDbus)
endif()
endif()
endif()
# TBB
if (UNIX)
# Tracy does not use TBB directly, but the implementation of parallel algorithms
# in some versions of libstdc++ depends on TBB. When it does, you must
# explicitly link against -ltbb.
#
# Some distributions have pgk-config files for TBB, others don't.
pkg_check_modules(TBB tbb)
if (TBB_FOUND)
add_library(TracyTbb INTERFACE)
target_include_directories(TracyTbb INTERFACE ${TBB_INCLUDE_DIRS})
target_link_libraries(TracyTbb INTERFACE ${TBB_LINK_LIBRARIES})
else()
CPMAddPackage(
NAME tbb
GITHUB_REPOSITORY oneapi-src/oneTBB
GIT_TAG v2021.12.0-rc2
OPTIONS "TBB_TEST OFF"
)
add_library(TracyTbb INTERFACE)
target_link_libraries(TracyTbb INTERFACE tbb)
endif()
endif()

View File

@ -3,10 +3,9 @@ cmake_minimum_required(VERSION 3.16)
option(NO_FILESELECTOR "Disable the file selector") option(NO_FILESELECTOR "Disable the file selector")
option(GTK_FILESELECTOR "Use the GTK file selector on Linux instead of the xdg-portal one") option(GTK_FILESELECTOR "Use the GTK file selector on Linux instead of the xdg-portal one")
option(LEGACY "Instead of Wayland, use the legacy X11 backend on Linux") option(LEGACY "Instead of Wayland, use the legacy X11 backend on Linux")
option(NO_ISA_EXTENSIONS "Disable ISA extensions (don't pass -march=native or -mcpu=native to the compiler)")
find_package(PkgConfig REQUIRED) include(${CMAKE_CURRENT_LIST_DIR}/../cmake/version.cmake)
include(../cmake/version.cmake)
set(TRACY_VERSION_MAJOR ${major}) set(TRACY_VERSION_MAJOR ${major})
set(TRACY_VERSION_MINOR ${minor}) set(TRACY_VERSION_MINOR ${minor})
@ -21,13 +20,31 @@ project(
VERSION ${TRACY_VERSION_STRING} VERSION ${TRACY_VERSION_STRING}
) )
include(CheckCXXCompilerFlag) if (NOT NO_ISA_EXTENSIONS)
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) include(CheckCXXCompilerFlag)
if(COMPILER_SUPPORTS_MARCH_NATIVE) if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
CHECK_CXX_COMPILER_FLAG("-mcpu=native" COMPILER_SUPPORTS_MCPU_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=native")
endif()
else()
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
endif()
endif()
endif() endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT LEGACY)
set(USE_WAYLAND ON)
else()
set(USE_WAYLAND OFF)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/vendor.cmake)
set(COMMON_FILES set(COMMON_FILES
../public/common/tracy_lz4.cpp ../public/common/tracy_lz4.cpp
../public/common/tracy_lz4hc.cpp ../public/common/tracy_lz4hc.cpp
@ -97,39 +114,6 @@ set(SERVER_FILES
../server/TracyWorker.cpp ../server/TracyWorker.cpp
) )
set(ZSTD_FILES
../zstd/common/debug.c
../zstd/common/entropy_common.c
../zstd/common/error_private.c
../zstd/common/fse_decompress.c
../zstd/common/pool.c
../zstd/common/threading.c
../zstd/common/xxhash.c
../zstd/common/zstd_common.c
../zstd/compress/fse_compress.c
../zstd/compress/hist.c
../zstd/compress/huf_compress.c
../zstd/compress/zstd_compress.c
../zstd/compress/zstd_compress_literals.c
../zstd/compress/zstd_compress_sequences.c
../zstd/compress/zstd_compress_superblock.c
../zstd/compress/zstd_double_fast.c
../zstd/compress/zstd_fast.c
../zstd/compress/zstd_lazy.c
../zstd/compress/zstd_ldm.c
../zstd/compress/zstd_opt.c
../zstd/compress/zstdmt_compress.c
../zstd/decompress/huf_decompress.c
../zstd/decompress/huf_decompress_amd64.S
../zstd/decompress/zstd_ddict.c
../zstd/decompress/zstd_decompress.c
../zstd/decompress/zstd_decompress_block.c
../zstd/dictBuilder/cover.c
../zstd/dictBuilder/divsufsort.c
../zstd/dictBuilder/fastcover.c
../zstd/dictBuilder/zdict.c
)
set(PROFILER_FILES set(PROFILER_FILES
src/imgui/imgui_impl_opengl3.cpp src/imgui/imgui_impl_opengl3.cpp
src/ConnectionHistory.cpp src/ConnectionHistory.cpp
@ -147,38 +131,9 @@ set(PROFILER_FILES
src/winmainArchDiscovery.cpp src/winmainArchDiscovery.cpp
) )
set(IMGUI_FILES
../imgui/misc/freetype/imgui_freetype.cpp
../imgui/imgui_demo.cpp
../imgui/imgui_draw.cpp
../imgui/imgui_tables.cpp
../imgui/imgui_widgets.cpp
../imgui/imgui.cpp
)
set(INCLUDES "") set(INCLUDES "")
set(LIBS "") set(LIBS "")
set(NFD_FILES)
if(NO_FILESELECTOR)
add_compile_definitions(TRACY_NO_FILESELECTOR)
else()
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
enable_language(OBJC)
set(NFD_FILES ../nfd/nfd_cocoa.m)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT GTK_FILESELECTOR)
pkg_check_modules(DBUS REQUIRED dbus-1)
set(INCLUDES "${INCLUDES};${DBUS_INCLUDE_DIRS}")
set(LIBS "${LIBS};${DBUS_LIBRARIES}")
set(NFD_FILES ../nfd/nfd_portal.cpp)
else()
pkg_check_modules(GTK REQUIRED gtk+-3.0)
set(INCLUDES "${INCLUDES};${GTK_INCLUDE_DIRS}")
set(LIBS "${LIBS};${GTK_LIBRARIES}")
set(NFD_FILES ../nfd/nfd_gtk.cpp)
endif()
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT LEGACY) if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT LEGACY)
pkg_check_modules(WAYLAND REQUIRED egl wayland-egl wayland-cursor xkbcommon) pkg_check_modules(WAYLAND REQUIRED egl wayland-egl wayland-cursor xkbcommon)
set(INCLUDES "${INCLUDES};${WAYLAND_INCLUDE_DIRS}") set(INCLUDES "${INCLUDES};${WAYLAND_INCLUDE_DIRS}")
@ -189,30 +144,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT LEGACY)
src/wayland/xdg-decoration.c src/wayland/xdg-decoration.c
src/wayland/xdg-shell.c src/wayland/xdg-shell.c
) )
else()
pkg_check_modules(GLFW REQUIRED glfw3)
set(INCLUDES "${INCLUDES};${GLFW_INCLUDE_DIRS}")
set(LIBS "${LIBS};${GLFW_LIBRARIES}")
set(PROFILER_FILES ${PROFILER_FILES}
src/BackendGlfw.cpp
src/imgui/imgui_impl_glfw.cpp
)
endif()
pkg_check_modules(DEPS REQUIRED capstone freetype2)
set(INCLUDES "${INCLUDES};${DEPS_INCLUDE_DIRS}")
set(LIBS "${LIBS};${DEPS_LIBRARIES}")
pkg_check_modules(DEPSOPT tbb)
if(DEPSOPT_FOUND)
set(INCLUDES "${INCLUDES};${DEPSOPT_INCLUDE_DIRS}")
set(LIBS "${LIBS};${DEPSOPT_LIBRARIES}")
endif() endif()
include_directories(${INCLUDES}) include_directories(${INCLUDES})
link_libraries(${LIBS}) link_libraries(${LIBS})
include_directories(../imgui) add_executable(${PROJECT_NAME} ${PROFILER_FILES} ${COMMON_FILES} ${SERVER_FILES})
add_compile_definitions(IMGUI_ENABLE_FREETYPE) target_link_libraries(${PROJECT_NAME} PRIVATE TracyImGui TracyCapstone TracyZstd TracyNfd)
add_executable(${PROJECT_NAME} ${PROFILER_FILES} ${IMGUI_FILES} ${COMMON_FILES} ${SERVER_FILES} ${ZSTD_FILES} ${NFD_FILES}) if (UNIX)
target_link_libraries(${PROJECT_NAME} PRIVATE TracyTbb)
endif()