Browse Source

Added setup_main_executable() CMake macro which sets up resource copying for an executable.

Lasse Öörni 12 years ago
parent
commit
648564c8fb
4 changed files with 38 additions and 42 deletions
  1. 32 0
      CMakeLists.txt
  2. 2 7
      Docs/GettingStarted.dox
  3. 2 7
      Extras/CharacterDemo/CMakeLists.txt
  4. 2 28
      Urho3D/CMakeLists.txt

+ 32 - 0
CMakeLists.txt

@@ -167,6 +167,38 @@ macro (setup_executable)
     endif ()
 endmacro ()
 
+# Macro for setting up an executable target with resources to copy
+macro (setup_main_executable)
+    # Define resource files
+    if (APPLE)
+        set (RESOURCE_FILES ${PROJECT_BINARY_DIR}/Bin/CoreData ${PROJECT_BINARY_DIR}/Bin/Data)
+        set_source_files_properties(${RESOURCE_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
+        set (SOURCE_FILES ${SOURCE_FILES} ${RESOURCE_FILES})
+    endif ()
+    
+    # Setup target
+    if (WIN32)
+        set (EXE_TYPE WIN32)
+    elseif (IOS)
+        set (CMAKE_EXE_LINKER_FLAGS "-framework AudioToolbox -framework CoreAudio -framework CoreGraphics -framework Foundation -framework OpenGLES -framework QuartzCore -framework UIKit")
+        set (EXE_TYPE MACOSX_BUNDLE)
+    elseif (APPLE)
+        set (CMAKE_EXE_LINKER_FLAGS "-framework AudioUnit -framework Carbon -framework Cocoa -framework CoreAudio -framework ForceFeedback -framework IOKit -framework OpenGL -framework CoreServices")
+    endif ()
+    setup_executable ()
+    
+    # Define a custom target to check for resource modification
+    if (IOS)
+        get_target_property (TARGET_LOC ${TARGET_NAME} LOCATION)
+        string (REGEX REPLACE "/Contents/MacOS" "" TARGET_LOC ${TARGET_LOC})    # The regex replacement is temporary workaround to correct the wrong location caused by CMake/Xcode generator bug
+        add_custom_target (RESOURCE_CHECK ALL
+            \(\( `find ${RESOURCE_FILES} -newer ${TARGET_LOC} 2>/dev/null |wc -l` \)\) && touch -cm ${SOURCE_FILES} || exit 0
+            COMMENT "This is a dummy target to check for changes in the Resource folders"
+        )
+        add_dependencies (${TARGET_NAME} RESOURCE_CHECK)
+    endif ()
+endmacro ()
+
 # Macro for setting up a library target
 macro (setup_library)
     add_library (${TARGET_NAME} STATIC ${SOURCE_FILES})

+ 2 - 7
Docs/GettingStarted.dox

@@ -495,13 +495,8 @@ set (SOURCE_FILES ${CPP_FILES} ${H_FILES})
 # Define dependency libs
 set (LIBS ../Engine/Container ../Engine/Core ../Engine/Engine ../Engine/Graphics ../Engine/Input ../Engine/IO ../Engine/Math ../Engine/Resource ../Engine/Scene ../Engine/UI)
 
-# Setup target
-if (WIN32)
-    set (EXE_TYPE WIN32)
-elseif (APPLE)
-    set (CMAKE_EXE_LINKER_FLAGS "-framework AudioUnit -framework Carbon -framework Cocoa -framework CoreAudio -framework ForceFeedback -framework IOKit -framework OpenGL -framework CoreServices")
-endif ()
-setup_executable ()
+# Setup target with resource copying
+setup_main_executable ()
 \endcode
 
 Before recreating the build files with CMake, create an empty HelloWorld.cpp into the HelloWorld directory. Now you can re-run CMake. If using Visual Studio, the HelloWorld project should now appear in the Urho3D solution, and you can start writing the actual application into HelloWorld.cpp.

+ 2 - 7
Extras/CharacterDemo/CMakeLists.txt

@@ -11,10 +11,5 @@ set (LIBS ../../Engine/Container ../../Engine/Core ../../Engine/Engine ../../Eng
     ../../Engine/Network ../../Engine/Physics ../../Engine/Resource ../../Engine/Scene ../../Engine/UI)
 set (INCLUDE_DIRS_ONLY ../../ThirdParty/Bullet/src)
 
-# Setup target
-if (WIN32)
-    set (EXE_TYPE WIN32)
-elseif (APPLE)
-    set (CMAKE_EXE_LINKER_FLAGS "-framework AudioUnit -framework Carbon -framework Cocoa -framework CoreAudio -framework ForceFeedback -framework IOKit -framework OpenGL -framework CoreServices")
-endif ()
-setup_executable ()
+# Setup target with resource copying
+setup_main_executable ()

+ 2 - 28
Urho3D/CMakeLists.txt

@@ -6,34 +6,8 @@ file (GLOB CPP_FILES *.cpp)
 file (GLOB H_FILES *.h)
 set (SOURCE_FILES ${CPP_FILES} ${H_FILES})
 
-# Define resource files
-if (APPLE)
-    set (RESOURCE_FILES ${PROJECT_BINARY_DIR}/Bin/CoreData ${PROJECT_BINARY_DIR}/Bin/Data)
-    set_source_files_properties(${RESOURCE_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
-    set (SOURCE_FILES ${SOURCE_FILES} ${RESOURCE_FILES})
-endif ()
-
 # Define dependency libs
 set (LIBS ../Engine/Container ../Engine/Core ../Engine/Engine ../Engine/IO ../Engine/Math ../Engine/Resource ../Engine/Script)
 
-# Setup target
-if (WIN32)
-    set (EXE_TYPE WIN32)
-elseif (IOS)
-    set (CMAKE_EXE_LINKER_FLAGS "-framework AudioToolbox -framework CoreAudio -framework CoreGraphics -framework Foundation -framework OpenGLES -framework QuartzCore -framework UIKit")
-    set (EXE_TYPE MACOSX_BUNDLE)
-elseif (APPLE)
-    set (CMAKE_EXE_LINKER_FLAGS "-framework AudioUnit -framework Carbon -framework Cocoa -framework CoreAudio -framework ForceFeedback -framework IOKit -framework OpenGL -framework CoreServices")
-endif ()
-setup_executable ()
-
-# Define a custom target to check for resource modification
-if (IOS)
-    get_target_property (TARGET_LOC ${TARGET_NAME} LOCATION)
-    string (REGEX REPLACE "/Contents/MacOS" "" TARGET_LOC ${TARGET_LOC})    # The regex replacement is temporary workaround to correct the wrong location caused by CMake/Xcode generator bug
-    add_custom_target (RESOURCE_CHECK ALL
-        \(\( `find ${RESOURCE_FILES} -newer ${TARGET_LOC} 2>/dev/null |wc -l` \)\) && touch -cm ${SOURCE_FILES} || exit 0
-        COMMENT "This is a dummy target to check for changes in the Resource folders"
-    )
-    add_dependencies (${TARGET_NAME} RESOURCE_CHECK)
-endif ()
+# Setup target with resource copying
+setup_main_executable ()