From d9d6338c8177e9fd676d0c0afb7e5689119f9405 Mon Sep 17 00:00:00 2001 From: Matt Bolitho Date: Sun, 17 Nov 2024 19:43:34 +0000 Subject: [PATCH] Adds initial CMake presets configuration (#2169) * Adds CMakeUserPresets.json to gitignore * Adds presets based on root CMakeLists * Adds build presets * Adds naive preset configuration detection * Adds self review changes * Uses NOT DEFINED for preset check --- .gitignore | 2 + enzyme/CMakeLists.txt | 10 ++-- enzyme/CMakePresets.json | 103 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 enzyme/CMakePresets.json diff --git a/.gitignore b/.gitignore index a3c2751a0f5c..5e7285d5f0af 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ enzyme/benchmarks/ReverseMode/*/*.exe enzyme/benchmarks/ReverseMode/*/results.txt enzyme/benchmarks/ReverseMode/*/results.json .cache +CMakeUserPresets.json +/out diff --git a/enzyme/CMakeLists.txt b/enzyme/CMakeLists.txt index 1f51afe2789d..2ba42e969ce8 100644 --- a/enzyme/CMakeLists.txt +++ b/enzyme/CMakeLists.txt @@ -17,11 +17,13 @@ add_definitions(-DENZYME_VERSION_PATCH=${ENZYME_PATCH_VERSION}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -SET(CMAKE_CXX_FLAGS "-Wall -fno-rtti ${CMAKE_CXX_FLAGS} -Werror=unused-variable -Werror=dangling-else -Werror=unused-but-set-variable -Werror=return-type -Werror=nonnull -Werror=unused-result -Werror=reorder -Werror=switch") -SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -ggdb") -SET(CMAKE_CXX_FLAGS_RELEASE "-O2") -SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb -fno-omit-frame-pointer") +if (NOT DEFINED ENZYME_CONFIGURED_WITH_PRESETS) + set(CMAKE_CXX_FLAGS "-Wall -fno-rtti ${CMAKE_CXX_FLAGS} -Werror=unused-variable -Werror=dangling-else -Werror=unused-but-set-variable -Werror=return-type -Werror=nonnull -Werror=unused-result -Werror=reorder -Werror=switch") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -ggdb") + set(CMAKE_CXX_FLAGS_RELEASE "-O2") + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb -fno-omit-frame-pointer") +endif() #SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -fno-omit-frame-pointer -fsanitize=address") #SET(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") diff --git a/enzyme/CMakePresets.json b/enzyme/CMakePresets.json new file mode 100644 index 000000000000..1a5ffa80c5d9 --- /dev/null +++ b/enzyme/CMakePresets.json @@ -0,0 +1,103 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "config-base", + "description": "Base configure preset.", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "CMAKE_CXX_STANDARD": "17", + "CMAKE_CXX_STANDARD_REQUIRED": "ON", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", + "ENZYME_CONFIGURED_WITH_PRESETS": "ON" + } + }, + { + "name": "config-base-linux", + "description": "Base configure preset for Linux.", + "inherits": "config-base", + "hidden": true, + "cacheVariables": { + "CMAKE_POSITION_INDEPENDENT_CODE": "ON" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "config-base-x64", + "description": "Base preset for x64 platforms.", + "hidden": true, + "architecture": { + "value": "x64", + "strategy": "external" + } + }, + { + "name": "x64-linux-clang", + "description": "Base preset for Linux development using Clang compilers.", + "hidden": true, + "inherits": [ + "config-base-x64", + "config-base-linux" + ], + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_CXX_FLAGS": "-Wall -fno-rtti -Werror=unused-variable -Werror=dangling-else -Werror=unused-but-set-variable -Werror=return-type -Werror=nonnull -Werror=unused-result -Werror=reorder -Werror=switch", + "CMAKE_CXX_FLAGS_DEBUG": "-O0 -g -ggdb -fno-omit-frame-pointer", + "CMAKE_CXX_FLAGS_RELEASE": "-O2", + "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-O2 -g -ggdb" + } + }, + { + "name": "x64-linux-clang-debug", + "displayName": "Clang x64 Linux Debug", + "inherits": "x64-linux-clang", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "x64-linux-clang-release", + "displayName": "Clang x64 Linux Release", + "inherits": "x64-linux-clang", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "x64-linux-clang-release-with-debug-info", + "displayName": "Clang x64 Linux Release with Debug Info", + "inherits": "x64-linux-clang", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + } + ], + "buildPresets": [ + { + "name": "x64-linux-clang-debug", + "displayName": "Clang x64 Linux Debug", + "description": "Builds the project using Clang on Linux in Debug configuration.", + "configurePreset": "x64-linux-clang-debug" + }, + { + "name": "x64-linux-clang-release", + "displayName": "Clang x64 Linux Release", + "description": "Builds the project using Clang on Linux in Release configuration.", + "configurePreset": "x64-linux-clang-release" + }, + { + "name": "x64-linux-clang-release-with-debug-info", + "displayName": "Clang x64 Linux Release with Debug Info", + "description": "Builds the project using Clang on Linux in Release configuration with debug info.", + "configurePreset": "x64-linux-clang-release-with-debug-info" + } + ] +}