forked from GaijinEntertainment/daScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeCommon.txt
68 lines (63 loc) · 2.81 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
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_COMPILER)
IF(APPLE)
ADD_DEFINITIONS(-DITS_PLATFORM_APPLE=1)
ADD_DEFINITIONS(-Wall -Wextra -pedantic)
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fomit-frame-pointer -momit-leaf-frame-pointer -flto=full")
ELSEIF(UNIX)
ADD_COMPILE_OPTIONS(-Wno-ignored-attributes)
ELSEIF(WIN32)
ADD_DEFINITIONS(-DITS_PLATFORM_WIN32=1)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ADD_DEFINITIONS(-W4)
SET(CMAKE_CXX_FLAGS_RELEASE "/MD /Ox /Ob2 /Ot /Oi /DNDEBUG /Gy /GS- /GR- /EHa")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Zi /MD /Ox /Ob2 /Ot /Oi /DNDEBUG /Gy /GS- /GR- /EHa")
ENDIF()
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()
ENDMACRO()
MACRO(ADD_PRECOMPILED_HEADER _targetName _input _inputXcode)
IF(APPLE)
MESSAGE(STATUS "Enabling precompiled headers for Xcode ${CMAKE_GENERATOR}" )
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER YES)
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/${_inputXcode} )
ENDIF()
IF(MSVC)
GET_FILENAME_COMPONENT(_name ${_input} NAME_WE)
GET_FILENAME_COMPONENT(_path ${_input} PATH )
MESSAGE(STATUS "PCH path is ${_path}" )
SET(EMPTY_PATH "" )
IF(EMPTY_PATH STREQUAL "${_path}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /EHsc /Yu${_name}.h")
SET_SOURCE_FILES_PROPERTIES(${_name}.cpp PROPERTIES COMPILE_FLAGS "/Yc${_name}.h" )
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /EHsc /Yu${_path}/${_name}.h")
SET_SOURCE_FILES_PROPERTIES(${_path}/${_name}.cpp PROPERTIES COMPILE_FLAGS "/Yc${_path}/${_name}.h" )
ENDIF()
ENDIF(MSVC)
ENDMACRO(ADD_PRECOMPILED_HEADER)
MACRO(FIND_XXD)
find_program(XXD_BIN xxd)
ENDMACRO(FIND_XXD)
MACRO(XXD input)
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")
ENDMACRO()