forked from thpatch/thtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·125 lines (107 loc) · 3.15 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
cmake_minimum_required(VERSION 3.0)
set(CMP0048 NEW)
project("Touhou Toolkit"
VERSION 8)
set(PROJECT_URL "https://github.com/thpatch/thtk")
set(PROJECT_BUGREPORT "chwo9843@gmail.com")
include(CheckCSourceRuns)
include(CheckTypeSize)
include(CheckIncludeFile)
include(CheckFunctionExists)
check_c_source_runs("
#include <stddef.h>
struct test_t { char a;
#pragma pack(push,1)
int b; };
#pragma pack(pop)
int main() {
return offsetof(struct test_t, b) == 1 ? 0 : 1;
}
" PACK_PRAGMA)
if (NOT ${PACK_PRAGMA})
check_c_source_runs("
#include <stddef.h>
struct test_t { char a; int b; } __attribute__((packed));
int main() {
return offsetof(struct test_t, b) == 1 ? 0 : 1;
}
" PACK_ATTRIBUTE_AVAILABLE)
if (${PACK_ATTRIBUTE_AVAILABLE})
set(PACK_ATTRIBUTE "__attribute__((packed))")
endif()
endif()
check_type_size(off_t OFF_T)
check_type_size(size_t SIZE_T)
if (NOT ${HAVE_SIZE_T})
check_c_source_runs("
#ifdef _WIN32
# include <BaseTsd.h>
typedef SIZE_T size_t;
#else
# include <sys/types.h>
#endif
int main() {
size_t test = -1;
return test>0 ? 0 : 1;
}
" HAVE_SSIZE_T_BASETSD)
endif()
check_type_size(ssize_t SSIZE_T)
if (NOT ${HAVE_SSIZE_T})
check_c_source_runs("
#ifdef _WIN32
# include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#else
# include <sys/types.h>
#endif
int main() {
ssize_t test = -1;
return test<0 ? 0 : 1;
}
" HAVE_SSIZE_T_BASETSD)
endif()
check_include_file("libgen.h" HAVE_LIBGEN_H)
check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
check_include_file("sys/mman.h" HAVE_SYS_MMAN_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
check_function_exists("_splitpath" HAVE__SPLITPATH)
check_function_exists("mempcpy" HAVE_MEMPCPY)
check_function_exists("mmap" HAVE_MMAP)
check_function_exists("munmap" HAVE_MUNMAP)
check_function_exists("feof" HAVE_FEOF)
check_function_exists("fileno" HAVE_FILENO)
check_function_exists("fread" HAVE_FREAD)
check_function_exists("fwrite" HAVE_FWRITE)
check_function_exists("getc" HAVE_GETC)
check_function_exists("putc" HAVE_PUTC)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
option(WITH_LIBPNG_SOURCE "Compile libpng from source" ON)
if(MSVC)
# Defining these here rather than in config.h.in also applies them to the
# zlib-ng and libpng build.
add_compile_options(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
else()
add_compile_options(-D_GNU_SOURCE -std=c99)
endif()
function(link_setargv target)
if(MSVC)
set_target_properties(${target} PROPERTIES LINK_FLAGS "setargv.obj")
endif()
endfunction()
if(MSVC)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT /GL /Ox /Ot")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /INCREMENTAL:NO /OPT:REF /LTCG")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /INCREMENTAL:NO /OPT:REF /LTCG")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(util)
include_directories(util)
add_subdirectory(thanm)
add_subdirectory(thdat)
add_subdirectory(thecl)
add_subdirectory(thmsg)
add_subdirectory(thtk)
configure_file(config.h.in config.h)