1 # -----------------------------------------------------------------------------
2 # Copyright (c) 2014 GarageGames, LLC
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to
6 # deal in the Software without restriction, including without limitation the
7 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 # sell copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 # -----------------------------------------------------------------------------
23 project("Torque3DEngine")
25 if( CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8 )
26 set( TORQUE_CPU_X64 ON )
27 elseif( CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 4 )
28 set( TORQUE_CPU_X32 ON )
31 if(NOT TORQUE_TEMPLATE)
32 set(TORQUE_TEMPLATE "Full" CACHE STRING "the template to use")
34 if(NOT TORQUE_APP_DIR)
35 set(TORQUE_APP_DIR "${CMAKE_SOURCE_DIR}/My Projects/${TORQUE_APP_NAME}")
38 set(projectOutDir "${TORQUE_APP_DIR}/game")
41 set(projectSrcDir "${TORQUE_APP_DIR}/source")
43 set(libDir "${CMAKE_SOURCE_DIR}/Engine/lib")
44 set(srcDir "${CMAKE_SOURCE_DIR}/Engine/source")
45 set(cmakeDir "${CMAKE_SOURCE_DIR}/Tools/CMake")
48 mark_as_advanced(CMAKE_INSTALL_PREFIX)
49 mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
52 #set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${projectOutDir}/game)
53 #set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${projectOutDir}/game)
54 #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${projectOutDir}/game)
56 ###############################################################################
57 ### Source File Handling
58 ###############################################################################
60 # finds and adds sources files in a folder
64 if(${ARGC} GREATER 1 AND "${ARGV1}" STREQUAL "REC")
65 set(glob_config GLOB_RECURSE)
69 set(mac_files ${dir}/*.mm ${dir}/*.m)
71 file(${glob_config} tmp_files
79 foreach(entry ${BLACKLIST})
80 list(REMOVE_ITEM tmp_files ${dir}/${entry})
82 LIST(APPEND ${PROJECT_NAME}_files "${tmp_files}")
83 LIST(APPEND ${PROJECT_NAME}_paths "${dir}")
84 #message(STATUS "addPath ${PROJECT_NAME} : ${tmp_files}")
87 # adds a file to the sources
88 macro(addFile filename)
89 LIST(APPEND ${PROJECT_NAME}_files "${filename}")
90 #message(STATUS "addFile ${PROJECT_NAME} : ${filename}")
93 # finds and adds sources files in a folder recursively
95 addPath("${dir}" "REC")
98 ###############################################################################
99 ### Definition Handling
100 ###############################################################################
101 macro(__addDef def config)
102 # two possibilities: a) target already known, so add it directly, or b) target not yet known, so add it to its cache
103 if(TARGET ${PROJECT_NAME})
104 #message(STATUS "directly applying defs: ${PROJECT_NAME} with config ${config}: ${def}")
105 if("${config}" STREQUAL "")
106 set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS ${def})
108 set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:${config}>:${def}>)
111 if("${config}" STREQUAL "")
112 list(APPEND ${PROJECT_NAME}_defs_ ${def})
114 list(APPEND ${PROJECT_NAME}_defs_ $<$<CONFIG:${config}>:${def}>)
116 #message(STATUS "added definition to cache: ${PROJECT_NAME}_defs_: ${${PROJECT_NAME}_defs_}")
120 # adds a definition: argument 1: Nothing(for all), _DEBUG, _RELEASE, <more build configurations>
123 if(${ARGC} GREATER 1)
124 foreach(config ${ARGN})
125 __addDef(${def} ${config})
132 # this applies cached definitions onto the target
134 if(DEFINED ${PROJECT_NAME}_defs_)
135 set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS ${${PROJECT_NAME}_defs_})
136 #message(STATUS "applying defs to project ${PROJECT_NAME}: ${${PROJECT_NAME}_defs_}")
140 ###############################################################################
141 ### Source Library Handling
142 ###############################################################################
143 macro(addLibSrc libPath)
144 set(cached_project_name ${PROJECT_NAME})
146 project(${cached_project_name})
149 ###############################################################################
150 ### Linked Library Handling
151 ###############################################################################
154 # check if we can build it ourselfs
155 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libraries/${lib}.cmake")
156 addLibSrc("${CMAKE_CURRENT_SOURCE_DIR}/libraries/${lib}.cmake")
158 # then link against it
159 # two possibilities: a) target already known, so add it directly, or b) target not yet known, so add it to its cache
160 if(TARGET ${PROJECT_NAME})
161 target_link_libraries(${PROJECT_NAME} "${lib}")
163 list(APPEND ${PROJECT_NAME}_libs ${lib})
168 #addLibRelease will add to only release builds
169 macro(addLibRelease libs)
171 # check if we can build it ourselfs
172 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libraries/${lib}.cmake")
173 addLibSrc("${CMAKE_CURRENT_SOURCE_DIR}/libraries/${lib}.cmake")
175 # then link against it
176 # two possibilities: a) target already known, so add it directly, or b) target not yet known, so add it to its cache
177 if(TARGET ${PROJECT_NAME})
178 target_link_libraries(${PROJECT_NAME} optimized "${lib}")
180 list(APPEND ${PROJECT_NAME}_libsRelease ${lib})
185 #addLibDebug will add to only debug builds
186 macro(addLibDebug libs)
188 # check if we can build it ourselfs
189 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libraries/${lib}.cmake")
190 addLibSrc("${CMAKE_CURRENT_SOURCE_DIR}/libraries/${lib}.cmake")
192 # then link against it
193 # two possibilities: a) target already known, so add it directly, or b) target not yet known, so add it to its cache
194 if(TARGET ${PROJECT_NAME})
195 target_link_libraries(${PROJECT_NAME} debug "${lib}")
197 list(APPEND ${PROJECT_NAME}_libsDebug ${lib})
202 # this applies cached definitions onto the target
204 if(DEFINED ${PROJECT_NAME}_libs)
205 target_link_libraries(${PROJECT_NAME} "${${PROJECT_NAME}_libs}")
207 if(DEFINED ${PROJECT_NAME}_libsRelease)
208 target_link_libraries(${PROJECT_NAME} optimized "${${PROJECT_NAME}_libsRelease}")
210 if(DEFINED ${PROJECT_NAME}_libsDebug)
211 target_link_libraries(${PROJECT_NAME} debug "${${PROJECT_NAME}_libsDebug}")
217 macro(addFramework framework)
219 addLib("-framework ${framework}")
223 ###############################################################################
225 ###############################################################################
226 macro(addInclude incPath)
227 if(TARGET ${PROJECT_NAME})
228 set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${incPath}")
230 list(APPEND ${PROJECT_NAME}_includes ${incPath})
234 # this applies cached definitions onto the target
235 macro(_process_includes)
236 if(DEFINED ${PROJECT_NAME}_includes)
237 set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${${PROJECT_NAME}_includes}")
241 ###############################################################################
243 macro(_postTargetProcess)
249 # adds a path to search for libs
250 macro(addLibPath dir)
251 link_directories(${dir})
254 # creates a proper filter for VS
255 macro(generateFilters relDir)
256 foreach(f ${${PROJECT_NAME}_files})
257 # Get the path of the file relative to ${DIRECTORY},
258 # then alter it (not compulsory)
259 file(RELATIVE_PATH SRCGR ${relDir} ${f})
260 set(SRCGR "${PROJECT_NAME}/${SRCGR}")
261 # Extract the folder, ie remove the filename part
262 string(REGEX REPLACE "(.*)(/[^/]*)$" "\\1" SRCGR ${SRCGR})
263 # do not have any ../ dirs
264 string(REPLACE "../" "" SRCGR ${SRCGR})
265 # Source_group expects \\ (double antislash), not / (slash)
266 string(REPLACE / \\ SRCGR ${SRCGR})
267 #STRING(REPLACE "//" "/" SRCGR ${SRCGR})
268 #message(STATUS "FILE: ${f} -> ${SRCGR}")
269 source_group("${SRCGR}" FILES ${f})
273 # creates a proper filter for VS
274 macro(generateFiltersSpecial relDir)
275 foreach(f ${${PROJECT_NAME}_files})
276 # Get the path of the file relative to ${DIRECTORY},
277 # then alter it (not compulsory)
278 file(RELATIVE_PATH SRCGR ${relDir} ${f})
279 set(SRCGR "torque3d/${SRCGR}")
280 # Extract the folder, ie remove the filename part
281 string(REGEX REPLACE "(.*)(/[^/]*)$" "\\1" SRCGR ${SRCGR})
282 # do not have any ../ dirs
283 string(REPLACE "../" "" SRCGR ${SRCGR})
284 IF("${SRCGR}" MATCHES "^torque3d/My Projects/.*$")
285 string(REPLACE "torque3d/My Projects/${PROJECT_NAME}/" "" SRCGR ${SRCGR})
286 string(REPLACE "/source" "" SRCGR ${SRCGR})
288 # Source_group expects \\ (double antislash), not / (slash)
289 string(REPLACE / \\ SRCGR ${SRCGR})
290 #STRING(REPLACE "//" "/" SRCGR ${SRCGR})
291 IF(EXISTS "${f}" AND NOT IS_DIRECTORY "${f}")
292 #message(STATUS "FILE: ${f} -> ${SRCGR}")
293 source_group("${SRCGR}" FILES ${f})
298 # macro to add a static library
301 if(${ARGC} GREATER 0)
302 foreach(dir ${ARGV0})
306 # now inspect the paths we got
308 foreach(dir ${${PROJECT_NAME}_paths})
309 if("${firstDir}" STREQUAL "")
310 set(firstDir "${dir}")
313 generateFilters("${firstDir}")
315 # set per target compile flags
316 if(TORQUE_CXX_FLAGS_${PROJECT_NAME})
317 set_source_files_properties(${${PROJECT_NAME}_files} PROPERTIES COMPILE_FLAGS "${TORQUE_CXX_FLAGS_${PROJECT_NAME}}")
319 set_source_files_properties(${${PROJECT_NAME}_files} PROPERTIES COMPILE_FLAGS "${TORQUE_CXX_FLAGS_LIBS}")
323 add_library("${PROJECT_NAME}" STATIC ${${PROJECT_NAME}_files})
325 add_library("${PROJECT_NAME}" SHARED ${${PROJECT_NAME}_files})
328 # omg - only use the first folder ... otherwise we get lots of header name collisions
329 #foreach(dir ${${PROJECT_NAME}_paths})
330 addInclude("${firstDir}")
336 # macro to add an executable
337 macro(finishExecutable)
338 # now inspect the paths we got
340 foreach(dir ${${PROJECT_NAME}_paths})
341 if("${firstDir}" STREQUAL "")
342 set(firstDir "${dir}")
345 generateFiltersSpecial("${firstDir}")
347 # set per target compile flags
348 if(TORQUE_CXX_FLAGS_${PROJECT_NAME})
349 set_source_files_properties(${${PROJECT_NAME}_files} PROPERTIES COMPILE_FLAGS "${TORQUE_CXX_FLAGS_${PROJECT_NAME}}")
351 set_source_files_properties(${${PROJECT_NAME}_files} PROPERTIES COMPILE_FLAGS "${TORQUE_CXX_FLAGS_EXECUTABLES}")
355 set(ICON_FILE "${projectSrcDir}/torque.icns")
356 set_source_files_properties(${ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
357 add_executable("${PROJECT_NAME}" MACOSX_BUNDLE ${ICON_FILE} ${${PROJECT_NAME}_files})
359 add_executable("${PROJECT_NAME}" WIN32 ${${PROJECT_NAME}_files})
361 addInclude("${firstDir}")
366 macro(setupVersionNumbers)
367 set(TORQUE_APP_VERSION_MAJOR 1 CACHE INTEGER "")
368 set(TORQUE_APP_VERSION_MINOR 0 CACHE INTEGER "")
369 set(TORQUE_APP_VERSION_PATCH 0 CACHE INTEGER "")
370 set(TORQUE_APP_VERSION_TWEAK 0 CACHE INTEGER "")
371 mark_as_advanced(TORQUE_APP_VERSION_TWEAK)
372 MATH(EXPR TORQUE_APP_VERSION "${TORQUE_APP_VERSION_MAJOR} * 1000 + ${TORQUE_APP_VERSION_MINOR} * 100 + ${TORQUE_APP_VERSION_PATCH} * 10 + ${TORQUE_APP_VERSION_TWEAK}")
373 set(TORQUE_APP_VERSION_STRING "${TORQUE_APP_VERSION_MAJOR}.${TORQUE_APP_VERSION_MINOR}.${TORQUE_APP_VERSION_PATCH}.${TORQUE_APP_VERSION_TWEAK}")
374 #message(STATUS "version numbers: ${TORQUE_APP_VERSION} / ${TORQUE_APP_VERSION_STRING}")
377 macro(setupPackaging)
379 # only enable zips for now
380 set(CPACK_BINARY_NSIS OFF CACHE INTERNAL "" FORCE)
381 set(CPACK_BINARY_ZIP ON CACHE INTERNAL "" FORCE)
382 set(CPACK_SOURCE_ZIP OFF CACHE INTERNAL "" FORCE)
383 SET(CPACK_GENERATOR "ZIP")
384 SET(CPACK_PACKAGE_VENDOR "${PROJECT_NAME}")
385 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_NAME}")
386 SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 1)
387 SET(CPACK_OUTPUT_FILE_PREFIX "${TORQUE_APP_DIR}/packages/${PROJECT_NAME}")
388 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "")
389 #SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ReadMe.txt")
390 #SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
391 SET(CPACK_PACKAGE_VERSION_MAJOR "${TORQUE_APP_VERSION_MAJOR}")
392 SET(CPACK_PACKAGE_VERSION_MINOR "${TORQUE_APP_VERSION_MINOR}")
393 SET(CPACK_PACKAGE_VERSION_PATCH "${TORQUE_APP_VERSION_PATCH}")
394 #SET(CPACK_PACKAGE_EXECUTABLES "${PROJECT_NAME}" "${PROJECT_NAME}")
395 SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${TORQUE_APP_VERSION_STRING}")
396 #SET(CPACK_SOURCE_STRIP_FILES "")
398 # always static for now
399 set(TORQUE_STATIC ON)
400 #option(TORQUE_STATIC "enables or disable static" OFF)
403 set(TORQUE_CXX_FLAGS_EXECUTABLES "/wd4018 /wd4100 /wd4121 /wd4127 /wd4130 /wd4244 /wd4245 /wd4389 /wd4511 /wd4512 /wd4800 /wd4995 " CACHE TYPE STRING)
404 mark_as_advanced(TORQUE_CXX_FLAGS_EXECUTABLES)
406 set(TORQUE_CXX_FLAGS_LIBS "/W0" CACHE TYPE STRING)
407 mark_as_advanced(TORQUE_CXX_FLAGS_LIBS)
409 set(TORQUE_CXX_FLAGS_COMMON_DEFAULT "-DUNICODE -D_UNICODE -D_CRT_SECURE_NO_WARNINGS /MP /O2 /Ob2 /Oi /Ot /Oy /GT /Zi /W4 /nologo /GF /EHsc /GS- /Gy- /Qpar- /fp:precise /fp:except- /GR /Zc:wchar_t-" )
411 set(TORQUE_CXX_FLAGS_COMMON_DEFAULT "${TORQUE_CXX_FLAGS_COMMON_DEFAULT} /arch:SSE2")
413 set(TORQUE_CXX_FLAGS_COMMON ${TORQUE_CXX_FLAGS_COMMON_DEFAULT} CACHE TYPE STRING)
415 mark_as_advanced(TORQUE_CXX_FLAGS_COMMON)
417 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORQUE_CXX_FLAGS_COMMON}")
418 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
419 set(CMAKE_EXE_LINKER_FLAGS "/LARGEADDRESSAWARE")
420 #set(STATIC_LIBRARY_FLAGS "/OPT:NOREF")
422 # Force static runtime libraries
425 CMAKE_C_FLAGS_RELEASE
426 CMAKE_C_FLAGS_RELWITHDEBINFO
428 CMAKE_C_FLAGS_DEBUG_INIT
429 CMAKE_CXX_FLAGS_RELEASE
430 CMAKE_CXX_FLAGS_RELWITHDEBINFO
431 CMAKE_CXX_FLAGS_DEBUG
432 CMAKE_CXX_FLAGS_DEBUG_INIT)
433 STRING(REPLACE "/MD" "/MT" "${flag}" "${${flag}}")
434 SET("${flag}" "${${flag}} /EHsc")
438 # TODO: improve default settings on other platforms
439 set(TORQUE_CXX_FLAGS_EXECUTABLES "" CACHE TYPE STRING)
440 mark_as_advanced(TORQUE_CXX_FLAGS_EXECUTABLES)
441 set(TORQUE_CXX_FLAGS_LIBS "" CACHE TYPE STRING)
442 mark_as_advanced(TORQUE_CXX_FLAGS_LIBS)
443 set(TORQUE_CXX_FLAGS_COMMON "" CACHE TYPE STRING)
444 mark_as_advanced(TORQUE_CXX_FLAGS)
445 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORQUE_CXX_FLAGS}")
446 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
449 if(UNIX AND NOT APPLE)
450 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${projectOutDir}")
451 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${projectOutDir}")
452 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${projectOutDir}")
453 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${projectOutDir}")
457 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${projectOutDir}")
458 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${projectOutDir}")
459 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${projectOutDir}")
460 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${projectOutDir}")
463 # fix the debug/release subfolders on windows
465 SET("CMAKE_RUNTIME_OUTPUT_DIRECTORY" "${projectOutDir}")
466 FOREACH(CONF ${CMAKE_CONFIGURATION_TYPES})
467 # Go uppercase (DEBUG, RELEASE...)
468 STRING(TOUPPER "${CONF}" CONF)
469 #SET("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONF}" "${projectOutDir}")
470 SET("CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONF}" "${projectOutDir}")