mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
Clean CMake files.
This commit is contained in:
parent
492f217330
commit
8a50895062
23 changed files with 239 additions and 238 deletions
|
|
@ -15,7 +15,6 @@ set(libDir "${CMAKE_SOURCE_DIR}/Engine/lib")
|
|||
set(srcDir "${CMAKE_SOURCE_DIR}/Engine/source")
|
||||
set(cmakeDir "${CMAKE_SOURCE_DIR}/Tools/CMake")
|
||||
|
||||
|
||||
# hide some things
|
||||
mark_as_advanced(CMAKE_INSTALL_PREFIX)
|
||||
mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
|
||||
|
|
@ -25,18 +24,25 @@ mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
|
|||
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${projectOutDir}/game)
|
||||
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${projectOutDir}/game)
|
||||
|
||||
###############################################################################
|
||||
### Source File Handling
|
||||
###############################################################################
|
||||
|
||||
# finds and adds sources files in a folder
|
||||
macro(addPath dir)
|
||||
set(tmpa "")
|
||||
file(GLOB tmpa
|
||||
set(tmp_files "")
|
||||
set(glob_config GLOB)
|
||||
if(${ARGC} GREATER 1 AND "${ARGV1}" STREQUAL "REC")
|
||||
set(glob_config GLOB_RECURSE)
|
||||
endif()
|
||||
file(${glob_config} tmp_files
|
||||
${dir}/*.cpp
|
||||
${dir}/*.c
|
||||
${dir}/*.cc
|
||||
${dir}/*.h)
|
||||
LIST(APPEND ${PROJECT_NAME}_files "${tmpa}")
|
||||
LIST(APPEND ${PROJECT_NAME}_files "${tmp_files}")
|
||||
LIST(APPEND ${PROJECT_NAME}_paths "${dir}")
|
||||
#message(STATUS "addPath ${PROJECT_NAME} : ${tmpa}")
|
||||
#set(t "${${t}};${tmpa}")
|
||||
#message(STATUS "addPath ${PROJECT_NAME} : ${tmp_files}")
|
||||
endmacro()
|
||||
|
||||
# adds a file to the sources
|
||||
|
|
@ -47,111 +53,115 @@ endmacro()
|
|||
|
||||
# finds and adds sources files in a folder recursively
|
||||
macro(addPathRec dir)
|
||||
set(tmpa "")
|
||||
file(GLOB_RECURSE tmpa
|
||||
${dir}/*.cpp
|
||||
${dir}/*.c
|
||||
${dir}/*.cc
|
||||
${dir}/*.h)
|
||||
LIST(APPEND ${PROJECT_NAME}_files "${tmpa}")
|
||||
LIST(APPEND ${PROJECT_NAME}_paths "${dir}")
|
||||
#message(STATUS "addPathRec ${PROJECT_NAME} : ${tmpa}")
|
||||
addPath("${dir}" "REC")
|
||||
endmacro()
|
||||
|
||||
# adds a definition
|
||||
###############################################################################
|
||||
### Definition Handling
|
||||
###############################################################################
|
||||
macro(__addDef def config)
|
||||
# two possibilities: a) target already known, so add it directly, or b) target not yet known, so add it to its cache
|
||||
if(TARGET ${PROJECT_NAME})
|
||||
#message(STATUS "directly applying defs: ${PROJECT_NAME} with config ${config}: ${def}")
|
||||
if("${config}" STREQUAL "")
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "${def}")
|
||||
else()
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS_${config} "${def}")
|
||||
endif()
|
||||
else()
|
||||
list(APPEND ${PROJECT_NAME}_defs_${config} ${def})
|
||||
#message(STATUS "added definition to cache: ${PROJECT_NAME}_defs_${config}: ${${PROJECT_NAME}_defs_${config}}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# adds a definition: argument 1: Nothing(for all), _DEBUG, _RELEASE, <more build configurations>
|
||||
macro(addDef def)
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "${def}")
|
||||
endmacro()
|
||||
# adds a definition
|
||||
macro(addDebugDef def)
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG "${def}")
|
||||
set(def_configs "")
|
||||
if(${ARGC} GREATER 1)
|
||||
foreach(config "${ARGV1}")
|
||||
__addDef(${def} ${config})
|
||||
endforeach()
|
||||
else()
|
||||
__addDef(${def} "")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# adds a required definition. Are processed on addExecutable or addStaticLib
|
||||
macro(addRequiredDefinition def)
|
||||
#message(STATUS "${PROJECT_NAME} : add def : ${def}")
|
||||
LIST( APPEND ${PROJECT_NAME}_required_definition ${def} )
|
||||
endmacro()
|
||||
# adds a required debug definition. Are processed on addExecutable or addStaticLib
|
||||
macro(addRequiredDebugDefinition def)
|
||||
#message(STATUS "${PROJECT_NAME} : add def : ${def}")
|
||||
LIST( APPEND ${PROJECT_NAME}_required_debug_definition ${def} )
|
||||
# this applies cached definitions onto the target
|
||||
macro(_process_defs)
|
||||
if(DEFINED ${PROJECT_NAME}_defs_)
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "${${PROJECT_NAME}_defs_}")
|
||||
#message(STATUS "applying defs to project ${PROJECT_NAME} on all configs: ${${PROJECT_NAME}_defs_}")
|
||||
endif()
|
||||
foreach(def_config ${CMAKE_CONFIGURATION_TYPES})
|
||||
string(TOUPPER "${def_config}" def_config)
|
||||
if(DEFINED ${PROJECT_NAME}_defs_${def_config})
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPILE_DEFINITIONS_${def_config} "${${PROJECT_NAME}_defs_${def_config}}")
|
||||
#message(STATUS "applying defs to project ${PROJECT_NAME} on config ${def_config}: ${${PROJECT_NAME}_defs_${def_config}}")
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# add definitions to project
|
||||
macro( _processProjectDefinition )
|
||||
foreach( def ${${PROJECT_NAME}_required_definition} )
|
||||
addDef( ${def} )
|
||||
endforeach()
|
||||
|
||||
foreach( def ${${PROJECT_NAME}_required_debug_definition} )
|
||||
addDebugDef( ${def} )
|
||||
###############################################################################
|
||||
### Source Library Handling
|
||||
###############################################################################
|
||||
macro(addLibSrc libPath)
|
||||
set(cached_project_name ${PROJECT_NAME})
|
||||
include(${libPath})
|
||||
project(${cached_project_name})
|
||||
endmacro()
|
||||
|
||||
###############################################################################
|
||||
### Linked Library Handling
|
||||
###############################################################################
|
||||
macro(addLib libs)
|
||||
foreach(lib ${libs})
|
||||
# check if we can build it ourselfs
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libraries/${lib}.cmake")
|
||||
addLibSrc("${CMAKE_CURRENT_SOURCE_DIR}/libraries/${lib}.cmake")
|
||||
endif()
|
||||
# then link against it
|
||||
# two possibilities: a) target already known, so add it directly, or b) target not yet known, so add it to its cache
|
||||
if(TARGET ${PROJECT_NAME})
|
||||
target_link_libraries(${PROJECT_NAME} "${lib}")
|
||||
else()
|
||||
list(APPEND ${PROJECT_NAME}_libs ${lib})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
#clear required defs
|
||||
set( ${PROJECT_NAME}_required_definition )
|
||||
set( ${PROJECT_NAME}_required_debug_definition )
|
||||
endmacro()
|
||||
|
||||
# adds an include path
|
||||
# this applies cached definitions onto the target
|
||||
macro(_process_libs)
|
||||
if(DEFINED ${PROJECT_NAME}_libs)
|
||||
target_link_libraries(${PROJECT_NAME} "${${PROJECT_NAME}_libs}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
###############################################################################
|
||||
### Include Handling
|
||||
###############################################################################
|
||||
macro(addInclude incPath)
|
||||
#message(STATUS "${PROJECT_NAME} : add include path : ${incPath}")
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${incPath}")
|
||||
if(TARGET ${PROJECT_NAME})
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${incPath}")
|
||||
else()
|
||||
list(APPEND ${PROJECT_NAME}_includes ${incPath})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# adds a library to link against
|
||||
macro(addLib lib)
|
||||
#message(STATUS "${PROJECT_NAME} : add lib : ${lib}")
|
||||
target_link_libraries(${PROJECT_NAME} "${lib}")
|
||||
# this applies cached definitions onto the target
|
||||
macro(_process_includes)
|
||||
if(DEFINED ${PROJECT_NAME}_includes)
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${${PROJECT_NAME}_includes}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# adds a library dependency. Are processed on addExecutable or addStaticLib
|
||||
macro(addRequiredLibrary lib)
|
||||
#message(STATUS "${PROJECT_NAME} : add lib : ${lib}")
|
||||
LIST( APPEND ${PROJECT_NAME}_required_library ${lib} )
|
||||
endmacro()
|
||||
###############################################################################
|
||||
|
||||
# adds a link dependency. Are processed on addExecutable or addStaticLib
|
||||
macro(addRequiredLink lib)
|
||||
#message(STATUS "${PROJECT_NAME} : add lib : ${lib}")
|
||||
LIST( APPEND ${PROJECT_NAME}_required_link ${lib} )
|
||||
macro(_postTargetProcess)
|
||||
_process_includes()
|
||||
_process_defs()
|
||||
_process_libs()
|
||||
endmacro()
|
||||
|
||||
macro( _processProjectLibrary )
|
||||
# Append currect project to PROJECT_STACK
|
||||
LIST( APPEND PROJECT_STACK "${PROJECT_NAME}" )
|
||||
|
||||
foreach( lib ${${PROJECT_NAME}_required_library} )
|
||||
#message( "adding library dependency: ${lib}" )
|
||||
include( ${lib} )
|
||||
endforeach()
|
||||
|
||||
#clear required libraries
|
||||
set( ${PROJECT_NAME}_required_library )
|
||||
|
||||
# pop currect project form PROJECT_STACK
|
||||
LIST(REMOVE_AT PROJECT_STACK -1)
|
||||
|
||||
# get currect project form stack
|
||||
if( PROJECT_STACK )
|
||||
LIST(GET PROJECT_STACK -1 TEMP_PROJECT)
|
||||
project( ${TEMP_PROJECT} )
|
||||
endif()
|
||||
|
||||
|
||||
endmacro()
|
||||
|
||||
macro( _processProjectLinks )
|
||||
#message( "_processProjectLinks: ${PROJECT_NAME}" )
|
||||
foreach( lib ${${PROJECT_NAME}_required_link} )
|
||||
addLib( ${lib} )
|
||||
endforeach()
|
||||
|
||||
#clear required libraries
|
||||
set( ${PROJECT_NAME}_required_link )
|
||||
endmacro()
|
||||
|
||||
|
||||
# adds a path to search for libs
|
||||
macro(addLibPath dir)
|
||||
link_directories(${dir})
|
||||
|
|
@ -163,7 +173,7 @@ macro(generateFilters relDir)
|
|||
# Get the path of the file relative to ${DIRECTORY},
|
||||
# then alter it (not compulsory)
|
||||
file(RELATIVE_PATH SRCGR ${relDir} ${f})
|
||||
set(SRCGR "${PROJECT_NAME}/${SRCGR}")
|
||||
set(SRCGR "${PROJECT_NAME}/${SRCGR}")
|
||||
# Extract the folder, ie remove the filename part
|
||||
string(REGEX REPLACE "(.*)(/[^/]*)$" "\\1" SRCGR ${SRCGR})
|
||||
# do not have any ../ dirs
|
||||
|
|
@ -182,7 +192,7 @@ macro(generateFiltersSpecial relDir)
|
|||
# Get the path of the file relative to ${DIRECTORY},
|
||||
# then alter it (not compulsory)
|
||||
file(RELATIVE_PATH SRCGR ${relDir} ${f})
|
||||
set(SRCGR "torque3d/${SRCGR}")
|
||||
set(SRCGR "torque3d/${SRCGR}")
|
||||
# Extract the folder, ie remove the filename part
|
||||
string(REGEX REPLACE "(.*)(/[^/]*)$" "\\1" SRCGR ${SRCGR})
|
||||
# do not have any ../ dirs
|
||||
|
|
@ -200,8 +210,9 @@ macro(generateFiltersSpecial relDir)
|
|||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# macro to add a static library
|
||||
macro(addStaticLib)
|
||||
macro(finishLibrary)
|
||||
# more paths?
|
||||
if(${ARGC} GREATER 0)
|
||||
foreach(dir ${ARGV0})
|
||||
|
|
@ -216,23 +227,30 @@ macro(addStaticLib)
|
|||
endif()
|
||||
endforeach()
|
||||
generateFilters("${firstDir}")
|
||||
|
||||
# set per target compile flags
|
||||
if(TORQUE_CXX_FLAGS_${PROJECT_NAME})
|
||||
set_source_files_properties(${${PROJECT_NAME}_files} PROPERTIES COMPILE_FLAGS "${TORQUE_CXX_FLAGS_${PROJECT_NAME}}")
|
||||
else()
|
||||
set_source_files_properties(${${PROJECT_NAME}_files} PROPERTIES COMPILE_FLAGS "${TORQUE_CXX_FLAGS_LIBS}")
|
||||
endif()
|
||||
|
||||
if(TORQUE_STATIC)
|
||||
add_library("${PROJECT_NAME}" STATIC ${${PROJECT_NAME}_files})
|
||||
else()
|
||||
add_library("${PROJECT_NAME}" SHARED ${${PROJECT_NAME}_files})
|
||||
endif()
|
||||
# omg - only use the first folder ... otehrwise we get lots of header name collisions
|
||||
|
||||
# omg - only use the first folder ... otherwise we get lots of header name collisions
|
||||
#foreach(dir ${${PROJECT_NAME}_paths})
|
||||
addInclude("${firstDir}")
|
||||
#endforeach()
|
||||
|
||||
_processProjectLinks()
|
||||
_processProjectLibrary()
|
||||
_processProjectDefinition()
|
||||
|
||||
_postTargetProcess()
|
||||
endmacro()
|
||||
|
||||
# macro to add an executable
|
||||
macro(addExecutable)
|
||||
macro(finishExecutable)
|
||||
# now inspect the paths we got
|
||||
set(firstDir "")
|
||||
foreach(dir ${${PROJECT_NAME}_paths})
|
||||
|
|
@ -241,13 +259,18 @@ macro(addExecutable)
|
|||
endif()
|
||||
endforeach()
|
||||
generateFiltersSpecial("${firstDir}")
|
||||
|
||||
# set per target compile flags
|
||||
if(TORQUE_CXX_FLAGS_${PROJECT_NAME})
|
||||
set_source_files_properties(${${PROJECT_NAME}_files} PROPERTIES COMPILE_FLAGS "${TORQUE_CXX_FLAGS_${PROJECT_NAME}}")
|
||||
else()
|
||||
set_source_files_properties(${${PROJECT_NAME}_files} PROPERTIES COMPILE_FLAGS "${TORQUE_CXX_FLAGS_EXECUTABLES}")
|
||||
endif()
|
||||
|
||||
add_executable("${PROJECT_NAME}" WIN32 ${${PROJECT_NAME}_files})
|
||||
# omg - only use the first folder ... otehrwise we get lots of header name collisions
|
||||
addInclude("${firstDir}")
|
||||
|
||||
_processProjectLinks()
|
||||
_processProjectLibrary()
|
||||
_processProjectDefinition()
|
||||
|
||||
_postTargetProcess()
|
||||
endmacro()
|
||||
|
||||
macro(setupVersionNumbers)
|
||||
|
|
@ -287,13 +310,20 @@ set(TORQUE_STATIC ON)
|
|||
#option(TORQUE_STATIC "enables or disable static" OFF)
|
||||
|
||||
if(WIN32)
|
||||
set(TORQUE_CXX_FLAGS "/MP /O2 /Ob2 /Oi /Ot /Oy /GT /Zi /W4 /nologo /GF /EHsc /GS- /Gy- /Qpar- /arch:SSE2 /fp:fast /fp:except- /GR /Zc:wchar_t- /wd4018 /wd4100 /wd4121 /wd4127 /wd4130 /wd4244 /wd4245 /wd4389 /wd4511 /wd4512 /wd4800 /wd4995 /D_CRT_SECURE_NO_WARNINGS " CACHE TYPE STRING)
|
||||
mark_as_advanced(TORQUE_CXX_FLAGS)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORQUE_CXX_FLAGS}")
|
||||
set(TORQUE_CXX_FLAGS_EXECUTABLES "/wd4018 /wd4100 /wd4121 /wd4127 /wd4130 /wd4244 /wd4245 /wd4389 /wd4511 /wd4512 /wd4800 /wd4995 " CACHE TYPE STRING)
|
||||
mark_as_advanced(TORQUE_CXX_FLAGS_EXECUTABLES)
|
||||
|
||||
set(TORQUE_CXX_FLAGS_LIBS "/W0" CACHE TYPE STRING)
|
||||
mark_as_advanced(TORQUE_CXX_FLAGS_LIBS)
|
||||
|
||||
set(TORQUE_CXX_FLAGS_COMMON "-DUNICODE -D_UNICODE /MP /O2 /Ob2 /Oi /Ot /Oy /GT /Zi /W4 /nologo /GF /EHsc /GS- /Gy- /Qpar- /arch:SSE2 /fp:fast /fp:except- /GR /Zc:wchar_t- /D_CRT_SECURE_NO_WARNINGS" CACHE TYPE STRING)
|
||||
mark_as_advanced(TORQUE_CXX_FLAGS_COMMON)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORQUE_CXX_FLAGS_COMMON}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "/LARGEADDRESSAWARE")
|
||||
#set(STATIC_LIBRARY_FLAGS "/OPT:NOREF")
|
||||
|
||||
|
||||
# Force static runtime libraries
|
||||
if(TORQUE_STATIC)
|
||||
FOREACH(flag
|
||||
|
|
@ -309,6 +339,16 @@ if(WIN32)
|
|||
SET("${flag}" "${${flag}} /EHsc")
|
||||
ENDFOREACH()
|
||||
endif()
|
||||
else()
|
||||
# TODO: improve default settings on other platforms
|
||||
set(TORQUE_CXX_FLAGS_EXECUTABLES "" CACHE TYPE STRING)
|
||||
mark_as_advanced(TORQUE_CXX_FLAGS_EXECUTABLES)
|
||||
set(TORQUE_CXX_FLAGS_LIBS "" CACHE TYPE STRING)
|
||||
mark_as_advanced(TORQUE_CXX_FLAGS_LIBS)
|
||||
set(TORQUE_CXX_FLAGS_COMMON "" CACHE TYPE STRING)
|
||||
mark_as_advanced(TORQUE_CXX_FLAGS)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORQUE_CXX_FLAGS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue