Merge remote-tracking branch 'public/release_candidate' into release
[CRYENGINE.git] / Tools / CMake / Build.cmake
blob5ec9cf5be20c79cce59dfdf2276b5eb7f331011f
1 include_guard(GLOBAL)
2 # Header guard to avoid duplicate execution when configuring (template) projects with OPTION_ENGINE
3 # Templates include Configure.cmake and add_subdirectory(${CRYENGINE_DIR}) which also includes Configure.cmake
4 # Templates do need Configure.cmake to set up some defines.
5 # In order to not have duplicate add_subdirectory calls (which causes errors), we need an include guard here.
7 if(OPTION_ENGINE OR OPTION_SHADERCACHEGEN OR OPTION_SCALEFORMHELPER OR OPTION_SANDBOX OR OPTION_PAKTOOLS OR OPTION_DOXYGEN_EXAMPLES)
8         # Add custom project with just listing of cmake files
9         add_subdirectory("${TOOLS_CMAKE_DIR}")
11         # Order currently matters for Engine, Games and Launchers
12         # 1. CryEngine
13         include ("${TOOLS_CMAKE_DIR}/BuildEngine.cmake")
14 endif()
16 # Sandbox Editor
17 if (OPTION_SANDBOX AND OPTION_STATIC_LINKING)
18         message(STATUS "Disabling Sandbox - requires dynamic linking")
19         set(OPTION_SANDBOX OFF)
20 endif()
22 if (OPTION_SANDBOX AND WINDOWS)
23         set(QT_DEPLOY_ROOT "${SDK_DIR}/Qt/5.12.3_python_37/msvc2017_64")
24         set(QT_DIR "${QT_DEPLOY_ROOT}/Qt")
25         set(Qt5_DIR "${QT_DIR}")
27         find_package(Qt5 COMPONENTS Core Gui OpenGL Widgets REQUIRED PATHS "${QT_DIR}" NO_DEFAULT_PATH)
29         set(QT_DIR "${QT_DIR}" CACHE INTERNAL "QT directory" FORCE)
30         set(Qt5_DIR "${Qt5_DIR}" CACHE INTERNAL "QT directory" FORCE)
32         set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER  "${VS_FOLDER_PREFIX}/Sandbox/AUTOGEN")
34         message(STATUS "Include Sandbox Editor")
35         include ("${TOOLS_CMAKE_DIR}/BuildSandbox.cmake")
36 endif()
37         
38 # Only allow building legacy GameDLL's with the engine, assuming that we're not using the project system
39 if(OPTION_ENGINE AND NOT PROJECT_BUILD)
40         # 2. Games
41         add_subdirectories_glob("Code/Game*")
42 endif()
43         
44 # 3. Extensions (deprecated / legacy)
45 if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/Code/CryExtensions")
46         add_subdirectory(Code/CryExtensions)
47 endif()
49 if(OPTION_ENGINE)
50         # 4. Plug-ins
51         add_subdirectory(Code/CryPlugins)
52 endif()
54 # 5. Launchers
55 include ("${TOOLS_CMAKE_DIR}/BuildLaunchers.cmake")
57 if (OPTION_CRYMONO)
58         add_subdirectory(Code/CryManaged)
59 endif()
61 macro(generate_crytest_targets target_name using_runner_target_name)
62         add_custom_target(${target_name})
63         set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
64         set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE)
65         set_property(TARGET ${target_name} PROPERTY FOLDER "_TEST_")
66         get_property(runner TARGET ${using_runner_target_name} PROPERTY OUTPUT_NAME )
67         if(NOT runner)
68                 set(runner ${using_runner_target_name})
69         endif()
70         #message("WindowsLauncherExe = ${WindowsLauncherExe}")
71         file( WRITE "${CMAKE_CURRENT_BINARY_DIR}/${target_name}.vcxproj.user" 
72         "<?xml version=\"1.0\" encoding=\"utf-8\"?>
73         <Project ToolsVersion=\"14.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">
74                         <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">
75                                 <LocalDebuggerCommand>${OUTPUT_DIRECTORY}/${runner}.exe</LocalDebuggerCommand>
76                                 <LocalDebuggerWorkingDirectory>${OUTPUT_DIRECTORY}</LocalDebuggerWorkingDirectory>
77                                 <LocalDebuggerCommandArguments>-run_crytest -crytest_open_report</LocalDebuggerCommandArguments>
78                                 <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
79                         </PropertyGroup>
80                         <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Profile|x64'\">
81                                 <LocalDebuggerCommand>${OUTPUT_DIRECTORY}/${runner}.exe</LocalDebuggerCommand>
82                                 <LocalDebuggerWorkingDirectory>${OUTPUT_DIRECTORY}</LocalDebuggerWorkingDirectory>
83                                 <LocalDebuggerCommandArguments>-run_crytest -crytest_open_report</LocalDebuggerCommandArguments>
84                                 <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
85                         </PropertyGroup>                
86                         <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">
87                                 <LocalDebuggerCommand>${OUTPUT_DIRECTORY}/${runner}.exe</LocalDebuggerCommand>
88                                 <LocalDebuggerWorkingDirectory>${OUTPUT_DIRECTORY}</LocalDebuggerWorkingDirectory>
89                                 <LocalDebuggerCommandArguments>-run_crytest -crytest_open_report</LocalDebuggerCommandArguments>
90                                 <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
91                         </PropertyGroup>
92                 </Project>")
94 endmacro()
96 # Run Unit Test
97 if (OPTION_ENGINE AND WINDOWS)
98         generate_crytest_targets(run_crytest WindowsLauncher)
99 endif()
101 if (OPTION_SANDBOX AND WINDOWS)
102         generate_crytest_targets(run_crytest_sandbox Sandbox)
103 endif()
105 if(WINDOWS AND EXISTS "${CRYENGINE_DIR}/Code/Tools/ShaderCacheGen/ShaderCacheGen")
106         option(OPTION_SHADERCACHEGEN "Build the shader cache generator." OFF)
107 endif()
109 if (OPTION_SHADERCACHEGEN)
110         add_subdirectory(Code/Tools/ShaderCacheGen/ShaderCacheGen)
111 endif()
113 if (OPTION_PAKTOOLS AND EXISTS "${CRYENGINE_DIR}/Code/Tools/PakEncrypt")
114         add_subdirectory(Code/Tools/PakEncrypt)
115 endif()
117 if (OPTION_RC AND EXISTS "${CRYENGINE_DIR}/Code/Tools/RC")
118         include(ExternalProject)
119         ExternalProject_Add(RC
120                 CMAKE_ARGS "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" "-DCMAKE_BUILD_TYPE=$<$<CONFIG:Profile>:Release>$<$<NOT:$<CONFIG:Profile>>:$<CONFIG>>"
121                 SOURCE_DIR "${CRYENGINE_DIR}/Code/Tools/RC"
122                 BUILD_COMMAND "${CMAKE_COMMAND}" --build "." --config $<$<CONFIG:Profile>:Release>$<$<NOT:$<CONFIG:Profile>>:$<CONFIG>>
123                 INSTALL_COMMAND echo "Skipping install"
124         )
125 endif()
127 if (OPTION_PHYSDBGR)
128         add_subdirectory(Code/Tools/PhysDebugger)
129 endif()
132 set(CMAKE_INSTALL_MESSAGE LAZY)
133 install(FILES "${TOOLS_CMAKE_DIR}/modules/CryCommonConfig.cmake" DESTINATION share/cmake)
134 install(FILES "${TOOLS_CMAKE_DIR}/modules/CryActionConfig.cmake" DESTINATION share/cmake)
136 copy_binary_files_to_target()