Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have target/host triples "arch-vendor-os" as in autotools #326

Merged
merged 3 commits into from
May 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ find_program( SED NAMES sed gsed )
################## CPack, checks, ... in external modules ##################
################################################################################

include( GetTriple )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the name GetTriple for this file. Can you make it more specific, please?MaybeDetermineArchitecture` or something like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In autotools they are called TypeTriplets. Other cmake implementations call this GetTriplet.cmake, or Triplet.cmake[1] [2]. As this is specifically for the autotools triplets, I think the name triplet should be contained.

get_host_triple( NEST_HOST_TRIPLE NEST_HOST_ARCH NEST_HOST_VENDOR NEST_HOST_OS )
get_target_triple( NEST_TARGET_TRIPLE NEST_TARGET_ARCH NEST_TARGET_VENDOR NEST_TARGET_OS )

include( CPackVariables )
include( CheckIncludesSymbols )
include( ProcessOptions )
Expand Down
92 changes: 92 additions & 0 deletions cmake/GetTriple.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# cmake/GetTriple.cmake
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

# Based on libcxx/cmake/Modules/GetTriple.cmake

# Define functions to get the host and target triple.

function(get_host_triple out out_arch out_vendor out_os)
# Get the architecture.
set( arch "${CMAKE_HOST_SYSTEM_PROCESSOR}" )
# i686 is an enhanced version of x86
if ( arch STREQUAL "x86" )
set( arch "i686" )
endif ()

# Get the vendor.
if ( "${CMAKE_HOST_SYSTEM_NAME}" MATCHES "^Darwin.*" )
set( vendor "apple" )
else ()
set( vendor "pc" )
endif ()

# Get os.
if ( "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows" )
set( os "win32" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't just "win" be more correct on current versions of that OS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not so sure how relevant this actually is, given that NEST is not officially supported on Windows ("we do not tests this regularly [building on Windows] and do not support NEST under Cygwin at present"), but the lines are only relevant, if the host system name is Windows, then this will default to win32. In other cases, the CMAKE_HOST_SYSTEM_NAME will just be cast to lower case. Maybe on a 64bit Windows this will default to win64 - I have not tested this - or on MinGW this will default to mingw32 (as the autoconf counterpart).

else ()
string( TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" os )
endif ()

set( triple "${arch}-${vendor}-${os}" )

# return values
set( ${out} ${triple} PARENT_SCOPE )
set( ${out_arch} ${arch} PARENT_SCOPE )
set( ${out_vendor} ${vendor} PARENT_SCOPE )
set( ${out_os} ${os} PARENT_SCOPE )

message( STATUS "Host triple: ${triple}" )
endfunction ()


function(get_target_triple out out_arch out_vendor out_os)
# Get the architecture.
set( arch "${CMAKE_SYSTEM_PROCESSOR}" )
# i686 is an enhanced version of x86
if ( arch STREQUAL "x86" )
set( arch "i686" )
endif ()

# Get the vendor.
if ( "${CMAKE_SYSTEM_NAME}" MATCHES "^Darwin.*")
set( vendor "apple" )
elseif ( TRIPLET_VENDOR )
# In our own tool chain files we define vendors.
set( vendor "${TRIPLET_VENDOR}" )
else ()
set( vendor "pc" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this set vendor to pc also for BlueGene and K?

endif ()

# Get os.
if ( "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" )
set( os "win32" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

else ()
string( TOLOWER "${CMAKE_SYSTEM_NAME}" os )
endif ()

set(triple "${arch}-${vendor}-${os}")

# return values
set( ${out} ${triple} PARENT_SCOPE )
set( ${out_arch} ${arch} PARENT_SCOPE )
set( ${out_vendor} ${vendor} PARENT_SCOPE )
set( ${out_os} ${os} PARENT_SCOPE )

message(STATUS "Target triple: ${triple}")
endfunction()
4 changes: 3 additions & 1 deletion cmake/Platform/BlueGeneQ_Base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@
#

# Based on the BlueGeneQ-base platform file
set( CMAKE_SYSTEM_NAME BlueGeneQ_Base CACHE STRING "Cross-compiling for BlueGene/Q" FORCE )
set( CMAKE_SYSTEM_NAME Linux CACHE STRING "Cross-compiling for BlueGene/Q" FORCE )
set( CMAKE_SYSTEM_PROCESSOR ppc64 )
set( TRIPLET_VENDOR ibm )

# Set enable-bluegene for main CMakeList.txt
set( enable-bluegene "Q" CACHE STRING "Configure for BlueGene." FORCE )
Expand Down
1 change: 1 addition & 0 deletions cmake/Platform/Fujitsu-Sparc64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# the name of the target operating system
set( CMAKE_SYSTEM_NAME Linux CACHE STRING "Cross-compiling for Fujitsu Sparc64, with MPI" )
set( CMAKE_SYSTEM_PROCESSOR "s64fx" )
set( TRIPLET_VENDOR fujitsu )

#
# Set k-computer for main CMakeList.txt
Expand Down
8 changes: 4 additions & 4 deletions libnestutil/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
#define NEST_VERSION_PATCHLEVEL "@NEST_VERSION_PATCHLEVEL@"

// TODO NEST_HOST and NEST_HOSTVENDOR not available with cmake
#define NEST_HOST "@CMAKE_HOST_SYSTEM_PROCESSOR@-@host_vendor@-@CMAKE_HOST_SYSTEM@"
#define NEST_HOSTOS "@CMAKE_HOST_SYSTEM@"
#define NEST_HOSTCPU "@CMAKE_HOST_SYSTEM_PROCESSOR@"
#define NEST_HOSTVENDOR "@host_vendor@"
#define NEST_HOST "@NEST_TARGET_TRIPLE@"
#define NEST_HOSTOS "@NEST_TARGET_OS@"
#define NEST_HOSTCPU "@NEST_TARGET_ARCH@"
#define NEST_HOSTVENDOR "@NEST_TARGET_VENDOR@"

#define NEST_SOURCEDIR "@PKGSRCDIR@"
#define NEST_BUILDDIR "@PKGBUILDDIR@"
Expand Down