changeset 753:eadcec7390ee

cmake: determine the data model at build time Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Thu, 25 Jul 2019 11:24:45 -0400
parents b9db76d1dd5b
children 389216c34b53
files cmake/config-datamodel.cmake cmake/config.cmake include/jeffpc/config.h.in
diffstat 3 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/config-datamodel.cmake	Thu Jul 25 11:24:45 2019 -0400
@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+
+# Determine the data model
+
+check_type_size("int" INT_SIZE)
+check_type_size("long" LONG_SIZE)
+check_type_size("void *" VOIDP_SIZE)
+set(size_code "${INT_SIZE}:${LONG_SIZE}:${VOIDP_SIZE}")
+if("${size_code}" STREQUAL "4:4:4")
+	set(JEFFPC_DATAMODEL "ILP32")
+	set(JEFFPC_ILP32 1)
+elseif("${size_code}" STREQUAL "4:8:8")
+	set(JEFFPC_DATAMODEL "LP64")
+	set(JEFFPC_LP64 1)
+else()
+	message(FATAL_ERROR "Failed to determine data model "
+		"(sizeof(int)=${INT_SIZE}, "
+		"sizeof(long)=${LONG_SIZE}, "
+		"sizeof(void *)=${VOIDP_SIZE})")
+endif()
+
+message(STATUS "Detected ${JEFFPC_DATAMODEL} data model")
--- a/cmake/config.cmake	Wed Jul 03 21:15:22 2019 -0400
+++ b/cmake/config.cmake	Thu Jul 25 11:24:45 2019 -0400
@@ -29,6 +29,8 @@
 
 test_big_endian(JEFFPC_CPU_BIG_ENDIAN)
 
+include("${CMAKE_DIR}/config-datamodel.cmake")
+
 # Find which library a particular function exists in
 macro(find_symbol fxn libs output_lib_name)
 	string(TOUPPER ${fxn} name)
--- a/include/jeffpc/config.h.in	Wed Jul 03 21:15:22 2019 -0400
+++ b/include/jeffpc/config.h.in	Thu Jul 25 11:24:45 2019 -0400
@@ -24,6 +24,9 @@
 #define __JEFFPC_CONFIG_H
 
 #cmakedefine JEFFPC_CPU_BIG_ENDIAN
+#cmakedefine JEFFPC_DATAMODEL		"${JEFFPC_DATAMODEL}"
+#cmakedefine JEFFPC_ILP32
+#cmakedefine JEFFPC_LP64
 
 #cmakedefine JEFFPC_HAVE___ASSERT_FREEBSD_STYLE
 #cmakedefine JEFFPC_HAVE___ASSERT_LINUX_STYLE