From 3e020ac24120feb9c0854fa8fabea9cc8c11a18a Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 10 Feb 2023 10:06:19 +0000 Subject: [PATCH 01/14] Experimental demonstration CMake configuration. --- code/.gitignore | 4 ++ code/CMakeLists.txt | 127 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 code/CMakeLists.txt diff --git a/code/.gitignore b/code/.gitignore index ff483930b8..fa3565667d 100644 --- a/code/.gitignore +++ b/code/.gitignore @@ -61,3 +61,7 @@ tags *~ # GNU make dependencies */*/*.d +# CMake output +CMakeFiles +CMakeCache.txt +cmake_install.cmake diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt new file mode 100644 index 0000000000..d85ff2f5d0 --- /dev/null +++ b/code/CMakeLists.txt @@ -0,0 +1,127 @@ +# code/CMakeLists.txt -- CMake configuration for the MPS +# +# This is just an experimental demonstration configuration to see how +# we might use CMake to replace GNU Make, NMAKE, and Xcodebuild in the +# MPS. +# +# A complete review of all the GNU Make, NMAKE, etc. files and their +# usage would be required. +# +# Invoke like:: +# +# cmake -DCMAKE_BUILD_TYPE=Debug . && make VERBOSE=1 clean all +# +# See GitHub issue #146 +# for discussion. + +# Tutorial says to put this in but does not give any advice about the +# argument, so I'm guessing based on feature documentation I've used. +cmake_minimum_required(VERSION 3.15) + +project(mps LANGUAGES C) + + +# Common definitions +# +# Lifted from comm.gmk section "Common definitions" to define a few of +# the "parts". + +set(TESTLIB testlib.c) +set(FMTDYTST fmtdy.c fmtno.c fmtdytst.c) +set(TESTTHR testthrix.c) # FIXME: Platform specific, varies by OS + + +# Targets +# +# Just using gcbench as an example target for now. + +add_executable(gcbench gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) +target_link_libraries(gcbench PRIVATE m) +# FIXME: Should be C89 but CMake doesn't know it. +# FIXME: How to set this for all targets not just gcbench? +target_compile_features(gcbench PRIVATE c_std_90) + + +# Varieties +# +# MPS varieties (HOT, COOL, etc.) probably map to CMake "Build +# Configurations" +# . +# I'm just mapping Debug and Release for now. + +add_compile_definitions( + $<$:CONFIG_VAR_COOL> + $<$:CONFIG_VAR_HOT> +) + + +# Compilers +# +# FIXME: How to set these for *all* targets, not just gcbench? + +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + + message(VERBOSE "compiler.gc detected") + + # Lifted from CFLAGSCOMPILER in gc.gmk + + target_compile_options(gcbench PRIVATE + -Waggregate-return + -Wall + -Wcast-qual + -Werror + -Wextra + -Winline + -Wmissing-prototypes + -Wnested-externs + -Wpointer-arith + -Wshadow + -Wstrict-aliasing=2 + -Wstrict-prototypes + -Wswitch-default + -Wwrite-strings + -pedantic + ) + +elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") + + message(VERBOSE "compiler.cl detected") + + # Lifted from CFLAGSCOMPILER in ll.gmk + + target_compile_options(gcbench PRIVATE + -Waggregate-return + -Wall + -Wcast-qual + -Wconversion + -Wduplicate-enum + -Werror + -Wextra + -Winline + -Wmissing-prototypes + -Wmissing-variable-declarations + -Wnested-externs + -Wpointer-arith + -Wshadow + -Wstrict-aliasing=2 + -Wstrict-prototypes + -Wunreachable-code + -Wwrite-strings + -pedantic + ) + +elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") + + message(VERBOSE "compiler.mv detected") + + # Lifted from CFLAGSCOMMONPRE in mv.nmk. + + target_compile_options(gcbench PRIVATE /W4 /WX) + +else () + + message(WARNING "Unknown compiler toolchain. Compiling without warning flags.") + +endif () + + From 7551b039476a913694bca215db53ac2a73f083c3 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Thu, 16 Feb 2023 01:46:19 +0000 Subject: [PATCH 02/14] Generalising for multiple targets. --- code/CMakeLists.txt | 72 ++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index d85ff2f5d0..876ebf341b 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -9,7 +9,7 @@ # # Invoke like:: # -# cmake -DCMAKE_BUILD_TYPE=Debug . && make VERBOSE=1 clean all +# cmake -B hot -DCMAKE_BUILD_TYPE=RELEASE --log-level=VERBOSE . && cmake --build hot --verbose # # See GitHub issue #146 # for discussion. @@ -31,17 +31,6 @@ set(FMTDYTST fmtdy.c fmtno.c fmtdytst.c) set(TESTTHR testthrix.c) # FIXME: Platform specific, varies by OS -# Targets -# -# Just using gcbench as an example target for now. - -add_executable(gcbench gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) -target_link_libraries(gcbench PRIVATE m) -# FIXME: Should be C89 but CMake doesn't know it. -# FIXME: How to set this for all targets not just gcbench? -target_compile_features(gcbench PRIVATE c_std_90) - - # Varieties # # MPS varieties (HOT, COOL, etc.) probably map to CMake "Build @@ -49,6 +38,11 @@ target_compile_features(gcbench PRIVATE c_std_90) # . # I'm just mapping Debug and Release for now. +# Unset CMake's default flags +set(CMAKE_C_FLAGS_DEBUG "") +set(CMAKE_C_FLAGS_RELEASE "") +set(CMAKE_C_FLAGS "") + add_compile_definitions( $<$:CONFIG_VAR_COOL> $<$:CONFIG_VAR_HOT> @@ -56,16 +50,15 @@ add_compile_definitions( # Compilers -# -# FIXME: How to set these for *all* targets, not just gcbench? if (CMAKE_C_COMPILER_ID STREQUAL "GNU") message(VERBOSE "compiler.gc detected") - # Lifted from CFLAGSCOMPILER in gc.gmk - - target_compile_options(gcbench PRIVATE + # Lifted from variables in gc.gmk + set(CFLAGSDEBUG -O -g3) + set(CFLAGSOPT -O2 -g3) + set(CFLAGSCOMPILER -Waggregate-return -Wall -Wcast-qual @@ -80,16 +73,20 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU") -Wstrict-prototypes -Wswitch-default -Wwrite-strings + ) + set(CFLAGSCOMPILERSTRICT + -std=c89 -pedantic ) - + elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") message(VERBOSE "compiler.cl detected") - # Lifted from CFLAGSCOMPILER in ll.gmk - - target_compile_options(gcbench PRIVATE + # Lifted from variables in ll.gmk + set(CFLAGSDEBUG, -O0 -g3) + set(CFLAGSOPT, O2 -g3) + set(CFLAGSCOMPILER, -Waggregate-return -Wall -Wcast-qual @@ -107,6 +104,9 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") -Wstrict-prototypes -Wunreachable-code -Wwrite-strings + ) + set(CFLAGSCOMPILERSTRICT, + -std=c89 -pedantic ) @@ -114,9 +114,19 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") message(VERBOSE "compiler.mv detected") - # Lifted from CFLAGSCOMMONPRE in mv.nmk. + # Lifted from variables in mv.nmk. + set(CFLAGSDEBUG, /MTd /Od) + set(CFLAGSOPT, /O2 /MT) + set(CFLAGSCOMPILER, + # from CFLAGSCOMMONPRE in commpre.nmk + /nologo + # FIXME: PFMDEFS? + # FIXME: CFLAGSTARGETPRE? + /W4 /WX + ) + set(CFLAGSCOMPILERSTRICT, ) - target_compile_options(gcbench PRIVATE /W4 /WX) + # FIXME: LINKFLAGS* from mv.nmk else () @@ -124,4 +134,20 @@ else () endif () +add_compile_options( + "$<$:${CFLAGSDEBUG}>" + "$<$:${CFLAGSOPT}>" + ${CFLAGSCOMPILER} + # FIXME: CFLAGSCOMPILERSTRICT or LAX +) + +# Targets +# +# Just using gcbench as an example target for now. + +add_executable(gcbench gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) +target_link_libraries(gcbench PRIVATE m) +# FIXME: Should be C89 but CMake doesn't know it. +# FIXME: How to set this for all targets not just gcbench? +target_compile_features(gcbench PRIVATE c_std_90) From 924b3aaecca51451b6ab7d8d81497868f52b7013 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Thu, 16 Feb 2023 02:03:27 +0000 Subject: [PATCH 03/14] Adding MPS library target. --- code/CMakeLists.txt | 90 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 876ebf341b..a53dedb428 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -13,6 +13,8 @@ # # See GitHub issue #146 # for discussion. +# +# TODO: Incorporate %% instructions # Tutorial says to put this in but does not give any advice about the # argument, so I'm guessing based on feature documentation I've used. @@ -23,12 +25,81 @@ project(mps LANGUAGES C) # Common definitions # -# Lifted from comm.gmk section "Common definitions" to define a few of -# the "parts". - +# Lifted from comm.gmk section "Common definitions". +# +# %%PART: When adding a new part, add it here, unless it's platform-specific +# These values are defined here because they have no variation between +# platforms. + +set(AMC poolamc.c) +set(AMS poolams.c) +set(AWL poolawl.c) +set(LO poollo.c) +set(SNC poolsnc.c) +set(POOLN pooln.c) +set(MV2 poolmv2.c) +set(MVFF poolmvff.c) set(TESTLIB testlib.c) +set(TESTTHR testthrix.c) # FIXME: Platform specific, varies by OS +set(FMTDY fmtdy.c fmtno.c) set(FMTDYTST fmtdy.c fmtno.c fmtdytst.c) -set(TESTTHR testthrix.c) # FIXME: Platform specific, varies by OS +set(FMTHETST fmthe.c fmtdy.c fmtno.c fmtdytst.c) +set(FMTSCM fmtscheme.c) +set(PLINTH mpsliban.c mpsioan.c) +set(MPMCOMMON + abq.c + arena.c + arenacl.c + arenavm.c + arg.c + boot.c + bt.c + buffer.c + cbs.c + dbgpool.c + dbgpooli.c + event.c + failover.c + format.c + freelist.c + global.c + land.c + ld.c + locus.c + message.c + meter.c + mpm.c + mpsi.c + nailboard.c + policy.c + pool.c + poolabs.c + poolmfs.c + poolmrg.c + protocol.c + range.c + rangetree.c + ref.c + ring.c + root.c + sa.c + sac.c + scan.c + seg.c + shield.c + splay.c + ss.c + table.c + trace.c + traceanc.c + tract.c + tree.c + version.c + vm.c + walk.c +) +set(POOLS ${AMC} ${AMS} ${AWL} ${LO} ${MV2} ${MVFF} ${SNC}) +set(MPM ${MPMCOMMON} ${MPMPF} ${POOLS} ${PLINTH}) # Varieties @@ -150,4 +221,13 @@ add_executable(gcbench gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) target_link_libraries(gcbench PRIVATE m) # FIXME: Should be C89 but CMake doesn't know it. # FIXME: How to set this for all targets not just gcbench? -target_compile_features(gcbench PRIVATE c_std_90) +# target_compile_features(gcbench PRIVATE c_std_90) + +#add_library(mps OBJECT mps.c) +#target_compile_options(mps PRIVATE ${CFLAGSCOMPILERSTRICT}) + +add_library(mps STATIC + $<$:mps.c> + $<$:${MPM}> +) +target_compile_options(mps PRIVATE ${CFLAGSCOMPILERSTRICT}) From 2ab9015214ce2e6815a3fff3e73b79cfe39719e2 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Thu, 16 Feb 2023 03:01:40 +0000 Subject: [PATCH 04/14] Adding library targets, target OS and architecture detection. --- code/CMakeLists.txt | 220 ++++++++++++++++++++++++++---------------- code/TargetArch.cmake | 142 +++++++++++++++++++++++++++ 2 files changed, 277 insertions(+), 85 deletions(-) create mode 100644 code/TargetArch.cmake diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index a53dedb428..07dfdc5b75 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -23,6 +23,134 @@ cmake_minimum_required(VERSION 3.15) project(mps LANGUAGES C) +# Architectures +# +# "it appears that CMake has no functionality to detect the target +# architecture whatsoever." -- https://stackoverflow.com/a/12024211 +# +# TODO: How does this work for multi-arch builds such as Xcode? + +include(TargetArch.cmake) +target_architecture(TARGET_ARCHITECTURE) +message(VERBOSE "Target architecture ${TARGET_ARCHITECTURE}") + + +# Operating Systems + +if (APPLE) # Must come before UNIX, which is also true for macOS + + # FIXME: Needs filling in + +elseif (UNIX) + + # FIXME: Lifted from lii6gc.gmk and not general for all Posix + # platforms + set(MPMPF + lockix.c + prmci6.c + prmcix.c + prmclii6.c + protix.c + protsgix.c + pthrdext.c + span.c + thix.c + vmix.c + ) + +elseif (WIN32) + + # FIXME: Import from w3*.nmk + +endif () + + +# Compilers + +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + + message(VERBOSE "compiler.gc detected") + + # Lifted from variables in gc.gmk + set(CFLAGSDEBUG -O -g3) + set(CFLAGSOPT -O2 -g3) + set(CFLAGSCOMPILER + -Waggregate-return + -Wall + -Wcast-qual + -Werror + -Wextra + -Winline + -Wmissing-prototypes + -Wnested-externs + -Wpointer-arith + -Wshadow + -Wstrict-aliasing=2 + -Wstrict-prototypes + -Wswitch-default + -Wwrite-strings + ) + set(CFLAGSCOMPILERSTRICT + -std=c89 + -pedantic + ) + +elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") + + message(VERBOSE "compiler.cl detected") + + # Lifted from variables in ll.gmk + set(CFLAGSDEBUG, -O0 -g3) + set(CFLAGSOPT, O2 -g3) + set(CFLAGSCOMPILER, + -Waggregate-return + -Wall + -Wcast-qual + -Wconversion + -Wduplicate-enum + -Werror + -Wextra + -Winline + -Wmissing-prototypes + -Wmissing-variable-declarations + -Wnested-externs + -Wpointer-arith + -Wshadow + -Wstrict-aliasing=2 + -Wstrict-prototypes + -Wunreachable-code + -Wwrite-strings + ) + set(CFLAGSCOMPILERSTRICT, + -std=c89 + -pedantic + ) + +elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") + + message(VERBOSE "compiler.mv detected") + + # Lifted from variables in mv.nmk. + set(CFLAGSDEBUG, /MTd /Od) + set(CFLAGSOPT, /O2 /MT) + set(CFLAGSCOMPILER, + # from CFLAGSCOMMONPRE in commpre.nmk + /nologo + # FIXME: PFMDEFS? + # FIXME: CFLAGSTARGETPRE? + /W4 /WX + ) + set(CFLAGSCOMPILERSTRICT, ) + + # FIXME: LINKFLAGS* from mv.nmk + +else () + + message(WARNING "Unknown compiler toolchain. Compiling without warning flags.") + +endif () + + # Common definitions # # Lifted from comm.gmk section "Common definitions". @@ -120,91 +248,6 @@ add_compile_definitions( ) -# Compilers - -if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - - message(VERBOSE "compiler.gc detected") - - # Lifted from variables in gc.gmk - set(CFLAGSDEBUG -O -g3) - set(CFLAGSOPT -O2 -g3) - set(CFLAGSCOMPILER - -Waggregate-return - -Wall - -Wcast-qual - -Werror - -Wextra - -Winline - -Wmissing-prototypes - -Wnested-externs - -Wpointer-arith - -Wshadow - -Wstrict-aliasing=2 - -Wstrict-prototypes - -Wswitch-default - -Wwrite-strings - ) - set(CFLAGSCOMPILERSTRICT - -std=c89 - -pedantic - ) - -elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") - - message(VERBOSE "compiler.cl detected") - - # Lifted from variables in ll.gmk - set(CFLAGSDEBUG, -O0 -g3) - set(CFLAGSOPT, O2 -g3) - set(CFLAGSCOMPILER, - -Waggregate-return - -Wall - -Wcast-qual - -Wconversion - -Wduplicate-enum - -Werror - -Wextra - -Winline - -Wmissing-prototypes - -Wmissing-variable-declarations - -Wnested-externs - -Wpointer-arith - -Wshadow - -Wstrict-aliasing=2 - -Wstrict-prototypes - -Wunreachable-code - -Wwrite-strings - ) - set(CFLAGSCOMPILERSTRICT, - -std=c89 - -pedantic - ) - -elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") - - message(VERBOSE "compiler.mv detected") - - # Lifted from variables in mv.nmk. - set(CFLAGSDEBUG, /MTd /Od) - set(CFLAGSOPT, /O2 /MT) - set(CFLAGSCOMPILER, - # from CFLAGSCOMMONPRE in commpre.nmk - /nologo - # FIXME: PFMDEFS? - # FIXME: CFLAGSTARGETPRE? - /W4 /WX - ) - set(CFLAGSCOMPILERSTRICT, ) - - # FIXME: LINKFLAGS* from mv.nmk - -else () - - message(WARNING "Unknown compiler toolchain. Compiling without warning flags.") - -endif () - add_compile_options( "$<$:${CFLAGSDEBUG}>" "$<$:${CFLAGSOPT}>" @@ -219,6 +262,7 @@ add_compile_options( add_executable(gcbench gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) target_link_libraries(gcbench PRIVATE m) +target_compile_options(gcbench PRIVATE ${CFLAGSCOMPILERSTRICT}) # FIXME: Should be C89 but CMake doesn't know it. # FIXME: How to set this for all targets not just gcbench? # target_compile_features(gcbench PRIVATE c_std_90) @@ -231,3 +275,9 @@ add_library(mps STATIC $<$:${MPM}> ) target_compile_options(mps PRIVATE ${CFLAGSCOMPILERSTRICT}) + +add_library(mpsplan STATIC ${PLINTH}) +target_compile_options(mpsplan PRIVATE ${CFLAGSCOMPILERSTRICT}) + +add_executable(abqtest abqtest.c ${TESTLIB}) +target_link_libraries(abqtest PRIVATE m mps) diff --git a/code/TargetArch.cmake b/code/TargetArch.cmake new file mode 100644 index 0000000000..818223f67d --- /dev/null +++ b/code/TargetArch.cmake @@ -0,0 +1,142 @@ +# TargetArch.cmake -- Detect target architecture in CMake +# +# See "How to detect target architecture using CMake?" +# . +# +# Imported from +# https://github.com/axr/solar-cmake/blob/73cfea0db0284c5e2010aca23989046e5bda95c9/TargetArch.cmake + +# Based on the Qt 5 processor detection code, so should be very accurate +# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h +# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64) + +# Regarding POWER/PowerPC, just as is noted in the Qt source, +# "There are many more known variants/revisions that we do not handle/detect." + +set(archdetect_c_code " +#if defined(__arm__) || defined(__TARGET_ARCH_ARM) + #if defined(__ARM_ARCH_7__) \\ + || defined(__ARM_ARCH_7A__) \\ + || defined(__ARM_ARCH_7R__) \\ + || defined(__ARM_ARCH_7M__) \\ + || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7) + #error cmake_ARCH armv7 + #elif defined(__ARM_ARCH_6__) \\ + || defined(__ARM_ARCH_6J__) \\ + || defined(__ARM_ARCH_6T2__) \\ + || defined(__ARM_ARCH_6Z__) \\ + || defined(__ARM_ARCH_6K__) \\ + || defined(__ARM_ARCH_6ZK__) \\ + || defined(__ARM_ARCH_6M__) \\ + || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6) + #error cmake_ARCH armv6 + #elif defined(__ARM_ARCH_5TEJ__) \\ + || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5) + #error cmake_ARCH armv5 + #else + #error cmake_ARCH arm + #endif +#elif defined(__i386) || defined(__i386__) || defined(_M_IX86) + #error cmake_ARCH i386 +#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) + #error cmake_ARCH x86_64 +#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64) + #error cmake_ARCH ia64 +#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\ + || defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\ + || defined(_M_MPPC) || defined(_M_PPC) + #if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__) + #error cmake_ARCH ppc64 + #else + #error cmake_ARCH ppc + #endif +#endif + +#error cmake_ARCH unknown +") + +# Set ppc_support to TRUE before including this file or ppc and ppc64 +# will be treated as invalid architectures since they are no longer supported by Apple + +function(target_architecture output_var) + if(APPLE AND CMAKE_OSX_ARCHITECTURES) + # On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set + # First let's normalize the order of the values + + # Note that it's not possible to compile PowerPC applications if you are using + # the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we + # disable it by default + # See this page for more information: + # http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4 + + # Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime. + # On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise. + + foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES}) + if("${osx_arch}" STREQUAL "ppc" AND ppc_support) + set(osx_arch_ppc TRUE) + elseif("${osx_arch}" STREQUAL "i386") + set(osx_arch_i386 TRUE) + elseif("${osx_arch}" STREQUAL "x86_64") + set(osx_arch_x86_64 TRUE) + elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support) + set(osx_arch_ppc64 TRUE) + else() + message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}") + endif() + endforeach() + + # Now add all the architectures in our normalized order + if(osx_arch_ppc) + list(APPEND ARCH ppc) + endif() + + if(osx_arch_i386) + list(APPEND ARCH i386) + endif() + + if(osx_arch_x86_64) + list(APPEND ARCH x86_64) + endif() + + if(osx_arch_ppc64) + list(APPEND ARCH ppc64) + endif() + else() + file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}") + + enable_language(C) + + # Detect the architecture in a rather creative way... + # This compiles a small C program which is a series of ifdefs that selects a + # particular #error preprocessor directive whose message string contains the + # target architecture. The program will always fail to compile (both because + # file is not a valid C program, and obviously because of the presence of the + # #error preprocessor directives... but by exploiting the preprocessor in this + # way, we can detect the correct target architecture even when cross-compiling, + # since the program itself never needs to be run (only the compiler/preprocessor) + try_run( + run_result_unused + compile_result_unused + "${CMAKE_BINARY_DIR}" + "${CMAKE_BINARY_DIR}/arch.c" + COMPILE_OUTPUT_VARIABLE ARCH + CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + ) + + # Parse the architecture name from the compiler output + string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}") + + # Get rid of the value marker leaving just the architecture name + string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}") + + # If we are compiling with an unknown architecture this variable should + # already be set to "unknown" but in the case that it's empty (i.e. due + # to a typo in the code), then set it to unknown + if (NOT ARCH) + set(ARCH unknown) + endif() + endif() + + set(${output_var} "${ARCH}" PARENT_SCOPE) +endfunction() From 2af1bddfa98b733496fc85171a841a87f23767dd Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Thu, 16 Feb 2023 08:09:58 +0000 Subject: [PATCH 05/14] Adding copyright and license (BSD 2-clause) from the source project . --- code/TargetArch.cmake | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/code/TargetArch.cmake b/code/TargetArch.cmake index 818223f67d..157ac13eff 100644 --- a/code/TargetArch.cmake +++ b/code/TargetArch.cmake @@ -1,5 +1,8 @@ # TargetArch.cmake -- Detect target architecture in CMake # +# Copyright (c) 2012 Petroules Corporation. All rights reserved. See +# end of file for license. +# # See "How to detect target architecture using CMake?" # . # @@ -140,3 +143,32 @@ function(target_architecture output_var) set(${output_var} "${ARCH}" PARENT_SCOPE) endfunction() + +# Copyright and License +# --------------------- +# +# Copyright (c) 2012 Petroules Corporation. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From fd84a330da87531bdd98f3f2def52529897261e4 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Thu, 16 Feb 2023 08:22:36 +0000 Subject: [PATCH 06/14] Noting likely problems and solutions in leader comment. --- code/TargetArch.cmake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/code/TargetArch.cmake b/code/TargetArch.cmake index 157ac13eff..16e4491fb9 100644 --- a/code/TargetArch.cmake +++ b/code/TargetArch.cmake @@ -8,6 +8,16 @@ # # Imported from # https://github.com/axr/solar-cmake/blob/73cfea0db0284c5e2010aca23989046e5bda95c9/TargetArch.cmake +# +# FIXME: This doesn't seem to deal with macOS on Apple Silicon (arm64). +# +# NOTE: A possible alternative is to invoke ``cc -dumpmachine`` for +# Clang or GCC (all platforms except Windows). +# +# NOTE: A possible alternative is to substitute mpstd.h for the +# ``archdetect_c_code`` in this file, substituting ``#define +# MPS_PF_STRING`` with ``#error MPS_PF_STRING``. + # Based on the Qt 5 processor detection code, so should be very accurate # https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h From 67af21af53bbcd7d7b13e78e2581b246ab98f44a Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Thu, 16 Feb 2023 12:49:02 +0000 Subject: [PATCH 07/14] Detecting and using target architecture to specify MPS library contents. --- code/CMakeLists.txt | 120 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 24 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 07dfdc5b75..ec85a88d9e 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -29,27 +29,77 @@ project(mps LANGUAGES C) # architecture whatsoever." -- https://stackoverflow.com/a/12024211 # # TODO: How does this work for multi-arch builds such as Xcode? +# +# NOTE: A possible alternative is to invoke ``cc -dumpmachine``. include(TargetArch.cmake) target_architecture(TARGET_ARCHITECTURE) message(VERBOSE "Target architecture ${TARGET_ARCHITECTURE}") +if (TARGET_ARCHITECTURE STREQUAL "x86_64") + message(VERBOSE, "arch.i6 detected") + set(ARCH i6) +elseif (TARGET_ARCHITECTURE STREQUAL "i386") + message(VERBOSE, "arch.i3 detected") + set(ARCH i3) +else () + + # FIXME: Needs filling in + +endif () + # Operating Systems -if (APPLE) # Must come before UNIX, which is also true for macOS +if (APPLE) + message(VERBOSE, "os.xc detected") + set(OS xc) +elseif (LINUX) + message(VERBOSE, "os.li detected") + set(OS li) +elseif (BSD) + message(VERBOSE, "os.fr detected") + set(OS fr) +elseif (WIN32) + message(VERBOSE, "os.w3 detected") + set(OS w3) +else () + message(FATAL_ERROR "Unable to detect target OS") +endif () - # FIXME: Needs filling in +# FIXME: What about ANSI platform? +# FIXME: What about Freestanding platform? + +if (OS STREQUAL "xc") + + # Lifted from xci3ll.gmk and xci6ll.gmk + # + # FIXME: Untested + # + # FIXME: xci3ll.gmk includes this line:: + # + # CC = clang -arch i386 + + set(MPMPF + lockix.c + prmc${ARCH}.c + prmc${OS}.c + prmcxc${ARCH}.c + protix.c + prot${OS}.c + span.c + thxc.c + vmix.c + ) -elseif (UNIX) +elseif (OS STREQUAL "li") - # FIXME: Lifted from lii6gc.gmk and not general for all Posix - # platforms + # Lifted from lii3ll.gmk and lii6ll.gmk set(MPMPF lockix.c - prmci6.c + prmc${ARCH}.c prmcix.c - prmclii6.c + prmc${OS}${ARCH}.c protix.c protsgix.c pthrdext.c @@ -58,9 +108,31 @@ elseif (UNIX) vmix.c ) -elseif (WIN32) +elseif (OS STREQUAL "fr") + + # FIXME: Fill this in from fr*.gmk - # FIXME: Import from w3*.nmk +elseif (OS STREQUAL "w3") + + # Lifted from w3i6mv.nmk + # + # FIXME: Untested + + set(MPMPF + lock${OS}.c + mpsi${OS}.c + prmc${ARCH}.c + prmc${OS}.c + prmc${OS}${ARCH}.c + prot${OS}.c + sp${OS}${ARCH}.c + th${OS}.c + vm${OS}.c + ) + +else () + + message(FATAL_ERROR "Unable to detect target OS") endif () @@ -100,9 +172,9 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") message(VERBOSE "compiler.cl detected") # Lifted from variables in ll.gmk - set(CFLAGSDEBUG, -O0 -g3) - set(CFLAGSOPT, O2 -g3) - set(CFLAGSCOMPILER, + set(CFLAGSDEBUG -O0 -g3) + set(CFLAGSOPT O2 -g3) + set(CFLAGSCOMPILER -Waggregate-return -Wall -Wcast-qual @@ -121,7 +193,7 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") -Wunreachable-code -Wwrite-strings ) - set(CFLAGSCOMPILERSTRICT, + set(CFLAGSCOMPILERSTRICT -std=c89 -pedantic ) @@ -131,16 +203,16 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") message(VERBOSE "compiler.mv detected") # Lifted from variables in mv.nmk. - set(CFLAGSDEBUG, /MTd /Od) - set(CFLAGSOPT, /O2 /MT) - set(CFLAGSCOMPILER, + set(CFLAGSDEBUG /MTd /Od) + set(CFLAGSOPT /O2 /MT) + set(CFLAGSCOMPILER # from CFLAGSCOMMONPRE in commpre.nmk /nologo # FIXME: PFMDEFS? # FIXME: CFLAGSTARGETPRE? /W4 /WX ) - set(CFLAGSCOMPILERSTRICT, ) + set(CFLAGSCOMPILERSTRICT ) # FIXME: LINKFLAGS* from mv.nmk @@ -260,13 +332,6 @@ add_compile_options( # # Just using gcbench as an example target for now. -add_executable(gcbench gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) -target_link_libraries(gcbench PRIVATE m) -target_compile_options(gcbench PRIVATE ${CFLAGSCOMPILERSTRICT}) -# FIXME: Should be C89 but CMake doesn't know it. -# FIXME: How to set this for all targets not just gcbench? -# target_compile_features(gcbench PRIVATE c_std_90) - #add_library(mps OBJECT mps.c) #target_compile_options(mps PRIVATE ${CFLAGSCOMPILERSTRICT}) @@ -281,3 +346,10 @@ target_compile_options(mpsplan PRIVATE ${CFLAGSCOMPILERSTRICT}) add_executable(abqtest abqtest.c ${TESTLIB}) target_link_libraries(abqtest PRIVATE m mps) + +add_executable(gcbench gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) +target_link_libraries(gcbench PRIVATE m) +target_compile_options(gcbench PRIVATE ${CFLAGSCOMPILERSTRICT}) +# FIXME: Should be C89 but CMake doesn't know it. +# FIXME: How to set this for all targets not just gcbench? +# target_compile_features(gcbench PRIVATE c_std_90) From c1d929f23292ba10d829299b73548208df567d53 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 17 Feb 2023 00:04:09 +0000 Subject: [PATCH 08/14] Possibly reliable target detection using mpstd.h. --- code/CMakeLists.txt | 94 ++++++++++----------- code/TargetArch.cmake | 184 ------------------------------------------ 2 files changed, 44 insertions(+), 234 deletions(-) delete mode 100644 code/TargetArch.cmake diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index ec85a88d9e..dd692c8e0a 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -18,55 +18,55 @@ # Tutorial says to put this in but does not give any advice about the # argument, so I'm guessing based on feature documentation I've used. -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.25) project(mps LANGUAGES C) +# Some people say this defaults to "Release", but it's sometimes +# blank. +message(VERBOSE "Build type ${CMAKE_BUILD_TYPE}") -# Architectures -# -# "it appears that CMake has no functionality to detect the target -# architecture whatsoever." -- https://stackoverflow.com/a/12024211 -# -# TODO: How does this work for multi-arch builds such as Xcode? -# -# NOTE: A possible alternative is to invoke ``cc -dumpmachine``. - -include(TargetArch.cmake) -target_architecture(TARGET_ARCHITECTURE) -message(VERBOSE "Target architecture ${TARGET_ARCHITECTURE}") - -if (TARGET_ARCHITECTURE STREQUAL "x86_64") - message(VERBOSE, "arch.i6 detected") - set(ARCH i6) -elseif (TARGET_ARCHITECTURE STREQUAL "i386") - message(VERBOSE, "arch.i3 detected") - set(ARCH i3) -else () - # FIXME: Needs filling in - -endif () - - -# Operating Systems - -if (APPLE) - message(VERBOSE, "os.xc detected") - set(OS xc) -elseif (LINUX) - message(VERBOSE, "os.li detected") - set(OS li) -elseif (BSD) - message(VERBOSE, "os.fr detected") - set(OS fr) -elseif (WIN32) - message(VERBOSE, "os.w3 detected") - set(OS w3) +# Detect target platform +# +# This is a nasty hack. CMake doesn't provide a reliably way of +# determining the target platform; nothing like the target triple from +# ``cc -dumpmachine``. Variables like CMAKE_SYSTEM_PROCESSOR are +# documented as "not guaranteed" and are therefore useless +# . +# Astounding hacks like seem to +# be necessary. This is based on that, but uses try_compile rather +# than try_run, and so should work when cross-compiling +# . + +# FIXME: This creates a dependency on the layout of mpstd.h. Document +# and link at both ends. + +# FIXME: How to override detection? + +file(READ mpstd.h FILE_MPSTD_H) +string( + REGEX REPLACE "\n[ \t]*#define[ \t]+MPS_PF_STRING[ \t]+" "\n#error " + FILE_MPSTDE_C "${FILE_MPSTD_H}" +) +string(APPEND FILE_MPSTDE_C "int main(void) { return 0; }\n") +try_compile( + MPSTDE_RESULT + SOURCE_FROM_VAR "mpstde.c" FILE_MPSTDE_C + OUTPUT_VARIABLE MPSTDE_OUTPUT +) +if (MPSTDE_OUTPUT MATCHES "#error[ \t]+\"((..)(..)(..))\"") + set(MPS_PF_STRING ${CMAKE_MATCH_1}) + set(OS ${CMAKE_MATCH_2}) + set(ARCH ${CMAKE_MATCH_3}) + set(COMPILER ${CMAKE_MATCH_4}) + message(VERBOSE "MPS_PF_STRING = ${CMAKE_MATCH_1}") + message(VERBOSE "OS = ${OS} ARCH = ${ARCH} COMPILER = ${COMPILER}") else () - message(FATAL_ERROR "Unable to detect target OS") + message(FATAL_ERROR "Unable to detect target platform") endif () + # FIXME: What about ANSI platform? # FIXME: What about Freestanding platform? @@ -139,9 +139,7 @@ endif () # Compilers -if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - - message(VERBOSE "compiler.gc detected") +if (COMPILER STREQUAL "gc") # Lifted from variables in gc.gmk set(CFLAGSDEBUG -O -g3) @@ -167,9 +165,7 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU") -pedantic ) -elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") - - message(VERBOSE "compiler.cl detected") +elseif (COMPILER STREQUAL "ll") # Lifted from variables in ll.gmk set(CFLAGSDEBUG -O0 -g3) @@ -198,9 +194,7 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") -pedantic ) -elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") - - message(VERBOSE "compiler.mv detected") +elseif (COMPILER STREQUAL "mv") # Lifted from variables in mv.nmk. set(CFLAGSDEBUG /MTd /Od) diff --git a/code/TargetArch.cmake b/code/TargetArch.cmake deleted file mode 100644 index 16e4491fb9..0000000000 --- a/code/TargetArch.cmake +++ /dev/null @@ -1,184 +0,0 @@ -# TargetArch.cmake -- Detect target architecture in CMake -# -# Copyright (c) 2012 Petroules Corporation. All rights reserved. See -# end of file for license. -# -# See "How to detect target architecture using CMake?" -# . -# -# Imported from -# https://github.com/axr/solar-cmake/blob/73cfea0db0284c5e2010aca23989046e5bda95c9/TargetArch.cmake -# -# FIXME: This doesn't seem to deal with macOS on Apple Silicon (arm64). -# -# NOTE: A possible alternative is to invoke ``cc -dumpmachine`` for -# Clang or GCC (all platforms except Windows). -# -# NOTE: A possible alternative is to substitute mpstd.h for the -# ``archdetect_c_code`` in this file, substituting ``#define -# MPS_PF_STRING`` with ``#error MPS_PF_STRING``. - - -# Based on the Qt 5 processor detection code, so should be very accurate -# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h -# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64) - -# Regarding POWER/PowerPC, just as is noted in the Qt source, -# "There are many more known variants/revisions that we do not handle/detect." - -set(archdetect_c_code " -#if defined(__arm__) || defined(__TARGET_ARCH_ARM) - #if defined(__ARM_ARCH_7__) \\ - || defined(__ARM_ARCH_7A__) \\ - || defined(__ARM_ARCH_7R__) \\ - || defined(__ARM_ARCH_7M__) \\ - || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7) - #error cmake_ARCH armv7 - #elif defined(__ARM_ARCH_6__) \\ - || defined(__ARM_ARCH_6J__) \\ - || defined(__ARM_ARCH_6T2__) \\ - || defined(__ARM_ARCH_6Z__) \\ - || defined(__ARM_ARCH_6K__) \\ - || defined(__ARM_ARCH_6ZK__) \\ - || defined(__ARM_ARCH_6M__) \\ - || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6) - #error cmake_ARCH armv6 - #elif defined(__ARM_ARCH_5TEJ__) \\ - || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5) - #error cmake_ARCH armv5 - #else - #error cmake_ARCH arm - #endif -#elif defined(__i386) || defined(__i386__) || defined(_M_IX86) - #error cmake_ARCH i386 -#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) - #error cmake_ARCH x86_64 -#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64) - #error cmake_ARCH ia64 -#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\ - || defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\ - || defined(_M_MPPC) || defined(_M_PPC) - #if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__) - #error cmake_ARCH ppc64 - #else - #error cmake_ARCH ppc - #endif -#endif - -#error cmake_ARCH unknown -") - -# Set ppc_support to TRUE before including this file or ppc and ppc64 -# will be treated as invalid architectures since they are no longer supported by Apple - -function(target_architecture output_var) - if(APPLE AND CMAKE_OSX_ARCHITECTURES) - # On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set - # First let's normalize the order of the values - - # Note that it's not possible to compile PowerPC applications if you are using - # the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we - # disable it by default - # See this page for more information: - # http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4 - - # Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime. - # On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise. - - foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES}) - if("${osx_arch}" STREQUAL "ppc" AND ppc_support) - set(osx_arch_ppc TRUE) - elseif("${osx_arch}" STREQUAL "i386") - set(osx_arch_i386 TRUE) - elseif("${osx_arch}" STREQUAL "x86_64") - set(osx_arch_x86_64 TRUE) - elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support) - set(osx_arch_ppc64 TRUE) - else() - message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}") - endif() - endforeach() - - # Now add all the architectures in our normalized order - if(osx_arch_ppc) - list(APPEND ARCH ppc) - endif() - - if(osx_arch_i386) - list(APPEND ARCH i386) - endif() - - if(osx_arch_x86_64) - list(APPEND ARCH x86_64) - endif() - - if(osx_arch_ppc64) - list(APPEND ARCH ppc64) - endif() - else() - file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${archdetect_c_code}") - - enable_language(C) - - # Detect the architecture in a rather creative way... - # This compiles a small C program which is a series of ifdefs that selects a - # particular #error preprocessor directive whose message string contains the - # target architecture. The program will always fail to compile (both because - # file is not a valid C program, and obviously because of the presence of the - # #error preprocessor directives... but by exploiting the preprocessor in this - # way, we can detect the correct target architecture even when cross-compiling, - # since the program itself never needs to be run (only the compiler/preprocessor) - try_run( - run_result_unused - compile_result_unused - "${CMAKE_BINARY_DIR}" - "${CMAKE_BINARY_DIR}/arch.c" - COMPILE_OUTPUT_VARIABLE ARCH - CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} - ) - - # Parse the architecture name from the compiler output - string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}") - - # Get rid of the value marker leaving just the architecture name - string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}") - - # If we are compiling with an unknown architecture this variable should - # already be set to "unknown" but in the case that it's empty (i.e. due - # to a typo in the code), then set it to unknown - if (NOT ARCH) - set(ARCH unknown) - endif() - endif() - - set(${output_var} "${ARCH}" PARENT_SCOPE) -endfunction() - -# Copyright and License -# --------------------- -# -# Copyright (c) 2012 Petroules Corporation. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the -# distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From b8308bb4c57f442563def8675160787373a0e9db Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 17 Feb 2023 00:41:20 +0000 Subject: [PATCH 09/14] Moving CMakeLists.txt to top level, as recommended by "Converting Existing Systems to CMake" . --- .gitignore | 6 ++++++ code/CMakeLists.txt => CMakeLists.txt | 18 +++++++++++++----- code/.gitignore | 4 ---- 3 files changed, 19 insertions(+), 9 deletions(-) rename code/CMakeLists.txt => CMakeLists.txt (93%) diff --git a/.gitignore b/.gitignore index 89c70e46dc..b9f9bcdd29 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,9 @@ test/test/obj *~ .#.* core +# CMake output +CMakeFiles +CMakeCache.txt +cmake_install.cmake +hot +cool diff --git a/code/CMakeLists.txt b/CMakeLists.txt similarity index 93% rename from code/CMakeLists.txt rename to CMakeLists.txt index dd692c8e0a..db8534b0d8 100644 --- a/code/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ # # Invoke like:: # -# cmake -B hot -DCMAKE_BUILD_TYPE=RELEASE --log-level=VERBOSE . && cmake --build hot --verbose +# cmake . -B hot -DCMAKE_BUILD_TYPE=RELEASE --log-level=VERBOSE && cmake --build hot --verbose # # See GitHub issue #146 # for discussion. @@ -44,7 +44,7 @@ message(VERBOSE "Build type ${CMAKE_BUILD_TYPE}") # FIXME: How to override detection? -file(READ mpstd.h FILE_MPSTD_H) +file(READ code/mpstd.h FILE_MPSTD_H) string( REGEX REPLACE "\n[ \t]*#define[ \t]+MPS_PF_STRING[ \t]+" "\n#error " FILE_MPSTDE_C "${FILE_MPSTD_H}" @@ -296,6 +296,14 @@ set(POOLS ${AMC} ${AMS} ${AWL} ${LO} ${MV2} ${MVFF} ${SNC}) set(MPM ${MPMCOMMON} ${MPMPF} ${POOLS} ${PLINTH}) +# FIXME: There's probably a better way to do this +list(TRANSFORM MPM PREPEND "code/") +list(TRANSFORM PLINTH PREPEND "code/") +list(TRANSFORM TESTLIB PREPEND "code/") +list(TRANSFORM FMTDYTST PREPEND "code/") +list(TRANSFORM TESTTHR PREPEND "code/") + + # Varieties # # MPS varieties (HOT, COOL, etc.) probably map to CMake "Build @@ -330,7 +338,7 @@ add_compile_options( #target_compile_options(mps PRIVATE ${CFLAGSCOMPILERSTRICT}) add_library(mps STATIC - $<$:mps.c> + $<$:code/mps.c> $<$:${MPM}> ) target_compile_options(mps PRIVATE ${CFLAGSCOMPILERSTRICT}) @@ -338,10 +346,10 @@ target_compile_options(mps PRIVATE ${CFLAGSCOMPILERSTRICT}) add_library(mpsplan STATIC ${PLINTH}) target_compile_options(mpsplan PRIVATE ${CFLAGSCOMPILERSTRICT}) -add_executable(abqtest abqtest.c ${TESTLIB}) +add_executable(abqtest code/abqtest.c ${TESTLIB}) target_link_libraries(abqtest PRIVATE m mps) -add_executable(gcbench gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) +add_executable(gcbench code/gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) target_link_libraries(gcbench PRIVATE m) target_compile_options(gcbench PRIVATE ${CFLAGSCOMPILERSTRICT}) # FIXME: Should be C89 but CMake doesn't know it. diff --git a/code/.gitignore b/code/.gitignore index fa3565667d..ff483930b8 100644 --- a/code/.gitignore +++ b/code/.gitignore @@ -61,7 +61,3 @@ tags *~ # GNU make dependencies */*/*.d -# CMake output -CMakeFiles -CMakeCache.txt -cmake_install.cmake From 5c758ae2f4abcb8e4258f71065a720614ea8dbb0 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 17 Feb 2023 00:47:40 +0000 Subject: [PATCH 10/14] Defaulting to RELEASE build type. --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db8534b0d8..3ba7b8fd67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,12 @@ project(mps LANGUAGES C) # Some people say this defaults to "Release", but it's sometimes # blank. -message(VERBOSE "Build type ${CMAKE_BUILD_TYPE}") +if (CMAKE_BUILD_TYPE) + message(VERBOSE "Build type ${CMAKE_BUILD_TYPE}") +else () + set(CMAKE_BUILD_TYPE "RELEASE") + message(VERBOSE "Set build type to ${CMAKE_BUILD_TYPE}") +endif () # Detect target platform From 08a2ec651f2f6cf6b14c9abaaf6089b4a7a416ba Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 17 Feb 2023 01:22:38 +0000 Subject: [PATCH 11/14] Experimenting with CTest. Adding amcss and abqtest as test targets. --- CMakeLists.txt | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ba7b8fd67..f60039b60d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,11 @@ # # cmake . -B hot -DCMAKE_BUILD_TYPE=RELEASE --log-level=VERBOSE && cmake --build hot --verbose # +# or like:: +# +# cmake . -B cool -DCMAKE_BUILD_TYPE=DEBUG +# make -C cool all test +# # See GitHub issue #146 # for discussion. # @@ -351,12 +356,27 @@ target_compile_options(mps PRIVATE ${CFLAGSCOMPILERSTRICT}) add_library(mpsplan STATIC ${PLINTH}) target_compile_options(mpsplan PRIVATE ${CFLAGSCOMPILERSTRICT}) -add_executable(abqtest code/abqtest.c ${TESTLIB}) -target_link_libraries(abqtest PRIVATE m mps) - add_executable(gcbench code/gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) target_link_libraries(gcbench PRIVATE m) target_compile_options(gcbench PRIVATE ${CFLAGSCOMPILERSTRICT}) # FIXME: Should be C89 but CMake doesn't know it. # FIXME: How to set this for all targets not just gcbench? # target_compile_features(gcbench PRIVATE c_std_90) + + +# Tests +# +# Tests specified with ``add_test`` can be run with e.g. +# ``make -C cool test``. +# +# See . + +include(CTest) + +add_executable(amcss code/amcss.c ${TESTLIB} ${FMTDYTST}) +target_link_libraries(amcss PRIVATE m mps) +add_test(NAME amcss COMMAND amcss) + +add_executable(abqtest code/abqtest.c ${TESTLIB}) +target_link_libraries(abqtest PRIVATE m mps) +add_test(NAME abqtest COMMAND abqtest) From 0ee88b239590e5c7efcf59b55f42d9113f137b3a Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Sat, 18 Feb 2023 21:44:18 +0000 Subject: [PATCH 12/14] Getting CMake to work on Windows, at least partially. --- CMakeLists.txt | 63 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f60039b60d..944b994a32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,12 @@ # cmake . -B cool -DCMAKE_BUILD_TYPE=DEBUG # make -C cool all test # +# or like (on Windows):: +# +# cmake . -B cool -DCMAKE_BUILD_TYPE=DEBUG -G "NMake Makefiles" +# cd cool +# nmake all test +# # See GitHub issue #146 # for discussion. # @@ -23,6 +29,9 @@ # Tutorial says to put this in but does not give any advice about the # argument, so I'm guessing based on feature documentation I've used. +# +# FIXME: The default CMake with Visual Studio 2017 is 3.12. Check +# features to see if we can work with that. cmake_minimum_required(VERSION 3.25) project(mps LANGUAGES C) @@ -65,7 +74,12 @@ try_compile( SOURCE_FROM_VAR "mpstde.c" FILE_MPSTDE_C OUTPUT_VARIABLE MPSTDE_OUTPUT ) -if (MPSTDE_OUTPUT MATCHES "#error[ \t]+\"((..)(..)(..))\"") +if (MPSTDE_RESULT) + message(FATAL_ERROR "Target detection should have failed due to #error") +endif () +# Uncomment the following line to help debug the #error match +# message(VERBOSE "MPSTDE_OUTPUT = ${MPSTDE_OUTPUT}") +if (MPSTDE_OUTPUT MATCHES "#error:?[ \t]+\"((..)(..)(..))\"") set(MPS_PF_STRING ${CMAKE_MATCH_1}) set(OS ${CMAKE_MATCH_2}) set(ARCH ${CMAKE_MATCH_3}) @@ -102,6 +116,12 @@ if (OS STREQUAL "xc") vmix.c ) + set(TESTLIB testlib.c) + set(TESTTHR testthrix.c) + + # FIXME: Is this necessary on macOS? + link_libraries(m) + elseif (OS STREQUAL "li") # Lifted from lii3ll.gmk and lii6ll.gmk @@ -118,10 +138,20 @@ elseif (OS STREQUAL "li") vmix.c ) + set(TESTLIB testlib.c) + set(TESTTHR testthrix.c) + + link_libraries(m) + elseif (OS STREQUAL "fr") # FIXME: Fill this in from fr*.gmk + set(TESTLIB testlib.c) + set(TESTTHR testthrix.c) + + link_libraries(m) + elseif (OS STREQUAL "w3") # Lifted from w3i6mv.nmk @@ -140,6 +170,9 @@ elseif (OS STREQUAL "w3") vm${OS}.c ) + set(TESTLIB testlib.c getoptl.c) + set(TESTTHR testthr${OS}.c) + else () message(FATAL_ERROR "Unable to detect target OS") @@ -209,16 +242,32 @@ elseif (COMPILER STREQUAL "mv") # Lifted from variables in mv.nmk. set(CFLAGSDEBUG /MTd /Od) set(CFLAGSOPT /O2 /MT) + set(CFLAGSCOMPILER # from CFLAGSCOMMONPRE in commpre.nmk /nologo # FIXME: PFMDEFS? # FIXME: CFLAGSTARGETPRE? - /W4 /WX + /Zi + # from mv.nmk + /D_CRT_SECURE_NO_WARNINGS /W4 /WX /Gs ) set(CFLAGSCOMPILERSTRICT ) # FIXME: LINKFLAGS* from mv.nmk + # What about PDBs? + set(CMAKE_EXE_LINKER_FLAGS /LARGEADDRESSAWARE) + + # These may be the defaults for CMake. Investigate. + # Defaults seem to be: + # Debug: /debug /INCREMENTAL + # Release: /INCREMENTAL:NO + # message(VERBOSE "Linker flags debug: ${CMAKE_EXE_LINKER_FLAGS_DEBUG}") + # message(VERBOSE "Linker flags release: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}") + # Lifted from commpre.nmk + # FIXME: mv.nmk specifies libcmt.lib and libcmtd.lib. Why? + set(CMAKE_EXE_LINKER_FLAGS_DEBUG /DEBUG) + set(CMAKE_EXE_LINKER_FLAGS_RELEASE /RELEASE) else () @@ -243,8 +292,6 @@ set(SNC poolsnc.c) set(POOLN pooln.c) set(MV2 poolmv2.c) set(MVFF poolmvff.c) -set(TESTLIB testlib.c) -set(TESTTHR testthrix.c) # FIXME: Platform specific, varies by OS set(FMTDY fmtdy.c fmtno.c) set(FMTDYTST fmtdy.c fmtno.c fmtdytst.c) set(FMTHETST fmthe.c fmtdy.c fmtno.c fmtdytst.c) @@ -322,6 +369,9 @@ list(TRANSFORM TESTTHR PREPEND "code/") # I'm just mapping Debug and Release for now. # Unset CMake's default flags +# message(VERBOSE "CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}") +# message(VERBOSE "CMAKE_C_FLAGS_DEBUG = ${CMAKE_C_FLAGS_DEBUG}") +# message(VERBOSE "CMAKE_C_FLAGS_RELEASE = ${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_DEBUG "") set(CMAKE_C_FLAGS_RELEASE "") set(CMAKE_C_FLAGS "") @@ -357,7 +407,6 @@ add_library(mpsplan STATIC ${PLINTH}) target_compile_options(mpsplan PRIVATE ${CFLAGSCOMPILERSTRICT}) add_executable(gcbench code/gcbench.c ${FMTDYTST} ${TESTLIB} ${TESTTHR}) -target_link_libraries(gcbench PRIVATE m) target_compile_options(gcbench PRIVATE ${CFLAGSCOMPILERSTRICT}) # FIXME: Should be C89 but CMake doesn't know it. # FIXME: How to set this for all targets not just gcbench? @@ -374,9 +423,9 @@ target_compile_options(gcbench PRIVATE ${CFLAGSCOMPILERSTRICT}) include(CTest) add_executable(amcss code/amcss.c ${TESTLIB} ${FMTDYTST}) -target_link_libraries(amcss PRIVATE m mps) +target_link_libraries(amcss PRIVATE mps) add_test(NAME amcss COMMAND amcss) add_executable(abqtest code/abqtest.c ${TESTLIB}) -target_link_libraries(abqtest PRIVATE m mps) +target_link_libraries(abqtest PRIVATE mps) add_test(NAME abqtest COMMAND abqtest) From 95c3f406131eab93cb3c068dcd5f4637ae8c4afc Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Mon, 20 Feb 2023 07:19:22 +0000 Subject: [PATCH 13/14] Determining minimum CMake version from docs. --- CMakeLists.txt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 944b994a32..a43d357654 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,14 +27,18 @@ # # TODO: Incorporate %% instructions -# Tutorial says to put this in but does not give any advice about the -# argument, so I'm guessing based on feature documentation I've used. +# Specify CMake version # -# FIXME: The default CMake with Visual Studio 2017 is 3.12. Check -# features to see if we can work with that. +# The latest feature use is try_compile, which requires CMake 3.25 +# . cmake_minimum_required(VERSION 3.25) -project(mps LANGUAGES C) +project( + mps + LANGUAGES C + DESCRIPTION "Memory Pool System" # New in CMake 3.9 + HOMEPAGE_URL "https://www.ravenbrook.com/project/mps" # New in CMake 3.12 +) # Some people say this defaults to "Release", but it's sometimes # blank. @@ -69,7 +73,7 @@ string( FILE_MPSTDE_C "${FILE_MPSTD_H}" ) string(APPEND FILE_MPSTDE_C "int main(void) { return 0; }\n") -try_compile( +try_compile( # New in CMake 3.25 MPSTDE_RESULT SOURCE_FROM_VAR "mpstde.c" FILE_MPSTDE_C OUTPUT_VARIABLE MPSTDE_OUTPUT From c1f1c83eee2add013c7c877c63aa82e16483a00c Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Mon, 20 Feb 2023 08:04:49 +0000 Subject: [PATCH 14/14] Tidying up FIXMEs. --- CMakeLists.txt | 248 ++++++++++++++++++++++++------------------------- 1 file changed, 120 insertions(+), 128 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a43d357654..f780a951ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# code/CMakeLists.txt -- CMake configuration for the MPS +# CMakeLists.txt -- CMake configuration for the MPS # # This is just an experimental demonstration configuration to see how # we might use CMake to replace GNU Make, NMAKE, and Xcodebuild in the @@ -41,7 +41,7 @@ project( ) # Some people say this defaults to "Release", but it's sometimes -# blank. +# blank. This file relies on it being set. if (CMAKE_BUILD_TYPE) message(VERBOSE "Build type ${CMAKE_BUILD_TYPE}") else () @@ -67,6 +67,8 @@ endif () # FIXME: How to override detection? +# TODO: Test with cross-compilation. + file(READ code/mpstd.h FILE_MPSTD_H) string( REGEX REPLACE "\n[ \t]*#define[ \t]+MPS_PF_STRING[ \t]+" "\n#error " @@ -95,8 +97,9 @@ else () endif () -# FIXME: What about ANSI platform? -# FIXME: What about Freestanding platform? +# FIXME: What about ANSI platform? Override with PLATFORM_ANSI passed +# to CMake with ``-D``, as in mps.c. Same for freestanding platform +# (see branch/2023-02-13/freestanding). if (OS STREQUAL "xc") @@ -109,19 +112,19 @@ if (OS STREQUAL "xc") # CC = clang -arch i386 set(MPMPF - lockix.c - prmc${ARCH}.c - prmc${OS}.c - prmcxc${ARCH}.c - protix.c - prot${OS}.c - span.c - thxc.c - vmix.c + code/lockix.c + code/prmc${ARCH}.c + code/prmc${OS}.c + code/prmcxc${ARCH}.c + code/protix.c + code/prot${OS}.c + code/span.c + code/thxc.c + code/vmix.c ) - set(TESTLIB testlib.c) - set(TESTTHR testthrix.c) + set(TESTLIB code/testlib.c) + set(TESTTHR code/testthrix.c) # FIXME: Is this necessary on macOS? link_libraries(m) @@ -130,20 +133,20 @@ elseif (OS STREQUAL "li") # Lifted from lii3ll.gmk and lii6ll.gmk set(MPMPF - lockix.c - prmc${ARCH}.c - prmcix.c - prmc${OS}${ARCH}.c - protix.c - protsgix.c - pthrdext.c - span.c - thix.c - vmix.c + code/lockix.c + code/prmc${ARCH}.c + code/prmcix.c + code/prmc${OS}${ARCH}.c + code/protix.c + code/protsgix.c + code/pthrdext.c + code/span.c + code/thix.c + code/vmix.c ) - set(TESTLIB testlib.c) - set(TESTTHR testthrix.c) + set(TESTLIB code/testlib.c) + set(TESTTHR code/testthrix.c) link_libraries(m) @@ -151,8 +154,8 @@ elseif (OS STREQUAL "fr") # FIXME: Fill this in from fr*.gmk - set(TESTLIB testlib.c) - set(TESTTHR testthrix.c) + set(TESTLIB code/testlib.c) + set(TESTTHR code/testthrix.c) link_libraries(m) @@ -163,19 +166,19 @@ elseif (OS STREQUAL "w3") # FIXME: Untested set(MPMPF - lock${OS}.c - mpsi${OS}.c - prmc${ARCH}.c - prmc${OS}.c - prmc${OS}${ARCH}.c - prot${OS}.c - sp${OS}${ARCH}.c - th${OS}.c - vm${OS}.c + code/lock${OS}.c + code/mpsi${OS}.c + code/prmc${ARCH}.c + code/prmc${OS}.c + code/prmc${OS}${ARCH}.c + code/prot${OS}.c + code/sp${OS}${ARCH}.c + code/th${OS}.c + code/vm${OS}.c ) - set(TESTLIB testlib.c getoptl.c) - set(TESTTHR testthr${OS}.c) + set(TESTLIB code/testlib.c code/getoptl.c) + set(TESTTHR code/testthr${OS}.c) else () @@ -288,117 +291,105 @@ endif () # These values are defined here because they have no variation between # platforms. -set(AMC poolamc.c) -set(AMS poolams.c) -set(AWL poolawl.c) -set(LO poollo.c) -set(SNC poolsnc.c) -set(POOLN pooln.c) -set(MV2 poolmv2.c) -set(MVFF poolmvff.c) -set(FMTDY fmtdy.c fmtno.c) -set(FMTDYTST fmtdy.c fmtno.c fmtdytst.c) -set(FMTHETST fmthe.c fmtdy.c fmtno.c fmtdytst.c) -set(FMTSCM fmtscheme.c) -set(PLINTH mpsliban.c mpsioan.c) +set(AMC code/poolamc.c) +set(AMS code/poolams.c) +set(AWL code/poolawl.c) +set(LO code/poollo.c) +set(SNC code/poolsnc.c) +set(POOLN code/pooln.c) +set(MV2 code/poolmv2.c) +set(MVFF code/poolmvff.c) +set(FMTDY code/fmtdy.c code/fmtno.c) +set(FMTDYTST code/fmtdy.c code/fmtno.c code/fmtdytst.c) +set(FMTHETST code/fmthe.c code/fmtdy.c code/fmtno.c code/fmtdytst.c) +set(FMTSCM code/fmtscheme.c) +set(PLINTH code/mpsliban.c code/mpsioan.c) set(MPMCOMMON - abq.c - arena.c - arenacl.c - arenavm.c - arg.c - boot.c - bt.c - buffer.c - cbs.c - dbgpool.c - dbgpooli.c - event.c - failover.c - format.c - freelist.c - global.c - land.c - ld.c - locus.c - message.c - meter.c - mpm.c - mpsi.c - nailboard.c - policy.c - pool.c - poolabs.c - poolmfs.c - poolmrg.c - protocol.c - range.c - rangetree.c - ref.c - ring.c - root.c - sa.c - sac.c - scan.c - seg.c - shield.c - splay.c - ss.c - table.c - trace.c - traceanc.c - tract.c - tree.c - version.c - vm.c - walk.c + code/abq.c + code/arena.c + code/arenacl.c + code/arenavm.c + code/arg.c + code/boot.c + code/bt.c + code/buffer.c + code/cbs.c + code/dbgpool.c + code/dbgpooli.c + code/event.c + code/failover.c + code/format.c + code/freelist.c + code/global.c + code/land.c + code/ld.c + code/locus.c + code/message.c + code/meter.c + code/mpm.c + code/mpsi.c + code/nailboard.c + code/policy.c + code/pool.c + code/poolabs.c + code/poolmfs.c + code/poolmrg.c + code/protocol.c + code/range.c + code/rangetree.c + code/ref.c + code/ring.c + code/root.c + code/sa.c + code/sac.c + code/scan.c + code/seg.c + code/shield.c + code/splay.c + code/ss.c + code/table.c + code/trace.c + code/traceanc.c + code/tract.c + code/tree.c + code/version.c + code/vm.c + code/walk.c ) set(POOLS ${AMC} ${AMS} ${AWL} ${LO} ${MV2} ${MVFF} ${SNC}) set(MPM ${MPMCOMMON} ${MPMPF} ${POOLS} ${PLINTH}) -# FIXME: There's probably a better way to do this -list(TRANSFORM MPM PREPEND "code/") -list(TRANSFORM PLINTH PREPEND "code/") -list(TRANSFORM TESTLIB PREPEND "code/") -list(TRANSFORM FMTDYTST PREPEND "code/") -list(TRANSFORM TESTTHR PREPEND "code/") - - # Varieties # # MPS varieties (HOT, COOL, etc.) probably map to CMake "Build # Configurations" # . -# I'm just mapping Debug and Release for now. - -# Unset CMake's default flags -# message(VERBOSE "CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}") -# message(VERBOSE "CMAKE_C_FLAGS_DEBUG = ${CMAKE_C_FLAGS_DEBUG}") -# message(VERBOSE "CMAKE_C_FLAGS_RELEASE = ${CMAKE_C_FLAGS_RELEASE}") -set(CMAKE_C_FLAGS_DEBUG "") -set(CMAKE_C_FLAGS_RELEASE "") -set(CMAKE_C_FLAGS "") +# +# FIXME: I'm just mapping variety.cool (Debug) and variety.hot +# (Release) for now, but we need to add variety.rash at least for +# automatic comparison with hot. It would be good to see if +# variety.cold builds and runs too. add_compile_definitions( $<$:CONFIG_VAR_COOL> $<$:CONFIG_VAR_HOT> ) - -add_compile_options( - "$<$:${CFLAGSDEBUG}>" - "$<$:${CFLAGSOPT}>" - ${CFLAGSCOMPILER} - # FIXME: CFLAGSCOMPILERSTRICT or LAX -) +# Override CMake's default flags because we specify all flags. +message(VERBOSE "Setting CMAKE_C_FLAGS from ${CMAKE_C_FLAGS} to ${CFLAGSCOMPILER}") +list(JOIN CFLAGSCOMPILER " " CMAKE_C_FLAGS) +message(VERBOSE "Setting CMAKE_C_FLAGS_DEBUG from ${CMAKE_C_FLAGS_DEBUG} to ${CFLAGSDEBUG}") +list(JOIN CFLAGSDEBUG " " CMAKE_C_FLAGS_DEBUG) +message(VERBOSE "Setting CMAKE_C_FLAGS_RELEASE from ${CMAKE_C_FLAGS_RELEASE} to ${CFLAGSOPT}") +list(JOIN CFLAGSOPT " " CMAKE_C_FLAGS_RELEASE) # Targets # # Just using gcbench as an example target for now. -#add_library(mps OBJECT mps.c) +#add_library(mps OBJECT code/mps.c) #target_compile_options(mps PRIVATE ${CFLAGSCOMPILERSTRICT}) add_library(mps STATIC @@ -427,6 +418,7 @@ target_compile_options(gcbench PRIVATE ${CFLAGSCOMPILERSTRICT}) include(CTest) add_executable(amcss code/amcss.c ${TESTLIB} ${FMTDYTST}) +# FIXME: target_compile_options(amcss PRIVATE ${CFLAGSCOMPILERLAX}) etc. ? target_link_libraries(amcss PRIVATE mps) add_test(NAME amcss COMMAND amcss)