-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
54 lines (44 loc) · 1.64 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
cmake_minimum_required(VERSION 3.14)
project(libsee
VERSION 1.1.0
DESCRIPTION "See where you use LibC the most. Trace calls failing tests. Then - roast!")
# Set C standard
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED True)
# Define library source file
set(SOURCE_FILES libsee.c)
set(OUTPUT_LIB_NAME "libsee")
# Detect OS and set library extension and compilation options accordingly
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_compile_options(-fPIC -nostdlib -nostartfiles)
set(LINK_OPTIONS "-shared")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_options(-fPIC -nostdlib -nostartfiles)
set(LINK_OPTIONS "-dynamiclib")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_options(-nostdlib -nostartfiles)
set(LINK_OPTIONS "-shared")
endif()
# Add library
add_library(${OUTPUT_LIB_NAME} SHARED ${SOURCE_FILES})
# Set properties for different build types
set_target_properties(${OUTPUT_LIB_NAME} PROPERTIES PREFIX "")
# Disable using the built-in functions
add_compile_options(-fno-builtin)
# Debug or Release flags
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(DEBUG=1)
add_compile_options(-g)
else()
add_compile_options(-O2)
endif()
# Link options
target_link_options(${OUTPUT_LIB_NAME} PRIVATE ${LINK_OPTIONS})
# Add clean target for generated library
set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${OUTPUT_LIB_NAME})
# Provide option for building in debug mode (can be passed via `-DCMAKE_BUILD_TYPE=Debug` during configuration)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Building in debug mode")
else()
message(STATUS "Building in release mode")
endif()