forked from GaijinEntertainment/daScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeCommon.txt
144 lines (136 loc) · 6.53 KB
/
CMakeCommon.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
MACRO(SOURCE_GROUP_FILES _groupName _fileNames )
STRING(REGEX REPLACE "/" "\\\\" _groupNameP ${_groupName} )
SOURCE_GROUP( ${_groupNameP} FILES ${${_fileNames}} )
SET_SOURCE_FILES_PROPERTIES( ${${_fileNames}} PROPERTIES "MY_GROUP_NAME" ${_groupNameP} )
ENDMACRO(SOURCE_GROUP_FILES)
MACRO(SETUP_LTO _targetName)
IF(APPLE)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# set_property(TARGET ${_targetName} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
ELSE()
set_property(TARGET ${_targetName} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
ENDIF()
ELSEIF(UNIX)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_property(TARGET ${_targetName} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
ENDIF()
ENDIF()
ENDMACRO()
MACRO(SETUP_COMPILER)
IF(APPLE)
ADD_DEFINITIONS(-DITS_PLATFORM_APPLE=1)
ADD_DEFINITIONS(-Wall -Wextra -pedantic)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
ADD_COMPILE_OPTIONS(-Wno-pedantic)
ADD_COMPILE_OPTIONS(-Wno-ignored-attributes)
ADD_COMPILE_OPTIONS(-Wno-unused-but-set-variable)
ADD_COMPILE_OPTIONS(-Wno-unused-parameter)
ADD_COMPILE_OPTIONS(-Wno-strict-aliasing)
ADD_COMPILE_OPTIONS(-Wno-extra)
ADD_COMPILE_OPTIONS(-Wno-unused-value)
ADD_COMPILE_OPTIONS(-Wno-unused-variable)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fno-rtti -fno-exceptions -fomit-frame-pointer -fno-stack-protector -s -DDAS_FUSION=2 -DDAS_DEBUGGER=0 -DNDEBUG=1")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -fno-rtti -fno-exceptions -fomit-frame-pointer -fno-stack-protector -s -DDAS_FUSION=1 -DDAS_DEBUGGER=0 -DNDEBUG=1")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -fno-rtti -fno-exceptions -fno-stack-protector -DDAS_FUSION=1 -DNDEBUG=1")
ELSE()
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fno-rtti -fno-exceptions -fomit-frame-pointer -fno-stack-protector -DDAS_FUSION=2 -DDAS_DEBUGGER=0 -DNDEBUG=1")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -fno-rtti -fno-exceptions -fomit-frame-pointer -fno-stack-protector -DDAS_FUSION=1 -DDAS_DEBUGGER=0 -DNDEBUG=1")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -fno-rtti -fno-exceptions -fno-stack-protector -DDAS_FUSION=1 -DNDEBUG=1")
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s")
SET(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} -s")
ENDIF()
ELSEIF(UNIX)
ADD_COMPILE_OPTIONS(-Wno-ignored-attributes)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fno-rtti -fno-exceptions -fomit-frame-pointer -fno-stack-protector -s -DDAS_FUSION=2 -DDAS_DEBUGGER=0 -DNDEBUG=1")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -fno-rtti -fno-exceptions -fomit-frame-pointer -fno-stack-protector -s -DDAS_FUSION=1 -DDAS_DEBUGGER=0 -DNDEBUG=1")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -fno-rtti -fno-exceptions -fno-stack-protector -DDAS_FUSION=1 -DNDEBUG=1")
ELSEIF(WIN32)
IF(MSVC)
ADD_COMPILE_OPTIONS(-bigobj)
ENDIF()
ADD_DEFINITIONS(-DITS_PLATFORM_WIN32=1)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
string (REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
ADD_DEFINITIONS("/W4")
IF(MSVC)
IF("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
ADD_DEFINITIONS("-DDAS_ENABLE_FPE")
ADD_DEFINITIONS("/arch:IA32")
ADD_DEFINITIONS("-D_TARGET_SIMD_SSE=2")
ENDIF()
ENDIF()
SET(CMAKE_CXX_FLAGS_RELEASE "/MD /Ot /Ox /Oi /DNDEBUG=1 /DDAS_FUSION=2 /DDAS_DEBUGGER=0 /Gy /GS- /GR- /EHa")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MD /Os /Oi /DNDEBUG=1 /DDAS_FUSION=1 /DDAS_DEBUGGER=0 /Gy /GS- /GR- /EHa")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Zi /MD /Ot /Oi /DNDEBUG=1 /DDAS_FUSION=1 /Gy /GS- /GR- /EHa")
ENDIF()
ADD_DEFINITIONS(-DSIZE_OF_VOID_P=${CMAKE_SIZEOF_VOID_P})
ENDMACRO()
MACRO(SETUP_CPP11 _targetName)
IF(APPLE)
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++17")
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_ARCHS "$(ARCHS_STANDARD_64_BIT)")
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "YES")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")
ENDIF()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -std=c++1z -stdlib=libc++")
ENDIF()
ENDMACRO()
MACRO(FIND_XXD)
find_program(XXD_BIN xxd)
ENDMACRO(FIND_XXD)
MACRO(FIND_FLEX_AND_BISON)
find_package(BISON)
find_package(FLEX)
ENDMACRO(FIND_FLEX_AND_BISON)
MACRO(XXD input)
IF(NOT XXD_BIN)
MESSAGE(STATUS "XXD not found, pre-generated files will be used." )
ELSE()
get_filename_component(input_src ${input} ABSOLUTE)
get_filename_component(input_dir ${input_src} DIRECTORY)
get_filename_component(input_name ${input} NAME)
ADD_CUSTOM_COMMAND(
DEPENDS ${input_src}
OUTPUT ${input_src}.inc
WORKING_DIRECTORY ${input_dir}
COMMAND ${XXD_BIN} -i ${input_name} ${input_name}.inc
COMMENT "compiling ${input} to c++ string")
ENDIF()
ENDMACRO()
MACRO(FLEX input)
IF(NOT FLEX_FOUND)
MESSAGE(STATUS "FLEX not found, pre-generated files will be used." )
ELSE()
get_filename_component(input_src ${input} ABSOLUTE)
get_filename_component(input_dir ${input_src} DIRECTORY)
get_filename_component(input_name ${input} NAME_WE)
get_filename_component(input_name_ext ${input} NAME)
ADD_CUSTOM_COMMAND(
DEPENDS ${input_src}
OUTPUT ${input_dir}/${input_name}.cpp
WORKING_DIRECTORY ${input_dir}
COMMAND ${FLEX_EXECUTABLE} --outfile=${input_name}.cpp ${input_name_ext}
COMMENT "flex (v ${FLEX_VERSION}) ${input} to ${input_dir}/${input_name}.cpp")
ENDIF()
ENDMACRO()
MACRO(BISON input)
IF(NOT BISON_FOUND)
MESSAGE(STATUS "BISON not found, pre-generated files will be used." )
ELSE()
get_filename_component(input_src ${input} ABSOLUTE)
get_filename_component(input_dir ${input_src} DIRECTORY)
get_filename_component(input_name ${input} NAME_WE)
get_filename_component(input_name_ext ${input} NAME)
ADD_CUSTOM_COMMAND(
DEPENDS ${input_src}
OUTPUT ${input_dir}/${input_name}.cpp ${input_dir}/${input_name}.hpp ${input_dir}/${input_name}.output
WORKING_DIRECTORY ${input_dir}
COMMAND ${BISON_EXECUTABLE} --output=${input_name}.cpp --defines=${input_name}.hpp ${input_name_ext}
COMMENT "bison (v ${BISON_VERSION}) ${input} to ${input_dir}/${input_name}.cpp + ${input_dir}/${input_name}.hpp + ${input_dir}/${input_name}.output")
ENDIF()
ENDMACRO()