sl@0: # Copyright (c) 2009-2012 Stéphane Lenclud. sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of the License "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Stéphane Lenclud. sl@0: # sl@0: sl@0: # sl@0: # This file contains some generic cmake macros we are using for building Symbian sl@0: # sl@0: sl@0: #----------------------------------------------------- sl@0: #Push a target on our target stack sl@0: macro(push_target targetName) sl@0: get_property(targetStackValue GLOBAL PROPERTY targetStack) sl@0: list(APPEND targetStackValue ${targetName}) sl@0: set_property(GLOBAL PROPERTY targetStack ${targetStackValue}) sl@0: #message("Push target: ${targetStackValue}") sl@0: endmacro(push_target) sl@0: sl@0: #----------------------------------------------------- sl@0: #Pop the given target from our target stack sl@0: macro(pop_target targetName) sl@0: get_property(targetStackValue GLOBAL PROPERTY targetStack) sl@0: list(LENGTH targetStackValue count) sl@0: math( EXPR count "${count} - 1") sl@0: list(GET targetStackValue ${count} poppedTargetName) sl@0: if (NOT(${poppedTargetName} STREQUAL ${targetName})) sl@0: message(FATAL_ERROR "pop_target expecting ${poppedTargetName} instead of ${targetName}!") sl@0: endif (NOT(${poppedTargetName} STREQUAL ${targetName})) sl@0: list(REMOVE_AT targetStackValue ${count}) sl@0: set_property(GLOBAL PROPERTY targetStack ${targetStackValue}) sl@0: #message("Pop target: ${targetName} :to: ${targetStackValue}") sl@0: endmacro(pop_target) sl@0: sl@0: #----------------------------------------------------- sl@0: #Get the name of the target from the top of our stack sl@0: macro(get_target targetName) sl@0: list(LENGTH targetStackValue count) sl@0: math( EXPR count "${count} - 1") sl@0: set(${targetName} "") sl@0: if (NOT(${count} LESS 0)) sl@0: list(GET targetStackValue ${count} ${targetName}) sl@0: endif (NOT(${count} LESS 0)) sl@0: endmacro(get_target) sl@0: sl@0: #----------------------------------------------------- sl@0: #Add the given source files to our source prepending the sourcepath sl@0: macro(add_source) sl@0: get_target(targetName) sl@0: set(sourcesProperty "${targetName}Sources") sl@0: get_property(sourcesPropertyValue GLOBAL PROPERTY ${sourcesProperty}) sl@0: sl@0: foreach(mySource ${ARGV}) sl@0: string(REGEX REPLACE "(^.+)" "${sourcepath}\\1" newsource ${mySource}) sl@0: set(sourcesPropertyValue ${sourcesPropertyValue} ${newsource}) sl@0: endforeach(mySource) sl@0: sl@0: set_property(GLOBAL PROPERTY ${sourcesProperty} ${sourcesPropertyValue}) sl@0: #message("${targetName} sources: ${sourcesPropertyValue}") sl@0: endmacro(add_source) sl@0: sl@0: #----------------------------------------------------- sl@0: #Get the sources for the current target sl@0: macro(get_source sourceVar) sl@0: get_target(targetName) sl@0: set(sourcesProperty "${targetName}Sources") sl@0: get_property(sourcesPropertyValue GLOBAL PROPERTY ${sourcesProperty}) sl@0: set(${sourceVar} ${sourcesPropertyValue}) sl@0: #message("${targetName} sources: ${sourcesPropertyValue}") sl@0: endmacro(get_source) sl@0: sl@0: #----------------------------------------------------- sl@0: #Add current cmake file to our source tree sl@0: macro(add_cmake_source) sl@0: get_target(targetName) sl@0: set(sourcesProperty "${targetName}Sources") sl@0: get_property(sourcesPropertyValue GLOBAL PROPERTY ${sourcesProperty}) sl@0: set(sourcesPropertyValue ${sourcesPropertyValue} ${CMAKE_CURRENT_LIST_FILE}) sl@0: set_property(GLOBAL PROPERTY ${sourcesProperty} ${sourcesPropertyValue}) sl@0: sl@0: source_group(CMake FILES ${CMAKE_CURRENT_LIST_FILE}) sl@0: endmacro(add_cmake_source) sl@0: sl@0: #----------------------------------------------------- sl@0: #TODO: implement macro to generate _uid file based on a template sl@0: #Also add the generated CPP file to our ${source} sl@0: macro(uid) sl@0: #set(source ${source} ${CMAKE_CURRENT_LIST_FILE}) sl@0: #source_group(CMake FILES ${CMAKE_CURRENT_LIST_FILE}) sl@0: endmacro(uid) sl@0: sl@0: #----------------------------------------------------- sl@0: #Add a pre-compiler define to the pre set target sl@0: macro(add_define define) sl@0: get_target(targetName) sl@0: get_target_property(value ${targetName} COMPILE_DEFINITIONS) sl@0: #message("Add define: ${define} to target: ${targetName}") sl@0: set(value ${value} ${define}) sl@0: set_target_properties(${targetName} PROPERTIES COMPILE_DEFINITIONS "${value}") sl@0: endmacro(add_define) sl@0: sl@0: sl@0: #----------------------------------------------------- sl@0: #Perform Symbian bld.inf export sl@0: macro(public_export source destination) sl@0: install(FILES sl@0: ${source} sl@0: DESTINATION ${PROJECT_SOURCE_DIR}/epoc32/include${destination} ) sl@0: endmacro(public_export) sl@0: sl@0: #----------------------------------------------------- sl@0: #Perform Symbian bld.inf export sl@0: macro(platform_export source destination) sl@0: install(FILES sl@0: ${source} sl@0: DESTINATION ${PROJECT_SOURCE_DIR}/epoc32/include/platform${destination} ) sl@0: endmacro(platform_export) sl@0: sl@0: #----------------------------------------------------- sl@0: #Add system include path to our current target sl@0: #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: macro(system_include path) sl@0: get_target(targetName) sl@0: get_target_property(value ${targetName} COMPILE_FLAGS) sl@0: #MS CL compiler specific. I guess gcc should use -I instead of /I sl@0: if (${value} STREQUAL "value-NOTFOUND") sl@0: set(value "/I ${PROJECT_SOURCE_DIR}${path}") sl@0: else (${value} STREQUAL "value-NOTFOUND") sl@0: set(value "${value} /I ${PROJECT_SOURCE_DIR}${path}") sl@0: endif (${value} STREQUAL "value-NOTFOUND") sl@0: #message("Add system include: ${value}") sl@0: set_target_properties(${targetName} PROPERTIES COMPILE_FLAGS "${value}") sl@0: endmacro(system_include) sl@0: sl@0: #----------------------------------------------------- sl@0: #Add user include path to our current target sl@0: #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: #TODO: Is this working with releative path? sl@0: macro(user_include path) sl@0: get_target(targetName) sl@0: get_target_property(value ${targetName} COMPILE_FLAGS) sl@0: #MS CL compiler specific. I guess gcc should use -I instead of /I sl@0: if (${value} STREQUAL "value-NOTFOUND") sl@0: set(value "/I ${CMAKE_CURRENT_LIST_DIR}/${path}") sl@0: else (${value} STREQUAL "value-NOTFOUND") sl@0: set(value "${value} /I ${CMAKE_CURRENT_LIST_DIR}/${path}") sl@0: endif (${value} STREQUAL "value-NOTFOUND") sl@0: set_target_properties(${targetName} PROPERTIES COMPILE_FLAGS "${value}") sl@0: endmacro(user_include) sl@0: sl@0: sl@0: sl@0: sl@0: #Generate our configuration file sl@0: #configure_file( ../../GameEngine/inc/GikConfig.h.cmake ../../GameEngine/inc/GikConfig.h ) sl@0: #Must make sure we include the generate config from the bynary tree sl@0: #include_directories("${CMAKE_BINARY_DIR}/../../GameEngine/inc") sl@0: sl@0: