generated from ut-issl/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
common.cmake
70 lines (64 loc) · 2.5 KB
/
common.cmake
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
if(BUILD_C2A_AS_CXX)
# memo: set_source_files_properties() must be set before add_library/add_executable on Visual Studio CMake
set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++
else()
if(BUILD_C2A_AS_C99)
set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99) # C99
else()
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
# TODO: remove this!
# -Wno-commentが`std=c90`の後に来る必要があるのでC89のうちはこうするしかない
target_compile_options(${PROJECT_NAME} PUBLIC "-std=c90")
else()
set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 90) # C89
# TODO: set always!
# GNU拡張を禁止すると1行コメントがエラーになる
if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU")
set_target_properties(${PROJECT_NAME} PROPERTIES C_EXTENSIONS FALSE) # no extensions(GNU)
endif()
endif()
endif()
endif()
if(BUILD_C2A_AS_SILS_FW)
target_compile_definitions(${PROJECT_NAME} PUBLIC SILS_FW)
endif()
# Build option
if(MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC "/W4")
target_compile_options(${PROJECT_NAME} PUBLIC "/MT")
if(BUILD_C2A_AS_CXX)
target_compile_options(${PROJECT_NAME} PUBLIC "/TP") # Compile C codes as C++
endif()
if(BUILD_C2A_AS_UTF8)
target_compile_options(${PROJECT_NAME} PUBLIC "/source-charset:utf-8")
endif()
# warning
target_compile_options(${PROJECT_NAME} PRIVATE /wd4083) # disable #pragma SECTION REPRO warning
target_compile_options(${PROJECT_NAME} PRIVATE /wd4081) # disable #pragma section (EOF)
else()
# SJIS
# if (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
# target_compile_options(${PROJECT_NAME} PUBLIC "-finput-charset=cp932")
# endif()
# 32bit
if(NOT USE_32BIT_COMPILER)
target_compile_options(${PROJECT_NAME} PUBLIC "-m32")
target_link_options(${PROJECT_NAME} PRIVATE "-m32")
endif()
# debug
target_compile_options(${PROJECT_NAME} PUBLIC "-g")
# warning
target_compile_options(${PROJECT_NAME} PUBLIC "-Wpedantic")
target_compile_options(${PROJECT_NAME} PUBLIC "-Wall")
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
# gccの-Wcommentは2重コメントにしか影響しない
target_compile_options(${PROJECT_NAME} PUBLIC "-Wno-comment")
endif()
target_compile_options(${PROJECT_NAME} PUBLIC "-Wno-unknown-pragmas")
if(ADD_WERROR_FLAGS)
target_compile_options(${PROJECT_NAME} PUBLIC "-Werror")
endif()
if(ADD_WEXTRA_FLAGS)
target_compile_options(${PROJECT_NAME} PUBLIC "-Wextra")
endif()
endif()