utils.cmake
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
parent 0 bde4ae8d615e
permissions -rw-r--r--
Update contrib.
     1 # Copyright (c) 2009-2012 Stéphane Lenclud.
     2 # All rights reserved.
     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".
     7 #
     8 # Initial Contributors:
     9 # Stéphane Lenclud.
    10 #
    11 
    12 #
    13 # This file contains some generic cmake macros we are using for building Symbian
    14 #
    15 
    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}")
    23 endmacro(push_target) 
    24 
    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}")
    38 endmacro(pop_target) 
    39 
    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")
    45 	set(${targetName} "")
    46 	if (NOT(${count} LESS 0))
    47 		list(GET targetStackValue ${count} ${targetName})
    48 	endif (NOT(${count} LESS 0))
    49 endmacro(get_target) 
    50 
    51 #-----------------------------------------------------
    52 #Add the given source files to our source prepending the sourcepath
    53 macro(add_source)
    54 	get_target(targetName)
    55 	set(sourcesProperty "${targetName}Sources")
    56 	get_property(sourcesPropertyValue GLOBAL PROPERTY ${sourcesProperty})
    57 		
    58 	foreach(mySource ${ARGV})
    59 		string(REGEX REPLACE "(^.+)" "${sourcepath}\\1" newsource ${mySource})		
    60 		set(sourcesPropertyValue ${sourcesPropertyValue} ${newsource})		
    61 	endforeach(mySource) 
    62 	
    63 	set_property(GLOBAL PROPERTY ${sourcesProperty} ${sourcesPropertyValue})
    64 	#message("${targetName} sources: ${sourcesPropertyValue}")
    65 endmacro(add_source)
    66 
    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}")	
    75 endmacro(get_source)
    76 
    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})
    85 	
    86 	source_group(CMake FILES ${CMAKE_CURRENT_LIST_FILE})
    87 endmacro(add_cmake_source)
    88 
    89 #-----------------------------------------------------
    90 #TODO: implement macro to generate _uid file based on a template
    91 #Also add the generated CPP file to our ${source}
    92 macro(uid)
    93 	#set(source ${source} ${CMAKE_CURRENT_LIST_FILE})
    94 	#source_group(CMake FILES ${CMAKE_CURRENT_LIST_FILE})
    95 endmacro(uid)
    96 
    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}")
   105 endmacro(add_define)
   106 
   107 
   108 #-----------------------------------------------------
   109 #Perform Symbian bld.inf export
   110 macro(public_export source destination)
   111 	install(FILES 
   112 			${source}
   113 			DESTINATION ${PROJECT_SOURCE_DIR}/epoc32/include${destination} )
   114 endmacro(public_export)
   115 
   116 #-----------------------------------------------------
   117 #Perform Symbian bld.inf export
   118 macro(platform_export source destination)
   119 	install(FILES 
   120 			${source}
   121 			DESTINATION ${PROJECT_SOURCE_DIR}/epoc32/include/platform${destination} )
   122 endmacro(platform_export)
   123 
   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 	set_property(TARGET ${targetName} APPEND PROPERTY INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}${path})
   139 endmacro(system_include)
   140 
   141 #-----------------------------------------------------
   142 #Add user include path to our current target
   143 #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.
   144 #TODO: Is this working with releative path?
   145 macro(user_include path)
   146 	get_target(targetName)
   147 	#get_target_property(value ${targetName} COMPILE_FLAGS)
   148 	##MS CL compiler specific. I guess gcc should use -I instead of /I
   149 	#if (${value} STREQUAL "value-NOTFOUND")
   150 	#	set(value "/I ${CMAKE_CURRENT_LIST_DIR}/${path}")	
   151 	#else (${value} STREQUAL "value-NOTFOUND")
   152 	#	set(value "${value} /I ${CMAKE_CURRENT_LIST_DIR}/${path}")	
   153 	#endif (${value} STREQUAL "value-NOTFOUND")	
   154 	#set_target_properties(${targetName} PROPERTIES COMPILE_FLAGS "${value}")
   155 	set_property(TARGET ${targetName} APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/${path})
   156 endmacro(user_include)
   157 
   158 
   159 
   160 
   161 #Generate our configuration file
   162 #configure_file( ../../GameEngine/inc/GikConfig.h.cmake ../../GameEngine/inc/GikConfig.h )
   163 #Must make sure we include the generate config from the bynary tree
   164 #include_directories("${CMAKE_BINARY_DIR}/../../GameEngine/inc")
   165 
   166