Browse Source

Added custom script for MSVC build.

Wei Tjong Yao 12 years ago
parent
commit
1cbdea8159

+ 9 - 3
CMakeLists.txt

@@ -105,9 +105,6 @@ if (URHO3D_BUILD_TYPE MATCHES "STATIC|SHARED" AND NOT IOS AND NOT ANDROID)
     # Urho3D library
     add_subdirectory (Urho3D/lib)
 else ()
-    # Create a dummy export header file as it is being included by all the Engine's header files
-    configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Urho3D.h.in ${CMAKE_CURRENT_BINARY_DIR}/Urho3D.h COPYONLY)
-
     # Urho3D script host application
     add_subdirectory (Tools/Urho3D)
 
@@ -151,3 +148,12 @@ else ()
         add_subdirectory (Tools/ShaderCompiler)
     endif ()
 endif ()
+
+# Generate platform specific export header file automatically
+set_target_properties (Urho3D PROPERTIES DEFINE_SYMBOL URHO3D_EXPORTS)
+generate_export_header (Urho3D EXPORT_MACRO_NAME URHO3D_API EXPORT_FILE_NAME Urho3D.h)
+
+# Append Urho3D license notice to the export header file
+file (READ ${CMAKE_SOURCE_DIR}/Urho3D.h.in LICENSE)
+file (READ ${CMAKE_BINARY_DIR}/Urho3D.h EXPORT_DEFINE)
+file (WRITE ${CMAKE_BINARY_DIR}/Urho3D.h ${LICENSE}${EXPORT_DEFINE})

+ 21 - 13
Urho3D.h.in

@@ -1,13 +1,21 @@
-
-#ifndef URHO3D_API_H
-#define URHO3D_API_H
-
-#define URHO3D_API
-#define URHO3D_NO_EXPORT
-
-#define URHO3D_DEPRECATED
-#define URHO3D_DEPRECATED_EXPORT
-#define URHO3D_DEPRECATED_NO_EXPORT
-#define URHO3D_NO_DEPRECATED
-
-#endif
+//
+// Copyright (c) 2008-2013 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//

+ 0 - 4
Urho3D/lib/CMakeLists.txt

@@ -48,10 +48,6 @@ set (INCLUDE_DIRS_ONLY ${CMAKE_CURRENT_BINARY_DIR})
 # Setup target
 setup_library ()
 
-# Generate platform specific export header file automatically 
-set_target_properties (${TARGET_NAME} PROPERTIES DEFINE_SYMBOL URHO3D_EXPORTS)
-generate_export_header (${TARGET_NAME} EXPORT_MACRO_NAME URHO3D_API EXPORT_FILE_NAME ../../Urho3D.h)
-
 if (WIN32)
 #todo
 else ()

+ 34 - 11
cmake/Modules/Urho3D-CMake-magic.cmake

@@ -152,7 +152,7 @@ endif ()
 # Include CMake builtin module for building shared library support
 include (GenerateExportHeader)
 
-# Override builtin macro to suit our need, always generate header file regardless of library type
+# Override builtin macro and function to suit our need, always generate header file regardless of target type...
 macro (_DO_SET_MACRO_VALUES TARGET_LIBRARY)
     set (DEFINE_DEPRECATED)
     set (DEFINE_EXPORT)
@@ -165,15 +165,31 @@ macro (_DO_SET_MACRO_VALUES TARGET_LIBRARY)
         set (DEFINE_DEPRECATED "__declspec(deprecated)")
     endif ()
 
-    if (WIN32)
-        set (DEFINE_EXPORT "__declspec(dllexport)")
-        set (DEFINE_IMPORT "__declspec(dllimport)")
-    elseif (COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY)
-        set (DEFINE_EXPORT "__attribute__((visibility(\"default\")))")
-        set (DEFINE_IMPORT "__attribute__((visibility(\"default\")))")
-        set (DEFINE_NO_EXPORT "__attribute__((visibility(\"hidden\")))")
+    get_property (type TARGET ${TARGET_LIBRARY} PROPERTY TYPE)
+    
+    if (type MATCHES "STATIC|SHARED")
+        if (WIN32)
+            set (DEFINE_EXPORT "__declspec(dllexport)")
+            set (DEFINE_IMPORT "__declspec(dllimport)")
+        elseif (COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY)
+            set (DEFINE_EXPORT "__attribute__((visibility(\"default\")))")
+            set (DEFINE_IMPORT "__attribute__((visibility(\"default\")))")
+            set (DEFINE_NO_EXPORT "__attribute__((visibility(\"hidden\")))")
+        endif ()
     endif ()
 endmacro ()
