Merge pull request #5555 from aws-lumberyard-dev/ghi-4320/ProjectManagerLinuxDefaultClang

Project Manager Fixes for Linux
This commit is contained in:
Steve Pham
2021-11-11 11:21:06 -08:00
committed by GitHub
15 changed files with 183 additions and 34 deletions
+1
View File
@@ -14,6 +14,7 @@ include(cmake/Version.cmake)
include(cmake/OutputDirectory.cmake)
if(NOT PROJECT_NAME)
include(cmake/CompilerSettings.cmake)
project(O3DE
LANGUAGES C CXX
VERSION ${LY_VERSION_STRING}
@@ -23,25 +23,11 @@ namespace O3DE::ProjectManager
QString cmakeGenerator = (whichNinjaResult.IsSuccess()) ? "Ninja Multi-Config" : "Unix Makefiles";
bool compileProfileOnBuild = (whichNinjaResult.IsSuccess());
// On Linux the default compiler is gcc. For O3DE, it is clang, so we need to specify the version of clang that is detected
// in order to get the compiler option.
auto compilerOptionResult = ProjectUtils::FindSupportedCompilerForPlatform();
if (!compilerOptionResult.IsSuccess())
{
return AZ::Failure(compilerOptionResult.GetError());
}
auto clangCompilers = compilerOptionResult.GetValue().split('|');
AZ_Assert(clangCompilers.length()==2, "Invalid clang compiler pair specification");
QString clangCompilerOption = clangCompilers[0];
QString clangPPCompilerOption = clangCompilers[1];
QString targetBuildPath = QDir(m_projectInfo.m_path).filePath(ProjectBuildPathPostfix);
QStringList generateProjectArgs = QStringList{ProjectCMakeCommand,
"-B", ProjectBuildPathPostfix,
"-S", ".",
QString("-G%1").arg(cmakeGenerator),
QString("-DCMAKE_C_COMPILER=").append(clangCompilerOption),
QString("-DCMAKE_CXX_COMPILER=").append(clangPPCompilerOption),
QString("-DLY_3RDPARTY_PATH=").append(thirdPartyPath)};
if (!compileProfileOnBuild)
{
@@ -17,13 +17,11 @@ namespace O3DE::ProjectManager
namespace ProjectUtils
{
// The list of clang C/C++ compiler command lines to validate on the host Linux system
const QStringList SupportedClangCommands = {"clang-12|clang++-12"};
const QStringList SupportedClangVersions = {"13", "12", "11", "10", "9", "8", "7", "6.0"};
AZ::Outcome<QProcessEnvironment, QString> GetCommandLineProcessEnvironment()
{
QProcessEnvironment currentEnvironment(QProcessEnvironment::systemEnvironment());
currentEnvironment.insert("CC", "clang-12");
currentEnvironment.insert("CXX", "clang++-12");
return AZ::Success(currentEnvironment);
}
@@ -39,16 +37,13 @@ namespace O3DE::ProjectManager
}
// Look for the first compatible version of clang. The list below will contain the known clang compilers that have been tested for O3DE.
for (const QString& supportClangCommand : SupportedClangCommands)
for (const QString& supportClangVersion : SupportedClangVersions)
{
auto clangCompilers = supportClangCommand.split('|');
AZ_Assert(clangCompilers.length()==2, "Invalid clang compiler pair specification");
auto whichClangResult = ProjectUtils::ExecuteCommandResult("which", QStringList{clangCompilers[0]}, QProcessEnvironment::systemEnvironment());
auto whichClangPPResult = ProjectUtils::ExecuteCommandResult("which", QStringList{clangCompilers[1]}, QProcessEnvironment::systemEnvironment());
auto whichClangResult = ProjectUtils::ExecuteCommandResult("which", QStringList{QString("clang-%1").arg(supportClangVersion)}, QProcessEnvironment::systemEnvironment());
auto whichClangPPResult = ProjectUtils::ExecuteCommandResult("which", QStringList{QString("clang++-%1").arg(supportClangVersion)}, QProcessEnvironment::systemEnvironment());
if (whichClangResult.IsSuccess() && whichClangPPResult.IsSuccess())
{
return AZ::Success(supportClangCommand);
return AZ::Success(QString("clang-%1").arg(supportClangVersion));
}
}
return AZ::Failure(QObject::tr("Clang not found. <br><br>"
@@ -10,11 +10,12 @@
if(NOT PROJECT_NAME)
cmake_minimum_required(VERSION 3.20)
include(cmake/CompilerSettings.cmake)
project(${Name}
LANGUAGES C CXX
VERSION 1.0.0.0
)
include(EngineFinder.cmake OPTIONAL)
include(cmake/EngineFinder.cmake OPTIONAL)
find_package(o3de REQUIRED)
o3de_initialize()
else()
@@ -0,0 +1,13 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# File to tweak compiler settings before compiler detection happens (before project() is called)
# We dont have PAL enabled at this point, so we can only use pure-CMake variables
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
include(cmake/Platform/${CMAKE_HOST_SYSTEM_NAME}/CompilerSettings.cmake)
endif()
@@ -13,8 +13,8 @@
include_guard()
# Read the engine name from the project_json file
file(READ ${CMAKE_CURRENT_LIST_DIR}/project.json project_json)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/project.json)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/project.json project_json)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/project.json)
string(JSON LY_ENGINE_NAME_TO_USE ERROR_VARIABLE json_error GET ${project_json} engine)
if(json_error)
@@ -0,0 +1,34 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
if(NOT CMAKE_C_COMPILER AND NOT CMAKE_CXX_COMPILER AND NOT "$ENV{CC}" AND NOT "$ENV{CXX}")
set(path_search
/bin
/usr/bin
/usr/local/bin
/sbin
/usr/sbin
/usr/local/sbin
)
list(TRANSFORM path_search APPEND "/clang-[0-9]*")
file(GLOB clang_versions ${path_search})
if(clang_versions)
# Find and pick the highest installed version
list(SORT clang_versions COMPARE NATURAL)
list(GET clang_versions 0 clang_higher_version_path)
string(REGEX MATCH "clang-([0-9.]*)" clang_higher_version ${clang_higher_version_path})
if(CMAKE_MATCH_1)
set(CMAKE_C_COMPILER clang-${CMAKE_MATCH_1})
set(CMAKE_CXX_COMPILER clang++-${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Clang not found, please install clang")
endif()
else()
message(FATAL_ERROR "Clang not found, please install clang")
endif()
endif()
+14 -2
View File
@@ -181,8 +181,20 @@
"isOptional": false
},
{
"file": "EngineFinder.cmake",
"origin": "EngineFinder.cmake",
"file": "cmake/EngineFinder.cmake",
"origin": "cmake/EngineFinder.cmake",
"isTemplated": false,
"isOptional": false
},
{
"file": "cmake/CompilerSettings.cmake",
"origin": "cmake/CompilerSettings.cmake",
"isTemplated": false,
"isOptional": false
},
{
"file": "cmake/Platform/Linux/CompilerSettings.cmake",
"origin": "cmake/Platform/Linux/CompilerSettings.cmake",
"isTemplated": false,
"isOptional": false
},
@@ -10,11 +10,12 @@
if(NOT PROJECT_NAME)
cmake_minimum_required(VERSION 3.20)
include(cmake/CompilerSettings.cmake)
project(${Name}
LANGUAGES C CXX
VERSION 1.0.0.0
)
include(EngineFinder.cmake OPTIONAL)
include(cmake/EngineFinder.cmake OPTIONAL)
find_package(o3de REQUIRED)
o3de_initialize()
else()
@@ -0,0 +1,13 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# File to tweak compiler settings before compiler detection happens (before project() is called)
# We dont have PAL enabled at this point, so we can only use pure-CMake variables
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
include(cmake/Platform/${CMAKE_HOST_SYSTEM_NAME}/CompilerSettings.cmake)
endif()
@@ -13,8 +13,8 @@
include_guard()
# Read the engine name from the project_json file
file(READ ${CMAKE_CURRENT_LIST_DIR}/project.json project_json)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/project.json)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/project.json project_json)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/project.json)
string(JSON LY_ENGINE_NAME_TO_USE ERROR_VARIABLE json_error GET ${project_json} engine)
if(json_error)
@@ -0,0 +1,34 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
if(NOT CMAKE_C_COMPILER AND NOT CMAKE_CXX_COMPILER AND NOT "$ENV{CC}" AND NOT "$ENV{CXX}")
set(path_search
/bin
/usr/bin
/usr/local/bin
/sbin
/usr/sbin
/usr/local/sbin
)
list(TRANSFORM path_search APPEND "/clang-[0-9]*")
file(GLOB clang_versions ${path_search})
if(clang_versions)
# Find and pick the highest installed version
list(SORT clang_versions COMPARE NATURAL)
list(GET clang_versions 0 clang_higher_version_path)
string(REGEX MATCH "clang-([0-9.]*)" clang_higher_version ${clang_higher_version_path})
if(CMAKE_MATCH_1)
set(CMAKE_C_COMPILER clang-${CMAKE_MATCH_1})
set(CMAKE_CXX_COMPILER clang++-${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Clang not found, please install clang")
endif()
else()
message(FATAL_ERROR "Clang not found, please install clang")
endif()
endif()
+14 -2
View File
@@ -173,8 +173,20 @@
"isOptional": false
},
{
"file": "EngineFinder.cmake",
"origin": "EngineFinder.cmake",
"file": "cmake/EngineFinder.cmake",
"origin": "cmake/EngineFinder.cmake",
"isTemplated": false,
"isOptional": false
},
{
"file": "cmake/CompilerSettings.cmake",
"origin": "cmake/CompilerSettings.cmake",
"isTemplated": false,
"isOptional": false
},
{
"file": "cmake/Platform/Linux/CompilerSettings.cmake",
"origin": "cmake/Platform/Linux/CompilerSettings.cmake",
"isTemplated": false,
"isOptional": false
},
+13
View File
@@ -0,0 +1,13 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# File to tweak compiler settings before compiler detection happens (before project() is called)
# We dont have PAL enabled at this point, so we can only use pure-CMake variables
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
include(cmake/Platform/${CMAKE_HOST_SYSTEM_NAME}/CompilerSettings.cmake)
endif()
@@ -0,0 +1,34 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
if(NOT CMAKE_C_COMPILER AND NOT CMAKE_CXX_COMPILER AND NOT "$ENV{CC}" AND NOT "$ENV{CXX}")
set(path_search
/bin
/usr/bin
/usr/local/bin
/sbin
/usr/sbin
/usr/local/sbin
)
list(TRANSFORM path_search APPEND "/clang-[0-9]*")
file(GLOB clang_versions ${path_search})
if(clang_versions)
# Find and pick the highest installed version
list(SORT clang_versions COMPARE NATURAL)
list(GET clang_versions 0 clang_higher_version_path)
string(REGEX MATCH "clang-([0-9.]*)" clang_higher_version ${clang_higher_version_path})
if(CMAKE_MATCH_1)
set(CMAKE_C_COMPILER clang-${CMAKE_MATCH_1})
set(CMAKE_CXX_COMPILER clang++-${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Clang not found, please install clang")
endif()
else()
message(FATAL_ERROR "Clang not found, please install clang")
endif()
endif()