!F (Profiling) (DEV-7030) Rewrite of the profiling system to have a unified interface...
[CRYENGINE.git] / Tools / CMake / Configure.cmake
blobee17ee842e3d7500f6b7bb9058571e529db42507
1 if(DURANGO OR ORBIS OR ANDROID OR LINUX)
2         unset(WIN32)
3         unset(WINDOWS)
4 elseif(WIN32) # Either Win32 or Win64
5         include("${CMAKE_CURRENT_LIST_DIR}/toolchain/windows/WindowsPC-MSVC.cmake")
6 endif()
8 # C/C++ languages required.
9 enable_language(C)
10 enable_language(CXX)
12 if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio")
13         set(valid_configs Debug Profile Release)
14         list(FIND valid_configs "${CMAKE_BUILD_TYPE}" config_index)
15         if(${config_index} EQUAL -1)
16                 message(SEND_ERROR "Build type \"${CMAKE_BUILD_TYPE}\" is not supported, set CMAKE_BUILD_TYPE to one of ${valid_configs}")
17         endif()
18 endif()
20 # Correct output directory slashes, has to be done after toolchain includes
21 if (OUTPUT_DIRECTORY)
22         string(REPLACE "\\" "/" OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}")
23 else()
24         # Note that PROJECT_DIR can be different depending on whether we're building the engine or a standalone game / plugin project
25         set(OUTPUT_DIRECTORY "${PROJECT_DIR}/bin")
26 endif()
28 if(OUTPUT_DIRECTORY_NAME)
29         set(OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}/${OUTPUT_DIRECTORY_NAME}")
30         set(OUTPUT_DIRECTORY_NAME "")
31 endif()
33 set(BASE_OUTPUT_DIRECTORY         "${OUTPUT_DIRECTORY}")
34 set(BASE_OUTPUT_DIRECTORY_DEBUG   "${OUTPUT_DIRECTORY}")
35 set(BASE_OUTPUT_DIRECTORY_PROFILE "${OUTPUT_DIRECTORY}")
36 set(BASE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIRECTORY}_release")
38 set(OUTPUT_DIRECTORY_SUFFIX "" CACHE STRING "Optional suffix for the binary output directory")
39 if(OUTPUT_DIRECTORY_SUFFIX)
40         set(OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}_${OUTPUT_DIRECTORY_SUFFIX}")
41 endif()
43 set(METADATA_PROJECT_NAME "CryEngine" CACHE STRING "Name of the solution project")
44 project("${METADATA_PROJECT_NAME}_CMake_${BUILD_PLATFORM}" CXX C)
46 # Prefix all Visual Studio solution folder names with this string
47 set( VS_FOLDER_PREFIX "CRYENGINE/" )
49 set(MODULES CACHE INTERNAL "List of engine modules being built" FORCE)
50 set(GAME_MODULES CACHE INTERNAL "List of game modules being built" FORCE)
52 if (DURANGO OR ORBIS OR ANDROID OR LINUX)
53         # WIN32 Should be unset  again after project( line to work correctly
54         unset(WIN32)
55         unset(WINDOWS)
56 endif ()
58 set(game_folder CACHE INTERNAL "Game folder used for resource files on Windows" FORCE)
60 # Define Options
61 get_property(global_defines DIRECTORY "${CRYENGINE_DIR}" PROPERTY COMPILE_DEFINITIONS)
62 get_property(global_includes DIRECTORY "${CRYENGINE_DIR}" PROPERTY INCLUDE_DIRECTORIES)
63 get_property(global_links DIRECTORY "${CRYENGINE_DIR}" PROPERTY LINK_DIRECTORIES)
65 if (OPTION_PROFILE)
66         set_property( DIRECTORY PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Release>:_PROFILE> )
67 else()
68         set_property( DIRECTORY PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Release>:_RELEASE> )
69 endif()
71 if(OPTION_UNITY_BUILD)
72         message(STATUS "UNITY BUILD Enabled")
73 endif()
75 # SDK Directory
76 if (LINUX AND LINUX_BOOTSTRAP_FOLDER)
77         set(SDK_DIR "${LINUX_BOOTSTRAP_FOLDER}")
78 else()
79         set(SDK_DIR "${CRYENGINE_DIR}/Code/SDKs")
80 endif()
82 set(CRY_LIBS_DIR "${CRYENGINE_DIR}/Code/Libs")
83 set(CRY_EXTENSIONS_DIR "${CRYENGINE_DIR}/Code/CryExtensions")
85 set(WINSDK_SDK_DIR "${SDK_DIR}/Microsoft Windows SDK")
86 set(WINSDK_SDK_LIB_DIR "${WINSDK_SDK_DIR}/V8.0/Lib/Win8/um")
87 set(WINSDK_SDK_INCLUDE_DIR "${WINSDK_SDK_DIR}/V8.0/Include/um")
89 if (NOT EXISTS "${CMAKE_BINARY_DIR}/ProjectCVarOverrides.h")
90         file(WRITE "${CMAKE_BINARY_DIR}/ProjectCVarOverrides.h" "")
91 endif ()
92 list(APPEND global_defines "CRY_CVAR_OVERRIDE_FILE=\"${CMAKE_BINARY_DIR}/ProjectCVarOverrides.h\"")
94 if (NOT EXISTS "${CMAKE_BINARY_DIR}/ProjectCVarWhitelist.h")
95         file(WRITE "${CMAKE_BINARY_DIR}/ProjectCVarWhitelist.h" "")
96 endif ()
97 list(APPEND global_defines "CRY_CVAR_WHITELIST_FILE=\"${CMAKE_BINARY_DIR}/ProjectCVarWhitelist.h\"")
99 if (NOT EXISTS "${CMAKE_BINARY_DIR}/ProjectEngineDefineOverrides.h")
100         file(WRITE "${CMAKE_BINARY_DIR}/ProjectEngineDefineOverrides.h" "")
101 endif ()
102 list(APPEND global_defines "CRY_ENGINE_DEFINE_OVERRIDE_FILE=\"${CMAKE_BINARY_DIR}/ProjectEngineDefineOverrides.h\"")
104 if (OPTION_RUNTIME_CVAR_OVERRIDES)
105         list(APPEND global_defines "USE_RUNTIME_CVAR_OVERRIDES")
106 endif()
108 # Print current project settings
109 MESSAGE(STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
110 MESSAGE(STATUS "CMAKE_GENERATOR = ${CMAKE_GENERATOR}")
111 MESSAGE(STATUS "CMAKE_CONFIGURATION_TYPES = ${CMAKE_CONFIGURATION_TYPES}")
112 MESSAGE(STATUS "BUILD_PLATFORM = ${BUILD_PLATFORM}")
113 MESSAGE(STATUS "OPTION_PROFILE = ${OPTION_PROFILE}")
114 MESSAGE(STATUS "OPTION_PCH = ${OPTION_PCH}")
115 MESSAGE(STATUS "MSVC = ${MSVC}")
116 MESSAGE(STATUS "CRYENGINE_DIR = ${CRYENGINE_DIR}")
117 MESSAGE(STATUS "SDK_DIR = ${SDK_DIR}")
119 # custom defines
120 list(APPEND global_defines "CRYENGINE_DEFINE")
122 include("${TOOLS_CMAKE_DIR}/CommonOptions.cmake")
124 # Must be included after SDK_DIR definition
125 include("${TOOLS_CMAKE_DIR}/CopyFilesToBin.cmake")
127 if(MSVC_VERSION AND NOT OPTION_PGO STREQUAL "Off")
128         if (OPTION_RECODE)
129                 MESSAGE(STATUS "Cannot support Recode with PGO enabled - disabling Recode support")
130                 set(OPTION_RECODE OFF CACHE BOOL "Enable support for Recode" FORCE)
131         endif()
132         if (NOT OPTION_LTCG)
133                 MESSAGE(STATUS "OPTION_LTCG is required for PGO - enabling LTCG")
134                 set(OPTION_LTCG ON CACHE BOOL "Enable link-time code generation/optimization" FORCE)
135         endif()
136 endif()
139 if (OPTION_STATIC_LINKING_WITH_GAME_AS_DLL)
140                 MESSAGE(STATUS "Enabling OPTION_STATIC_LINKING because OPTION_STATIC_LINKING_WITH_GAME_AS_DLL was set")
141                 set(OPTION_STATIC_LINKING ON CACHE BOOL "Enabling OPTION_STATIC_LINKING because OPTION_STATIC_LINKING_WITH_GAME_AS_DLL was set" FORCE)
142 endif()
144 if(OPTION_STATIC_LINKING)
145         # Enable static libraries
146         MESSAGE(STATUS "Use Static Linking (.lib/.a)" )
147         set(BUILD_SHARED_LIBS FALSE)
148 else()
149         # Enable dynamic librariesboost
150         MESSAGE(STATUS "Use Dynamic Linking (.dll/.so)" )
151         set(BUILD_SHARED_LIBS TRUE)
152 endif()
154 if (OUTPUT_DIRECTORY)
155         if(OPTION_DEDICATED_SERVER)
156                 set(OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}_dedicated")
157         endif()
159         message(STATUS "OUTPUT_DIRECTORY=${OUTPUT_DIRECTORY}")
160         set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}")
161         set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY}")
162         set(EXECUTABLE_OUTPUT_PATH "${OUTPUT_DIRECTORY}")
164         # Make sure the output directory exists
165         file(MAKE_DIRECTORY "${OUTPUT_DIRECTORY}")
166 endif (OUTPUT_DIRECTORY)
168 include("${TOOLS_CMAKE_DIR}/ConfigureChecks.cmake")
169 include("${TOOLS_CMAKE_DIR}/CommonMacros.cmake")
170 include("${TOOLS_CMAKE_DIR}/Recode.cmake")
172 if(WINDOWS)
173         # Common Libriries linked to all targets
174         set(COMMON_LIBS Ntdll User32 Advapi32 Ntdll Ws2_32)
176         if (EXISTS "${SDK_DIR}/GPA" AND OPTION_ENGINE)
177                 list(APPEND global_includes "${SDK_DIR}/GPA/include" )
178                 list(APPEND global_links "${SDK_DIR}/GPA/lib64" )
179                 set(COMMON_LIBS ${COMMON_LIBS} jitprofiling libittnotify)
180         endif()
181 else()
182         # Common Libriries linked to all targets
183         set(COMMON_LIBS )
184 endif()
186 # add global defines
187 foreach( current_define ${platform_defines} )
188         list(APPEND global_defines "${current_define}")
189 endforeach()
191 if (OPTION_RELEASE_PROFILING)
192         list(APPEND global_defines  "$<$<CONFIG:Release>:PERFORMANCE_BUILD>")
193 endif()
194 if (OPTION_RELEASE_LOGGING)
195         list(APPEND global_defines  "$<$<CONFIG:Release>:RELEASE_LOGGING>")
196 endif()
199 if (OPTION_ENGINE)
200         if(NOT TARGET SDL2)
201                 include("${TOOLS_CMAKE_DIR}/modules/SDL2.cmake")
202         endif()
203         if(NOT TARGET ncursesw)
204            include("${TOOLS_CMAKE_DIR}/modules/ncurses.cmake")
205    endif()
207         option(OPTION_GEOM_CACHES "Enable Geom Cache" ON)
209         if(OPTION_GEOM_CACHES)
210                 list(APPEND global_defines USE_GEOM_CACHES=1)
211         endif()
212         
213         option(OPTION_FPE "Enable floating point exceptions" OFF)
215         if(OPTION_FPE)
216                 list(APPEND global_defines USE_FPE=1)
217         endif()
218 endif()
219 include("${TOOLS_CMAKE_DIR}/modules/Boost.cmake")
221 # Apply global defines
222 set_property(DIRECTORY "${CRYENGINE_DIR}" PROPERTY COMPILE_DEFINITIONS ${global_defines})
223 set_property(DIRECTORY "${CRYENGINE_DIR}" PROPERTY INCLUDE_DIRECTORIES ${global_includes})
224 set_property(DIRECTORY "${CRYENGINE_DIR}" PROPERTY LINK_DIRECTORIES ${global_links})
225 # Used by game project when they share the solution with the engine.
226 set_property(DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY COMPILE_DEFINITIONS ${global_defines})
227 set_property(DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY INCLUDE_DIRECTORIES ${global_includes})
228 set_property(DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY LINK_DIRECTORIES ${global_links})
230 if (MSVC_VERSION GREATER 1900) # Visual Studio > 2015
231         set(MSVC_LIB_PREFIX vc140)
232 elseif (MSVC_VERSION EQUAL 1900) # Visual Studio 2015
233         set(MSVC_LIB_PREFIX vc140)
234 elseif (MSVC_VERSION EQUAL 1800) # Visual Studio 2013
235         set(MSVC_LIB_PREFIX vc120)
236 elseif (MSVC_VERSION EQUAL 1700) # Visual Studio 2012
237         set(MSVC_LIB_PREFIX "vc110")
238 else()
239         set(MSVC_LIB_PREFIX "")
240 endif()
243 if (NOT VERSION)
244         if (METADATA_VERSION)
245                 set(VERSION ${METADATA_VERSION})
246         else()
247                 set(VERSION "1.0.0.0")
248         endif()
249 endif()
250 set(METADATA_VERSION ${VERSION} CACHE STRING "Version number for executable metadata" FORCE)
252 if(WINDOWS)
253         if (NOT METADATA_COMPANY)
254                 set(METADATA_COMPANY "Crytek GmbH")
255         endif()
256         set(METADATA_COMPANY "${METADATA_COMPANY}" CACHE STRING "Company name for executable metadata")
258         if (NOT METADATA_COPYRIGHT)
259                 string(TIMESTAMP year "%Y")
260                 set(METADATA_COPYRIGHT "(C) ${year} ${METADATA_COMPANY}")
261         endif()
262         set(METADATA_COPYRIGHT "${METADATA_COPYRIGHT}" CACHE STRING "Copyright string for executable metadata") 
264         string(REPLACE . , METADATA_VERSION_COMMA ${METADATA_VERSION})
265         set(METADATA_VERSION_COMMA ${METADATA_VERSION_COMMA} CACHE INTERNAL "" FORCE)
266 endif(WINDOWS)
268 include("${TOOLS_CMAKE_DIR}/Build.cmake")