+# ... except, when target is a module library type
+function (GENERATE_EXPORT_HEADER TARGET_LIBRARY)
+    get_property (type TARGET ${TARGET_LIBRARY} PROPERTY TYPE)
+    if (${type} MATCHES MODULE)
+        message (WARNING "This macro should not be used with libraries of type MODULE")
+        return ()
+    endif ()
+    _test_compiler_hidden_visibility()
+    _test_compiler_has_deprecated()
+    _do_set_macro_values(${TARGET_LIBRARY})
+    _do_generate_export_header(${TARGET_LIBRARY} ${ARGN})
+endfunction ()
 
 # Override builtin function to suit our need, takes care of C flags as well as CXX flags
 function (add_compiler_export_flags)
@@ -255,8 +271,15 @@ macro (setup_library)
         elseif (URHO3D_BUILD_TYPE STREQUAL STATIC)
             set_target_properties (${TARGET_NAME} PROPERTIES COMPILE_DEFINITIONS URHO3D_STATIC_DEFINE)
         endif ()
-        if (NOT WIN32)
-            # Specific to GCC build, locate the location of the objects that are used to link to this target to be used later by Urho3D library target
+        
+        # Locate the location of the objects that are used to link to this target to be used later by Urho3D library target
+        if (MSVC)
+            # Specific to VS generator
+            add_custom_command (TARGET ${TARGET_NAME} PRE_LINK
+                COMMAND ${CMAKE_SOURCE_DIR}/cmake/Scripts/ObjectLocator.bat ${TARGET_NAME} ${CMAKE_BINARY_DIR}/CMakeScriptOutput ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}.dir/$<CONFIGURATION> $<TARGET_PROPERTY:${TARGET_NAME},SOURCES>
+                COMMENT "Locating object files")
+        else ()
+            # Specific to Makefile generator
             set_target_properties (${TARGET_NAME} PROPERTIES RULE_LAUNCH_LINK
                 "${CMAKE_SOURCE_DIR}/cmake/Scripts/ObjectLocator.sh ${TARGET_NAME} ${CMAKE_BINARY_DIR}/CMakeScriptOutput ${CMAKE_CURRENT_BINARY_DIR} <OBJECTS>\n")
         endif ()
@@ -407,7 +430,7 @@ macro (define_dependency_libs TARGET)
     endif ()
     
     if (LINK_LIBS_ONLY)
-        list (REMOVE_DUPLICATES LINK_LIBS_ONLY)
         list (SORT LINK_LIBS_ONLY)
+        list (REMOVE_DUPLICATES LINK_LIBS_ONLY)
     endif ()
 endmacro ()

+ 34 - 0
cmake/Scripts/ObjectLocator.bat

@@ -0,0 +1,34 @@
+::
+:: Copyright (c) 2008-2013 the Urho3D project.
+::
+:: Permission is hereby granted, free of charge, to any person obtaining a copy
+:: of this software and associated documentation files (the "Software"), to deal
+:: in the Software without restriction, including without limitation the rights
+:: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+:: copies of the Software, and to permit persons to whom the Software is
+:: furnished to do so, subject to the following conditions:
+::
+:: The above copyright notice and this permission notice shall be included in
+:: all copies or substantial portions of the Software.
+::
+:: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+:: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+:: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+:: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+:: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+:: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+:: THE SOFTWARE.
+::
+
+:: This script is being called by CMake during MSVC build
+:: PLEASE DO NOT EDIT unless you know what you are doing
+@echo off
+set "target=%1"
+set "outdir=%2"
+set "objdir=%3"
+echo |set /p=>%outdir%/%target%.obj
+for %%o in (%*) do call :append %%o
+exit /B 0
+:append
+if not "%~x1" == ".cpp" if not "%~x1" == ".c" goto :eof
+echo |set /p=%objdir%/%~n1.obj >>%outdir%/%target%.obj

+ 1 - 1
cmake/Scripts/ObjectLocator.sh

@@ -21,7 +21,7 @@
 # THE SOFTWARE.
 #
 
-# This script is being called by CMake during GCC build
+# This script is being called by CMake during Makefile build
 # PLEASE DO NOT EDIT unless you know what you are doing
 target=$1; shift
 outdir=$1; shift