On Mar 20 [13:08], Brad King wrote:
> On 03/20/2015 04:23 AM, Steven Vancoillie wrote:
> > Looking at other compiler configurations, it seems it might be better
> > to have a SunPro.cmake module that combines flags that are independent
> > of the language?
> 
> Yes.  This refactoring has simply not been done for this compiler.
> If you want to work on it, please note that such a module is not
> loaded automatically and must be included by the per-language
> modules.  This pattern is visible in several other compiler modules.

I've included a candidate patch for this refactoring.

I also noticed the follow variables are set for C, CSS, and ASM:

  set(CMAKE_${type}_LINK_STATIC_${lang}_FLAGS "-Bstatic")
  set(CMAKE_${type}_LINK_DYNAMIC_${lang}_FLAGS "-Bdynamic")

I could add these for Fortran as well and move it also to the
macro in SunPro.cmake. However, since this only seems to be there
for SunPro, I wondered if these are used at all? These options are
just passed to ld, so they are not sun-specific.

grtz
Steven
>From b541e110cdc3404ac7b5ac0c24f501c2216058bb Mon Sep 17 00:00:00 2001
From: Steven Vancoillie <[email protected]>
Date: Mon, 23 Mar 2015 09:22:14 +0100
Subject: [PATCH] Combine SunPro compiler flags for multiple languages

Merge equivalent compiler flags into one single SunPro.cmake file,
which are then imported into the per-language modules.

This also removes the non-existent -KPIE option.
---
 Modules/Compiler/SunPro-ASM.cmake     | 17 +++-----------
 Modules/Compiler/SunPro-C.cmake       | 20 ++---------------
 Modules/Compiler/SunPro-CXX.cmake     | 21 ++----------------
 Modules/Compiler/SunPro-Fortran.cmake | 17 +++-----------
 Modules/Compiler/SunPro.cmake         | 42 +++++++++++++++++++++++++++++++++++
 5 files changed, 52 insertions(+), 65 deletions(-)
 create mode 100644 Modules/Compiler/SunPro.cmake

diff --git a/Modules/Compiler/SunPro-ASM.cmake b/Modules/Compiler/SunPro-ASM.cmake
index 2fa8b99..fc17271 100644
--- a/Modules/Compiler/SunPro-ASM.cmake
+++ b/Modules/Compiler/SunPro-ASM.cmake
@@ -1,18 +1,7 @@
-set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s )
-
-set(CMAKE_ASM_VERBOSE_FLAG "-#")
+include(Compiler/SunPro)
+__compiler_sunpro(ASM)
 
-set(CMAKE_SHARED_LIBRARY_ASM_FLAGS "-KPIC")
-set(CMAKE_SHARED_LIBRARY_CREATE_ASM_FLAGS "-G")
-set(CMAKE_SHARED_LIBRARY_RUNTIME_ASM_FLAG "-R")
-set(CMAKE_SHARED_LIBRARY_RUNTIME_ASM_FLAG_SEP ":")
-set(CMAKE_SHARED_LIBRARY_SONAME_ASM_FLAG "-h")
-
-set(CMAKE_ASM_FLAGS_INIT "")
-set(CMAKE_ASM_FLAGS_DEBUG_INIT "-g")
-set(CMAKE_ASM_FLAGS_MINSIZEREL_INIT "-xO2 -xspace -DNDEBUG")
-set(CMAKE_ASM_FLAGS_RELEASE_INIT "-xO3 -DNDEBUG")
-set(CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
+set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s )
 
 # Initialize ASM link type selection flags.  These flags are used when
 # building a shared library, shared module, or executable that links
diff --git a/Modules/Compiler/SunPro-C.cmake b/Modules/Compiler/SunPro-C.cmake
index c5b5203..a065d75 100644
--- a/Modules/Compiler/SunPro-C.cmake
+++ b/Modules/Compiler/SunPro-C.cmake
@@ -1,18 +1,5 @@
-set(CMAKE_C_VERBOSE_FLAG "-#")
-
-set(CMAKE_C_COMPILE_OPTIONS_PIC -KPIC)
-set(CMAKE_C_COMPILE_OPTIONS_PIE -KPIE)
-set(CMAKE_SHARED_LIBRARY_C_FLAGS "-KPIC")
-set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-G")
-set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-R")
-set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP ":")
-set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-h")
-
-set(CMAKE_C_FLAGS_INIT "")
-set(CMAKE_C_FLAGS_DEBUG_INIT "-g")
-set(CMAKE_C_FLAGS_MINSIZEREL_INIT "-xO2 -xspace -DNDEBUG")
-set(CMAKE_C_FLAGS_RELEASE_INIT "-xO3 -DNDEBUG")
-set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
+include(Compiler/SunPro)
+__compiler_sunpro(C)
 
 # Initialize C link type selection flags.  These flags are used when
 # building a shared library, shared module, or executable that links
