[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 # Wrapper functions for the important properties, using add_target_property
28 # where appropriate.
29 # Note that the functions for string properties take a single string
30 # argument while those for list properties can take a variable number of
31 # arguments, all of which will be added to the list
32 #
33 # Examples:
34 # add_compile_flags("-pedantic -O5")
35 # add_target_link_flags(mymodule "-s --fatal-warnings")
36 # add_target_compile_flags(mymodule "-pedantic -O5")
37 # add_target_compile_definitions(mymodule WIN32 _WIN32 INLINE=inline)
38 # add_target_include_directories(mymodule include ../include)
39 function(add_compile_flags _flags)
40 if (${ARGC} GREATER 1)
41 message(STATUS "Excess arguments to add_compile_flags! Args ${ARGN}")
42 endif()
43 # Adds the compiler flag to both CMAKE_C_FLAGS and CMAKE_CXX_FLAGS
44 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flags}" PARENT_SCOPE)
45 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flags}" PARENT_SCOPE)
46 endfunction()
47
48 function(add_target_compile_flags _module _flags)
49 if (${ARGC} GREATER 2)
50 message(STATUS "Excess arguments to add_target_compile_flags! Module ${_module}, args ${ARGN}")
51 endif()
52 add_target_property(${_module} COMPILE_FLAGS ${_flags})
53 endfunction()
54
55 function(add_target_link_flags _module _flags)
56 if (${ARGC} GREATER 2)
57 message(STATUS "Excess arguments to add_target_link_flags! Module ${_module}, args ${ARGN}")
58 endif()
59 add_target_property(${_module} LINK_FLAGS ${_flags})
60 endfunction()
61
62 function(add_target_compile_definitions _module)
63 add_target_property(${_module} COMPILE_DEFINITIONS ${ARGN})
64 endfunction()
65
66 function(add_target_include_directories _module)
67 add_target_property(${_module} INCLUDE_DIRECTORIES ${ARGN})
68 endfunction()
69
70 macro(set_unicode)
71 add_definitions(-DUNICODE -D_UNICODE)
72 set(IS_UNICODE 1)
73 endmacro()