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