Browse Source

GHS: try_compile() now uses GHS platform variables

-- Forward GHS platform variables to try_compile()
   CMAKE_TRY_COMPILE_PLATFORM_VARIABLES only worked for source signature try_compile()
-- Update tests to no longer add GHS platform variables to try_compile()
-- Avoid linker error in GhsMulti/GhsMultiCompilerOptions/CMakeLists.txt by building library
Fred Baksik 6 years ago
parent
commit
436cc5e991

+ 3 - 0
Help/command/try_compile.rst

@@ -168,3 +168,6 @@ then the language standard variables are honored:
 
 Their values are used to set the corresponding target properties in
 the generated project (unless overridden by an explicit option).
+
+For the :generator:`Green Hills MULTI` generator the GHS toolset and target
+system customization cache variables are also propagated into the test project.

+ 2 - 1
Help/generator/Green Hills MULTI.rst

@@ -17,13 +17,14 @@ Both absolute and relative paths are valid. Relative paths use ``GHS_TOOLSET_ROO
 as the root. If the toolset is not specified then the latest toolset found in
 ``GHS_TOOLSET_ROOT`` will be used.
 
+Cache variables that are used for toolset and target system customization:
+
 * ``GHS_TARGET_PLATFORM``
 
   | Defaults to ``integrity``.
   | Usual values are ``integrity``, ``threadx``, ``uvelosity``, ``velosity``,
     ``vxworks``, ``standalone``.
 
-
 * ``GHS_PRIMARY_TARGET``
 
   | Sets ``primaryTarget`` entry in project file.

+ 16 - 0
Source/cmCoreTryCompile.cxx

@@ -57,6 +57,12 @@ static std::string const kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES =
   "CMAKE_TRY_COMPILE_PLATFORM_VARIABLES";
 static std::string const kCMAKE_WARN_DEPRECATED = "CMAKE_WARN_DEPRECATED";
 
+/* GHS Multi platform variables */
+static std::set<std::string> ghs_platform_vars{
+  "GHS_TARGET_PLATFORM", "GHS_PRIMARY_TARGET", "GHS_TOOLSET_ROOT",
+  "GHS_OS_ROOT",         "GHS_OS_DIR",         "GHS_BSP_NAME"
+};
+
 static void writeProperty(FILE* fout, std::string const& targetName,
                           std::string const& prop, std::string const& value)
 {
@@ -869,6 +875,16 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
     projectName = "CMAKE_TRY_COMPILE";
   }
 
+  if (this->Makefile->GetState()->UseGhsMultiIDE()) {
+    // Forward the GHS variables to the inner project cache.
+    for (std::string const& var : ghs_platform_vars) {
+      if (const char* val = this->Makefile->GetDefinition(var)) {
+        std::string flag = "-D" + var + "=" + val;
+        cmakeFlags.push_back(std::move(flag));
+      }
+    }
+  }
+
   bool erroroc = cmSystemTools::GetErrorOccuredFlag();
   cmSystemTools::ResetErrorOccuredFlag();
   std::string output;

+ 2 - 0
Source/cmGlobalGhsMultiGenerator.cxx

@@ -11,6 +11,7 @@
 #include "cmGhsMultiTargetGenerator.h"
 #include "cmLocalGhsMultiGenerator.h"
 #include "cmMakefile.h"
+#include "cmState.h"
 #include "cmVersion.h"
 #include "cmake.h"
 
@@ -21,6 +22,7 @@ const char* cmGlobalGhsMultiGenerator::DEFAULT_TOOLSET_ROOT = "C:/ghs";
 cmGlobalGhsMultiGenerator::cmGlobalGhsMultiGenerator(cmake* cm)
   : cmGlobalGenerator(cm)
 {
+  cm->GetState()->SetGhsMultiIDE(true);
 }
 
 cmGlobalGhsMultiGenerator::~cmGlobalGhsMultiGenerator()

+ 10 - 0
Source/cmState.cxx

@@ -593,6 +593,16 @@ bool cmState::UseWindowsVSIDE() const
   return this->WindowsVSIDE;
 }
 
