Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
6.6 KiB

  1. //========= (C) Copyright 2009-2016 Valve, L.L.C. All rights reserved. ========
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // $Header: $
  9. // $NoKeywords: $
  10. //
  11. //=============================================================================
  12. #include "tier0/dbg.h"
  13. #include "environment_utils.h"
  14. #ifdef PLATFORM_WINDOWS_PC
  15. #include <windows.h> // for RegGetValue
  16. #endif
  17. #undef GetCurrentDirectory
  18. #undef OUT
  19. #undef ERR
  20. #if defined( PLATFORM_WINDOWS_PC )
  21. bool VGetRegistryKeyValue( HKEY baseKey, const char *pSubKey, const char *pValue, char *pOutBuf, int nMaxBuf )
  22. {
  23. DWORD nBufSize = nMaxBuf;
  24. HKEY hKey = NULL;
  25. LONG nResult;
  26. nResult = RegOpenKeyEx( baseKey, pSubKey, NULL, KEY_READ, &hKey );
  27. if ( nResult == ERROR_SUCCESS )
  28. {
  29. nResult = RegQueryValueExA( hKey, pValue, NULL, NULL, (LPBYTE)pOutBuf, &nBufSize);
  30. RegCloseKey( hKey );
  31. return nResult == ERROR_SUCCESS;
  32. }
  33. return false;
  34. }
  35. #endif
  36. //--------------------------------------------------------------------------------------------------
  37. //--------------------------------------------------------------------------------------------------
  38. bool GetWindowsSDKDir( char *pOutBuf, int nMaxBuf )
  39. {
  40. #ifdef PLATFORM_WINDOWS_PC
  41. const char *pWindowsSDKDirRegKey = "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows";
  42. if( !VGetRegistryKeyValue( HKEY_LOCAL_MACHINE, pWindowsSDKDirRegKey, "CurrentInstallFolder", pOutBuf, nMaxBuf ) &&
  43. !VGetRegistryKeyValue( HKEY_CURRENT_USER, pWindowsSDKDirRegKey, "CurrentInstallFolder", pOutBuf, nMaxBuf ) )
  44. {
  45. Warning( "ERROR: Failed to read VS Windows SDK from registry key '%s'\n", pWindowsSDKDirRegKey );
  46. return false;
  47. }
  48. return true;
  49. #else
  50. return false;
  51. #endif
  52. }
  53. //--------------------------------------------------------------------------------------------------
  54. //--------------------------------------------------------------------------------------------------
  55. bool GetMSVCIncludePaths( CUtlVector<CUtlString> &paths, const char *pVSToolsEnv )
  56. {
  57. const char *pVSToolsPath = Plat_GetEnv( pVSToolsEnv );
  58. if ( !pVSToolsPath )
  59. {
  60. Warning( "ERROR: GetMSVCIncludePaths failed to read VS location from environment variable '%s'\n", pVSToolsEnv );
  61. return false;
  62. }
  63. char pWindowsSDKDir[MAX_PATH];
  64. if ( !GetWindowsSDKDir( pWindowsSDKDir, sizeof(pWindowsSDKDir) ) )
  65. {
  66. return false;
  67. }
  68. char pVSRootPath[MAX_PATH];
  69. V_MakeAbsolutePath( pVSRootPath, sizeof(pVSRootPath), "../../", pVSToolsPath );
  70. char pIncludePath[MAX_PATH];
  71. V_MakeAbsolutePath( pIncludePath, sizeof(pIncludePath), "VC/INCLUDE", pVSRootPath );
  72. paths.AddToTail( pIncludePath );
  73. V_MakeAbsolutePath( pIncludePath, sizeof(pIncludePath), "VC/ATLMFC/INCLUDE", pVSRootPath );
  74. paths.AddToTail( pIncludePath );
  75. V_MakeAbsolutePath( pIncludePath, sizeof(pIncludePath), "INCLUDE", pWindowsSDKDir );
  76. paths.AddToTail( pIncludePath );
  77. return true;
  78. }
  79. //--------------------------------------------------------------------------------------------------
  80. //--------------------------------------------------------------------------------------------------
  81. bool GetX360IncludePaths( CUtlVector<CUtlString> &paths )
  82. {
  83. const char *pXdkPathEnv = "XEDK";
  84. const char *pXdkPath = Plat_GetEnv( pXdkPathEnv );
  85. if ( !pXdkPath )
  86. {
  87. Warning( "ERROR: GetX360IncludePaths failed to read XDK location from environment variable '%s'\n", pXdkPath );
  88. return false;
  89. }
  90. char pIncludePath[MAX_PATH];
  91. V_MakeAbsolutePath( pIncludePath, sizeof(pIncludePath), "include/xbox", pXdkPath );
  92. paths.AddToTail( pIncludePath );
  93. V_MakeAbsolutePath( pIncludePath, sizeof(pIncludePath), "include/win32", pXdkPath );
  94. paths.AddToTail( pIncludePath );
  95. return true;
  96. }
  97. //--------------------------------------------------------------------------------------------------
  98. //--------------------------------------------------------------------------------------------------
  99. bool GetOSXIncludePaths( CUtlVector<CUtlString> &paths )
  100. {
  101. const char *pPath = Plat_GetEnv( "SDKROOT" );
  102. if ( !pPath )
  103. {
  104. pPath = Plat_GetEnv( "OSX_SDK_PATH" );
  105. if ( !pPath )
  106. {
  107. Warning( "ERROR: %s failed to read SDK location from environment variable 'SDKROOT' or 'OSX_SDK_PATH'\n",
  108. __FUNCTION__ );
  109. return false;
  110. }
  111. }
  112. char pIncludePath[MAX_PATH];
  113. V_MakeAbsolutePath( pIncludePath, sizeof(pIncludePath), "usr/include", pPath, false );
  114. paths.AddToTail( pIncludePath );
  115. return true;
  116. }
  117. //--------------------------------------------------------------------------------------------------
  118. //--------------------------------------------------------------------------------------------------
  119. bool GetSystemIncludePaths( CUtlVector<CUtlString> &paths, const char *pPlatform, const char *pCompiler )
  120. {
  121. #if !defined( PLATFORM_WINDOWS ) && !defined( PLATFORM_POSIX ) && !defined( PLATFORM_OSX )
  122. Warning( "ERROR: GetSystemIncludePaths not implemented for this platform!\n" );
  123. return false;
  124. #endif
  125. if ( !V_stricmp_fast( pPlatform, "WIN32" ) || !V_stricmp_fast( pPlatform, "WIN64" ) )
  126. {
  127. if ( !V_stricmp_fast( pCompiler, "VS2005" ) )
  128. {
  129. return GetMSVCIncludePaths( paths, "VS80COMNTOOLS" );
  130. }
  131. else if ( !V_stricmp_fast( pCompiler, "VS2010" ) )
  132. {
  133. return GetMSVCIncludePaths( paths, "VS100COMNTOOLS" );
  134. }
  135. else if ( !V_stricmp_fast( pCompiler, "VS2012" ) )
  136. {
  137. return GetMSVCIncludePaths( paths, "VS110COMNTOOLS" );
  138. }
  139. else if ( !V_stricmp_fast( pCompiler, "VS2013" ) )
  140. {
  141. return GetMSVCIncludePaths( paths, "VS120COMNTOOLS" );
  142. }
  143. else if ( !V_stricmp_fast( pCompiler, "VS2015" ) )
  144. {
  145. return GetMSVCIncludePaths( paths, "VS140COMNTOOLS" );
  146. }
  147. AssertMsg1( false, "ERROR: GetSystemIncludePaths not implemented for this compiler yet! (%s)\n", pCompiler );
  148. return false;
  149. }
  150. else if ( !V_stricmp_fast( pPlatform, "X360" ) )
  151. {
  152. return GetX360IncludePaths( paths );
  153. }
  154. else if ( !V_stricmp_fast( pPlatform, "LINUXSTEAMRT64" ) ||
  155. !V_stricmp_fast( pPlatform, "LINUXSERVER64" ) )
  156. {
  157. // The Steam runtime tool.sh script will rewrite /usr/include
  158. // to whatever is appropriate for runtime compiles, so
  159. // we can just blindly use it here and it will work both
  160. // for runtime and non-runtime compiles.
  161. paths.AddToTail( "/usr/include" );
  162. return true;
  163. }
  164. else if ( !V_stricmp_fast( pPlatform, "OSX32" ) ||
  165. !V_stricmp_fast( pPlatform, "OSX64" ) )
  166. {
  167. return GetOSXIncludePaths( paths );
  168. }
  169. AssertMsg1( false, "ERROR: GetSystemIncludePaths not implemented for this platform yet! (%s)\n", pPlatform );
  170. return false;
  171. }