First public contribution.
1 # Copyright (c) 2009-2012 St駱hane Lenclud.
3 # This component and the accompanying materials are made available
4 # under the terms of the License "Eclipse Public License v1.0"
5 # which accompanies this distribution, and is available
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 # Initial Contributors:
13 # This file contains some generic cmake macros we are using for building Symbian
16 #-----------------------------------------------------
17 #Push a target on our target stack
18 macro(push_target targetName)
19 get_property(targetStackValue GLOBAL PROPERTY targetStack)
20 list(APPEND targetStackValue ${targetName})
21 set_property(GLOBAL PROPERTY targetStack ${targetStackValue})
22 #message("Push target: ${targetStackValue}")
25 #-----------------------------------------------------
26 #Pop the given target from our target stack
27 macro(pop_target targetName)
28 get_property(targetStackValue GLOBAL PROPERTY targetStack)
29 list(LENGTH targetStackValue count)
30 math( EXPR count "${count} - 1")
31 list(GET targetStackValue ${count} poppedTargetName)
32 if (NOT(${poppedTargetName} STREQUAL ${targetName}))
33 message(FATAL_ERROR "pop_target expecting ${poppedTargetName} instead of ${targetName}!")
34 endif (NOT(${poppedTargetName} STREQUAL ${targetName}))
35 list(REMOVE_AT targetStackValue ${count})
36 set_property(GLOBAL PROPERTY targetStack ${targetStackValue})
37 #message("Pop target: ${targetName} :to: ${targetStackValue}")
40 #-----------------------------------------------------
41 #Get the name of the target from the top of our stack
42 macro(get_target targetName)
43 list(LENGTH targetStackValue count)
44 math( EXPR count "${count} - 1")
46 if (NOT(${count} LESS 0))
47 list(GET targetStackValue ${count} ${targetName})
48 endif (NOT(${count} LESS 0))
51 #-----------------------------------------------------
52 #Add the given source files to our source prepending the sourcepath
54 get_target(targetName)
55 set(sourcesProperty "${targetName}Sources")
56 get_property(sourcesPropertyValue GLOBAL PROPERTY ${sourcesProperty})
58 foreach(mySource ${ARGV})
59 string(REGEX REPLACE "(^.+)" "${sourcepath}\1円" newsource ${mySource})
60 set(sourcesPropertyValue ${sourcesPropertyValue} ${newsource})
63 set_property(GLOBAL PROPERTY ${sourcesProperty} ${sourcesPropertyValue})
64 #message("${targetName} sources: ${sourcesPropertyValue}")
67 #-----------------------------------------------------
68 #Get the sources for the current target
69 macro(get_source sourceVar)
70 get_target(targetName)
71 set(sourcesProperty "${targetName}Sources")
72 get_property(sourcesPropertyValue GLOBAL PROPERTY ${sourcesProperty})
73 set(${sourceVar} ${sourcesPropertyValue})
74 #message("${targetName} sources: ${sourcesPropertyValue}")
77 #-----------------------------------------------------
78 #Add current cmake file to our source tree
79 macro(add_cmake_source)
80 get_target(targetName)
81 set(sourcesProperty "${targetName}Sources")
82 get_property(sourcesPropertyValue GLOBAL PROPERTY ${sourcesProperty})
83 set(sourcesPropertyValue ${sourcesPropertyValue} ${CMAKE_CURRENT_LIST_FILE})
84 set_property(GLOBAL PROPERTY ${sourcesProperty} ${sourcesPropertyValue})
86 source_group(CMake FILES ${CMAKE_CURRENT_LIST_FILE})
87 endmacro(add_cmake_source)
89 #-----------------------------------------------------
90 #TODO: implement macro to generate _uid file based on a template
91 #Also add the generated CPP file to our ${source}
93 #set(source ${source} ${CMAKE_CURRENT_LIST_FILE})
94 #source_group(CMake FILES ${CMAKE_CURRENT_LIST_FILE})
97 #-----------------------------------------------------
98 #Add a pre-compiler define to the pre set target
99 macro(add_define define)
100 get_target(targetName)
101 get_target_property(value ${targetName} COMPILE_DEFINITIONS)
102 #message("Add define: ${define} to target: ${targetName}")
103 set(value ${value} ${define})
104 set_target_properties(${targetName} PROPERTIES COMPILE_DEFINITIONS "${value}")
108 #-----------------------------------------------------
109 #Perform Symbian bld.inf export
110 macro(public_export source destination)
113 DESTINATION ${PROJECT_SOURCE_DIR}/epoc32/include${destination} )
114 endmacro(public_export)
116 #-----------------------------------------------------
117 #Perform Symbian bld.inf export
118 macro(platform_export source destination)
121 DESTINATION ${PROJECT_SOURCE_DIR}/epoc32/include/platform${destination} )
122 endmacro(platform_export)
124 #-----------------------------------------------------
125 #Add system include path to our current target
126 #Use those include path macro instead of cmake built-in include_directories as it allows us to set include directories per target instead of per directory.
127 macro(system_include path)
128 get_target(targetName)
129 get_target_property(value ${targetName} COMPILE_FLAGS)
130 #MS CL compiler specific. I guess gcc should use -I instead of /I
131 if (${value} STREQUAL "value-NOTFOUND")
132 set(value "/I ${PROJECT_SOURCE_DIR}${path}")
133 else (${value} STREQUAL "value-NOTFOUND")
134 set(value "${value} /I ${PROJECT_SOURCE_DIR}${path}")
135 endif (${value} STREQUAL "value-NOTFOUND")
136 #message("Add system include: ${value}")
137 set_target_properties(${targetName} PROPERTIES COMPILE_FLAGS "${value}")
138 endmacro(system_include)
140 #-----------------------------------------------------
141 #Add user include path to our current target
142 #Use those include path macro instead of cmake built-in include_directories as it allows us to set include directories per target instead of per directory.
143 #TODO: Is this working with releative path?
144 macro(user_include path)
145 get_target(targetName)
146 get_target_property(value ${targetName} COMPILE_FLAGS)
147 #MS CL compiler specific. I guess gcc should use -I instead of /I
148 if (${value} STREQUAL "value-NOTFOUND")
149 set(value "/I ${CMAKE_CURRENT_LIST_DIR}/${path}")
150 else (${value} STREQUAL "value-NOTFOUND")
151 set(value "${value} /I ${CMAKE_CURRENT_LIST_DIR}/${path}")
152 endif (${value} STREQUAL "value-NOTFOUND")
153 set_target_properties(${targetName} PROPERTIES COMPILE_FLAGS "${value}")
154 endmacro(user_include)
159 #Generate our configuration file
160 #configure_file( ../../GameEngine/inc/GikConfig.h.cmake ../../GameEngine/inc/GikConfig.h )
161 #Must make sure we include the generate config from the bynary tree
162 #include_directories("${CMAKE_BINARY_DIR}/../../GameEngine/inc")