+void cmState::SetGhsMultiIDE(bool ghsMultiIDE)
+{
+  this->GhsMultiIDE = ghsMultiIDE;
+}
+
+bool cmState::UseGhsMultiIDE() const
+{
+  return this->GhsMultiIDE;
+}
+
 void cmState::SetWatcomWMake(bool watcomWMake)
 {
   this->WatcomWMake = watcomWMake;

+ 3 - 0
Source/cmState.h

@@ -154,6 +154,8 @@ public:
   bool UseWindowsShell() const;
   void SetWindowsVSIDE(bool windowsVSIDE);
   bool UseWindowsVSIDE() const;
+  void SetGhsMultiIDE(bool ghsMultiIDE);
+  bool UseGhsMultiIDE() const;
   void SetWatcomWMake(bool watcomWMake);
   bool UseWatcomWMake() const;
   void SetMinGWMake(bool minGWMake);
@@ -206,6 +208,7 @@ private:
   bool IsGeneratorMultiConfig = false;
   bool WindowsShell = false;
   bool WindowsVSIDE = false;
+  bool GhsMultiIDE = false;
   bool WatcomWMake = false;
   bool MinGWMake = false;
   bool NMake = false;

+ 2 - 4
Tests/GhsMulti/GhsMultiCompilerOptions/CMakeLists.txt

@@ -14,14 +14,12 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test.c
 )
 
 message("Building project")
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
 try_compile(RESULT
   ${CMAKE_CURRENT_BINARY_DIR}/build
   ${CMAKE_CURRENT_BINARY_DIR}/src
   test
-  CMAKE_FLAGS -DGHS_BSP_NAME=${GHS_BSP_NAME}
-    -DGHS_OS_ROOT=${GHS_OS_ROOT}
-    -DGHS_TOOLSET_ROOT=${GHS_TOOLSET_ROOT}
-    -DGHS_TARGET_PLATFORM=${GHS_TARGET_PLATFORM}
+  CMAKE_FLAGS
     -DRUN_TEST=${RUN_TEST}
     -DCMAKE_BUILD_TYPE=${RUN_TEST_BUILD_TYPE}
   OUTPUT_VARIABLE OUTPUT)

+ 0 - 5
Tests/GhsMulti/GhsMultiCopyFile/CMakeLists.txt

@@ -9,11 +9,6 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
 try_compile(RESULT
   ${CMAKE_CURRENT_BINARY_DIR}/build
   ${CMAKE_CURRENT_SOURCE_DIR}/test.c
-  CMAKE_FLAGS -DGHS_BSP_NAME=${GHS_BSP_NAME}
-  -DGHS_OS_ROOT=${GHS_OS_ROOT}
-  -DGHS_OS_DIR=${GHS_OS_DIR}
-  -DGHS_TOOLSET_ROOT=${GHS_TOOLSET_ROOT}
-  -DGHS_TARGET_PLATFORM=${GHS_TARGET_PLATFORM}
   OUTPUT_VARIABLE OUTPUT
   COPY_FILE "${CMAKE_CURRENT_BINARY_DIR}/test_library"
 )

+ 1 - 5
Tests/GhsMulti/GhsMultiLinkTest/CMakeLists.txt

@@ -25,11 +25,7 @@ try_compile(RESULT
   ${CMAKE_CURRENT_BINARY_DIR}/link_build
   ${CMAKE_CURRENT_BINARY_DIR}/link_src
   test
-  CMAKE_FLAGS -DGHS_BSP_NAME=${GHS_BSP_NAME}
-    -DGHS_OS_ROOT=${GHS_OS_ROOT}
-    -DGHS_OS_DIR=${GHS_OS_DIR}
-    -DGHS_TOOLSET_ROOT=${GHS_TOOLSET_ROOT}
-    -DGHS_TARGET_PLATFORM=${GHS_TARGET_PLATFORM}
+  CMAKE_FLAGS
     -DRUN_TEST=${RUN_TEST}
     -DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}
   OUTPUT_VARIABLE OUTPUT)