From 1f7656e8454ae96f1657cf91abe8b01dc667689c Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Wed, 31 Aug 2022 18:06:51 +0200 Subject: [PATCH] CMake: Add option to explicitly set lib type With this new option, it is now possible to explicitly build Tracy as a shared or static library independent from the BUILD_SHARED_LIBS variable, which always acts on a global scope (thus, affecting all CMake targets). If the options is not explicitly given, it will default to whatever BUILD_SHARED_LIBS would indicate, leaving the default behavior unchanged. --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c85d266e..d1dee59f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,19 @@ cmake_minimum_required(VERSION 3.10) project(Tracy LANGUAGES CXX) +option(TRACY_STATIC "Whether to build Tracy as a static library" NOT ${BUILD_SHARED_LIBS}) + find_package(Threads REQUIRED) set(TRACY_PUBLIC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/public) -add_library(TracyClient "${TRACY_PUBLIC_DIR}/TracyClient.cpp") +if(TRACY_STATIC) + set(TRACY_VISIBILITY "STATIC") +else() + set(TRACY_VISIBILITY "SHARED") +endif() + +add_library(TracyClient ${TRACY_VISIBILITY} "${TRACY_PUBLIC_DIR}/TracyClient.cpp") target_compile_features(TracyClient PUBLIC cxx_std_11) target_include_directories(TracyClient SYSTEM PUBLIC $ @@ -62,7 +70,7 @@ set_option(TRACY_FIBERS "Enable fibers support" OFF) set_option(TRACY_NO_CRASH_HANDLER "Disable crash handling" OFF) set_option(TRACY_TIMER_FALLBACK "Use lower resolution timers" OFF) -if(BUILD_SHARED_LIBS) +if(NOT TRACY_STATIC) target_compile_definitions(TracyClient PRIVATE TRACY_EXPORTS) target_compile_definitions(TracyClient PUBLIC TRACY_IMPORTS) endif()