@@ -22,6 +9,3 @@ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
   set(CMAKE_${type}_LINK_STATIC_C_FLAGS "-Bstatic")
   set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Bdynamic")
 endforeach()
-
-set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
-set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
diff --git a/Modules/Compiler/SunPro-CXX.cmake b/Modules/Compiler/SunPro-CXX.cmake
index c7bc734..fee75f3 100644
--- a/Modules/Compiler/SunPro-CXX.cmake
+++ b/Modules/Compiler/SunPro-CXX.cmake
@@ -1,19 +1,5 @@
-set(CMAKE_CXX_VERBOSE_FLAG "-v")
-
-set(CMAKE_CXX_COMPILE_OPTIONS_PIC -KPIC)
-set(CMAKE_CXX_COMPILE_OPTIONS_PIE -KPIE)
-set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-KPIC")
-set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-G")
-set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-R")
-set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP ":")
-set(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-h")
-
-set(CMAKE_CXX_FLAGS_INIT "")
-set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
-set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-xO2 -xspace -DNDEBUG")
-set(CMAKE_CXX_FLAGS_RELEASE_INIT "-xO3 -DNDEBUG")
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
-
+include(Compiler/SunPro)
+__compiler_sunpro(CXX)
 # Initialize C link type selection flags.  These flags are used when
 # building a shared library, shared module, or executable that links
 # to other libraries to select whether to use the static or shared
@@ -23,9 +9,6 @@ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
   set(CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS "-Bdynamic")
 endforeach()
 
-set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
-set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
-
 # Create archives with "CC -xar" in case user adds "-instances=extern"
 # so that template instantiations are available to archive members.
 set(CMAKE_CXX_CREATE_STATIC_LIBRARY
diff --git a/Modules/Compiler/SunPro-Fortran.cmake b/Modules/Compiler/SunPro-Fortran.cmake
index e4db1e8..8b6054e 100644
--- a/Modules/Compiler/SunPro-Fortran.cmake
+++ b/Modules/Compiler/SunPro-Fortran.cmake
@@ -1,21 +1,10 @@
-set(CMAKE_Fortran_VERBOSE_FLAG "-v")
+include(Compiler/SunPro)
+__compiler_sunpro(Fortran)
+
 set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
 set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
 
-set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS "-KPIC")
-set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "-G")
-set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG "-R")
-set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ":")
-set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-h")
 set(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG "-R")
 
-set(CMAKE_Fortran_FLAGS_INIT "")
-set(CMAKE_Fortran_FLAGS_DEBUG_INIT "-g")
-set(CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "-xO2 -xspace -DNDEBUG")
-set(CMAKE_Fortran_FLAGS_RELEASE_INIT "-xO3 -DNDEBUG")
-set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
 set(CMAKE_Fortran_MODDIR_FLAG "-moddir=")
 set(CMAKE_Fortran_MODPATH_FLAG "-M")
-
-set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -F <SOURCE> -o <PREPROCESSED_SOURCE>")
-set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
diff --git a/Modules/Compiler/SunPro.cmake b/Modules/Compiler/SunPro.cmake
new file mode 100644
index 0000000..9b2298e
--- /dev/null
+++ b/Modules/Compiler/SunPro.cmake
@@ -0,0 +1,42 @@
+#=============================================================================
+# Copyright 2002-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+# This module is shared by multiple languages; use include blocker.
+if(__COMPILER_SUNPRO)
+  return()
+endif()
+set(__COMPILER_SUNPRO 1)
+
+macro(__compiler_sunpro lang)
+  # Feature flags.
+  set(CMAKE_${lang}_VERBOSE_FLAG "-#")
+
+  set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-KPIC")
+
+  set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-KPIC")
+  set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-G")
+  set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG "-R")
+  set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP ":")
+  set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-h")
+
+  # Initial configuration flags.
+  set(CMAKE_${lang}_FLAGS_INIT "")
+  set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-g")
+  set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "-xO2 -xspace -DNDEBUG")
+  set(CMAKE_${lang}_FLAGS_RELEASE_INIT "-xO3 -DNDEBUG")
+  set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "-g -xO2 -DNDEBUG")
+
+  # Preprocessing and assembly rules.
+  set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+  set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+endmacro()
-- 
2.3.3

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to