From 18bfb1521452e84e1b2e6e23d509bfe67102d633 Mon Sep 17 00:00:00 2001 From: Marco Antonio Jaguaribe Costa Date: Mon, 16 Jan 2023 23:33:36 -0300 Subject: [PATCH 1/3] Use a modifiable user-preset sample for VS 2022/2019 Customizing a repo-tracked preset file doesn't work: Type in your gamedir for debugging, or toggle verbose mode for the build, or configure Chinese UB MapEditor: you now have an unstaged `CMakePresets.json` change in your working directory. very annoying. Also, Visual Studio 2022's preset support has a bug: if you have a `CMakePresets.json` file, no matter in which file (user or repo) the preset you have selected is defined, if you click "Manage Configurations..." it will always open `CMakePresets.json` for editing, setting the user up for failure and editing the commited-to-repository file. Having just the `CMakeUserPresets.json` file also sidesteps another poor Visual Studio 2022 decision: hiding in Folder View files that are .gitignore'd (like `CMakeUserPresets.json`). In the absence of a `CMakePresets.json` file, selecting "Manage Configurations..." will open the right file for editing. The workflow is then: Copy `CMakeUserPresets.json.sample` into `CMakeUserPresets.json` _once_, then customize that to your heart's content without git bothering you and accidentally adding an unwanted change to a patch. Or make your own. --- .gitignore | 11 +++++---- CMakePresets.json | 44 ----------------------------------- CMakeUserPresetsTEMPLATE.json | 44 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 48 deletions(-) delete mode 100644 CMakePresets.json create mode 100644 CMakeUserPresetsTEMPLATE.json diff --git a/.gitignore b/.gitignore index 933e1b8c5b..854ddcef04 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ +# CLion +.idea/ +cmake-build-*/ + +# Visual Studio 2022 +.vs/ build/ lib/ -.vs/ -.idea/ +out/ CMakeSettings.json CMakeUserPresets.json -cmake-build-* -out/ \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json deleted file mode 100644 index 89c13bbc7d..0000000000 --- a/CMakePresets.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "version": 3, - "configurePresets": [ - { - "name": "default", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/out/build/${presetName}", - "cacheVariables": { - "Languages": "CHINESE;DUTCH;ENGLISH;FRENCH;GERMAN;ITALIAN;POLISH;RUSSIAN", - "Applications": "JA2;JA2MAPEDITOR;JA2UB;JA2UBMAPEDITOR", - "CMAKE_RUNTIME_OUTPUT_DIRECTORY": "." - }, - "architecture": { - "value": "x86", - "strategy": "external" - } - }, - { - "name": "Debug", - "displayName": "Debug", - "inherits": "default", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "RelWithDebInfo", - "displayName": "RelWithDebInfo", - "inherits": "default", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo" - } - }, - { - "name": "Release", - "displayName": "Release", - "inherits": "default", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" - } - } - ] -} \ No newline at end of file diff --git a/CMakeUserPresetsTEMPLATE.json b/CMakeUserPresetsTEMPLATE.json new file mode 100644 index 0000000000..2da6b5ca2a --- /dev/null +++ b/CMakeUserPresetsTEMPLATE.json @@ -0,0 +1,44 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "__userBase", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + // Valid choices: ENGLISH;GERMAN;FRENCH;ITALIAN;POLISH;DUTCH;RUSSIAN;CHINESE. If empty (""), will configure all. + "Languages": "ENGLISH", + // Valid choices: JA2;JA2MAPEDITOR;JA2UB;JA2UBMAPEDITOR. If empty (""), will configure all. + "Applications": "JA2", + // For debugging: enter your desired gamedir. + "CMAKE_RUNTIME_OUTPUT_DIRECTORY": "C:/Ja2" + }, + "architecture": { + "value": "x86", + "strategy": "external" + } + }, + { + "name": "1dot13 RelWithDebInfo", + "inherits": "__userBase", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "1dot13 Release", + "inherits": "__userBase", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "1dot13 Debug", + "inherits": "__userBase", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + } + ] +} From bd2821261a0000688dfa0172bb77e72d8c973c41 Mon Sep 17 00:00:00 2001 From: CptMoore <39010654+CptMoore@users.noreply.github.com> Date: Sat, 21 Jan 2023 12:31:03 +0100 Subject: [PATCH 2/3] Added auto-copy of profile template. --- CMakeLists.txt | 9 +++++++++ ...resetsTEMPLATE.json => CMakeUserPresets-TEMPLATE.json | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) rename CMakeUserPresetsTEMPLATE.json => CMakeUserPresets-TEMPLATE.json (89%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 166dd9d584..7a94cdbc77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,15 @@ cmake_minimum_required(VERSION 3.20) project(ja2) +set(ProfilePath "${CMAKE_SOURCE_DIR}/CMakePresets.json") +set(UserProfilePath "${CMAKE_SOURCE_DIR}/CMakeUserPresets.json") +if(NOT DEFINED Languages AND NOT DEFINED Applications AND NOT EXISTS "${ProfilePath}" AND NOT EXISTS "${UserProfilePath}") + set(UserProfileTemplatePath "${CMAKE_SOURCE_DIR}/CMakeUserPresets-TEMPLATE.json") + file(READ "${UserProfileTemplatePath}" UserProfileTemplatContent) + file(WRITE "${UserProfilePath}" "${UserProfileTemplatContent}") + message( FATAL_ERROR "No existing profile was found, copied a profile template as CMakeUserProfile.json . Writing an error to trick Visual Studio into reloading the new profile automatically." ) +endif() + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/CMakeUserPresetsTEMPLATE.json b/CMakeUserPresets-TEMPLATE.json similarity index 89% rename from CMakeUserPresetsTEMPLATE.json rename to CMakeUserPresets-TEMPLATE.json index 2da6b5ca2a..ffbc4788b0 100644 --- a/CMakeUserPresetsTEMPLATE.json +++ b/CMakeUserPresets-TEMPLATE.json @@ -11,8 +11,8 @@ "Languages": "ENGLISH", // Valid choices: JA2;JA2MAPEDITOR;JA2UB;JA2UBMAPEDITOR. If empty (""), will configure all. "Applications": "JA2", - // For debugging: enter your desired gamedir. - "CMAKE_RUNTIME_OUTPUT_DIRECTORY": "C:/Ja2" + // For debugging: enter your desired gamedir. e.g. C:/Games/JA2 + "CMAKE_RUNTIME_OUTPUT_DIRECTORY": "." }, "architecture": { "value": "x86", From a6b568be066c9566aa0d276735e2e31265b25c9e Mon Sep 17 00:00:00 2001 From: Marco Antonio Jaguaribe Costa Date: Sat, 21 Jan 2023 16:20:48 -0300 Subject: [PATCH 3/3] declutter things a bit move function out of root cmakelists.txt file move user preset template to a presets directory this is horrible and I hate it --- .gitignore | 2 +- CMakeLists.txt | 10 ++-------- cmake/CopyUserPresetTemplate.cmake | 11 +++++++++++ .../presets/CMakeUserPresets.json | 0 4 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 cmake/CopyUserPresetTemplate.cmake rename CMakeUserPresets-TEMPLATE.json => cmake/presets/CMakeUserPresets.json (100%) diff --git a/.gitignore b/.gitignore index 854ddcef04..22d2271de1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ build/ lib/ out/ CMakeSettings.json -CMakeUserPresets.json +/CMakeUserPresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a94cdbc77..8b95bfbc0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,14 +2,8 @@ cmake_minimum_required(VERSION 3.20) project(ja2) -set(ProfilePath "${CMAKE_SOURCE_DIR}/CMakePresets.json") -set(UserProfilePath "${CMAKE_SOURCE_DIR}/CMakeUserPresets.json") -if(NOT DEFINED Languages AND NOT DEFINED Applications AND NOT EXISTS "${ProfilePath}" AND NOT EXISTS "${UserProfilePath}") - set(UserProfileTemplatePath "${CMAKE_SOURCE_DIR}/CMakeUserPresets-TEMPLATE.json") - file(READ "${UserProfileTemplatePath}" UserProfileTemplatContent) - file(WRITE "${UserProfilePath}" "${UserProfileTemplatContent}") - message( FATAL_ERROR "No existing profile was found, copied a profile template as CMakeUserProfile.json . Writing an error to trick Visual Studio into reloading the new profile automatically." ) -endif() +include(cmake/CopyUserPresetTemplate.cmake) +CopyUserPresetTemplate() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/cmake/CopyUserPresetTemplate.cmake b/cmake/CopyUserPresetTemplate.cmake new file mode 100644 index 0000000000..484f7ec801 --- /dev/null +++ b/cmake/CopyUserPresetTemplate.cmake @@ -0,0 +1,11 @@ +function(CopyUserPresetTemplate) + if( + NOT DEFINED Languages AND + NOT DEFINED Applications AND + NOT EXISTS "${CMAKE_SOURCE_DIR}/CMakePresets.json" AND + NOT EXISTS "${CMAKE_SOURCE_DIR}/CMakeUserPresets.json" + ) + file(COPY "${CMAKE_SOURCE_DIR}/cmake/presets/CMakeUserPresets.json" DESTINATION "${CMAKE_SOURCE_DIR}") + message(FATAL_ERROR "No existing preset was found, copied a preset template to ${CMAKE_SOURCE_DIR}/CMakeUserPresets.json.") + endif() +endfunction() diff --git a/CMakeUserPresets-TEMPLATE.json b/cmake/presets/CMakeUserPresets.json similarity index 100% rename from CMakeUserPresets-TEMPLATE.json rename to cmake/presets/CMakeUserPresets.json