[CMAKE]
[reactos.git] / reactos / cmake / compilerflags.cmake
1
2 # add_target_property
3 # Adds one or more values to the specified property of the specified target.
4 # Note that there are properties which require (semicolon-separated) lists,
5 # while others require space-separated strings. The function has a list of
6 # properties of the former variety and handles the values accordingly
7 function(add_target_property _module _propname)
8 list(APPEND _list_properties COMPILE_DEFINITIONS INCLUDE_DIRECTORIES)
9 set(_newvalue "")
10 get_target_property(_oldvalue ${_module} ${_propname})
11 if (_oldvalue)
12 set(_newvalue ${_oldvalue})
13 endif()
14 list(FIND _list_properties ${_propname} _list_index)
15 if (NOT _list_index EQUAL -1)
16 # list property
17 list(APPEND _newvalue ${ARGN})
18 else()
19 # string property
20 foreach(_flag ${ARGN})
21 set(_newvalue "${_newvalue} ${_flag}")
22 endforeach()
23 endif()
24 set_property(TARGET ${_module} PROPERTY ${_propname} ${_newvalue})
25 endfunction()
26
27 #
28 # For backwards compatibility. To be removed soon.
29 #
30 function(add_compiler_flags)
31 set(flags_list "")
32 # Adds the compiler flag to both CMAKE_C_FLAGS and CMAKE_CXX_FLAGS
33 foreach(flag ${ARGN})
34 set(flags_list "${flags_list} ${flag}")
35 endforeach()
36
37 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flags_list}" PARENT_SCOPE)
38 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flags_list}" PARENT_SCOPE)
39 endfunction()
40
41 function(add_linkerflag MODULE _flag)
42 if (${ARGC} GREATER 2)
43 message(STATUS "Excess arguments to add_linkerflag! Module ${MODULE}, args ${ARGN}")
44 endif()
45 set(NEW_LINKER_FLAGS ${_flag})
46 get_target_property(LINKER_FLAGS ${MODULE} LINK_FLAGS)
47 if(LINKER_FLAGS)
48 set(NEW_LINKER_FLAGS "${LINKER_FLAGS} ${NEW_LINKER_FLAGS}")
49 endif()
50 set_target_properties(${MODULE} PROPERTIES LINK_FLAGS ${NEW_LINKER_FLAGS})
51 endfunction()
52
53 # New versions, using add_target_property where appropriate.
54 # Note that the functions for string properties take a single string
55 # argument while those for list properties can take a variable number of
56 # arguments, all of which will be added to the list
57 #
58 # Examples:
59 # add_compile_flags("-pedantic -O5")
60 # add_target_link_flags(mymodule "-s --fatal-warnings")
61 # add_target_compile_flags(mymodule "-pedantic -O5")
62 # add_target_compile_definitions(mymodule WIN32 _WIN32)
63 # add_target_include_directories(mymodule include ../include)
64 function(add_compile_flags _flags)
65 if (${ARGC} GREATER 1)
66 message(STATUS "Excess arguments to add_compile_flags! Args ${ARGN}")
67 endif()
68 # Adds the compiler flag to both CMAKE_C_FLAGS and CMAKE_CXX_FLAGS
69 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flags}" PARENT_SCOPE)
70 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flags}" PARENT_SCOPE)
71 endfunction()
72
73 function(add_target_compile_flags _module _flags)
74 if (${ARGC} GREATER 2)
75 message(STATUS "Excess arguments to add_target_compile_flags! Module ${_module}, args ${ARGN}")
76 endif()
77 add_target_property(${_module} COMPILE_FLAGS ${_flags})
78 endfunction()
79
80 function(add_target_link_flags _module _flags)
81 if (${ARGC} GREATER 2)
82 message(STATUS "Excess arguments to add_target_link_flags! Module ${_module}, args ${ARGN}")
83 endif()
84 add_target_property(${_module} LINK_FLAGS ${_flags})
85 endfunction()
86
87 function(add_target_compile_definitions _module)
88 add_target_property(${_module} COMPILE_DEFINITIONS ${ARGN})
89 endfunction()
90
91 function(add_target_include_directories _module)
92 add_target_property(${_module} INCLUDE_DIRECTORIES ${ARGN})
93 endfunction()
94
95 macro(set_unicode)
96 add_definitions(-DUNICODE -D_UNICODE)
97 set(IS_UNICODE 1)
98 endmacro()