diff --git a/CMakeLists.txt b/CMakeLists.txt index a88dddd..e1c2656 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,17 @@ cmake_minimum_required(VERSION 3.8.2) project(ds VERSION 0.2.2 LANGUAGES C) +if(POLICY CMP0076) + cmake_policy(SET CMP0076 NEW) +endif() + set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED YES) set(DEFAULT_BUILD_TYPE "Release") +set(CMAKE_C_FLAGS_DEBUG "-g") +set(CMAKE_C_FLAGS_RELEASE "-O3") + set(DS_BUILD) option(DS_SHARED "Shared build" ON) option(DS_STATIC "Static build" OFF) @@ -22,10 +29,18 @@ if(DS_USE_C99) endif() if(MSVC) - add_definitions(-DNDEBUG -D_WINDOWS -D_USRDLL -DDS_EXPORTS -DDS_DLL) - add_compile_options(/W3 /Ox /Gy /Oi /TC) + add_definitions(-DNDEBUG -D_WINDOWS -D_USRDLL -DDS_EXPORTS) + add_compile_options(/W3 /Ox /Gy /Oi /TC) + + # Ref: https://skia.googlesource.com/third_party/sdl/+/refs/heads/master/CMakeLists.txt#225 + # Make sure /RTC1 is disabled, otherwise it will use functions from the CRT + foreach(flag_var + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) + string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}") + endforeach(flag_var) else() - add_compile_options(-Wall -Werror -O3) + add_compile_options(-Wall -Wextra -O3 -Wstrict-aliasing=2 -Wno-overlength-strings -Wmissing-declarations) endif() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) @@ -58,6 +73,12 @@ add_library(${PROJECT_NAME} src/sort/sort.c ) +if(DS_SHARED) + add_definitions(-DDS_EXPORTS) +else() + target_compile_definitions(${PROJECT_NAME} PUBLIC -DDS_STATIC) +endif() + set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})