From 7ddc6aad72f7516362bce61122d2c807a5757f49 Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Mon, 9 Sep 2024 08:00:44 +0800 Subject: [PATCH] optimize CMakeLists.txt --- CMakeLists.txt | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b286c19..417713c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,20 +20,9 @@ if (ENABLE_ASAN) -fsanitize=undefined -fno-omit-frame-pointer ) - - add_link_options( - -fsanitize=address - -fsanitize=undefined - ) message("asan is on. if have any problems, disable it.") endif () -if (WIN32) - add_link_options( - -static - ) -endif () - # For CURL set(BUILD_STATIC_LIBS ON) if (WIN32) @@ -61,4 +50,19 @@ FetchContent_MakeAvailable(cJSON curl) add_executable(main main.c) target_include_directories(main PUBLIC ${cJSON_SOURCE_DIR}) -target_link_libraries(main cjson-static libcurl_static pthread) \ No newline at end of file +target_link_libraries(main cjson-static libcurl_static pthread) + +if (ENABLE_ASAN) + target_link_options( + main BEFORE PUBLIC + -fsanitize=address + -fsanitize=undefined + ) +endif () + +if (WIN32) + target_link_options( + main BEFORE PUBLIC + -static + ) +endif () \ No newline at end of file