Skip to content

Commit a4670d0

Browse files
committed
Improve setup instructions and input handling - WIP
Updated README and setup.cmake to clarify template file generation steps and improve user prompts for input. Project directory is now created in the current working directory, and setup messages better reflect the workflow for generating and regenerating template files.
1 parent f13bae3 commit a4670d0

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,17 @@ After setup completes:
7373

7474
```bash
7575
cd my-library
76+
77+
# Generate template files (CMakePresets.json, CI workflows, etc.)
78+
cmake -B build -DCPP_LIBRARY_FORCE_INIT=ON
79+
80+
# Now you can use the presets
7681
cmake --preset=test
7782
cmake --build --preset=test
7883
ctest --preset=test
7984
```
8085

81-
To regenerate template files (CMakePresets.json, CI workflows):
86+
To regenerate template files later:
8287

8388
```bash
8489
cmake --preset=init

setup.cmake

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,22 @@ endforeach()
8585

8686
# Helper function to prompt user for input
8787
function(prompt_user PROMPT_TEXT OUTPUT_VAR DEFAULT_VALUE)
88+
# Display prompt using CMake message (goes to console)
89+
execute_process(COMMAND ${CMAKE_COMMAND} -E echo_append "${PROMPT_TEXT}")
90+
8891
if(CMAKE_HOST_WIN32)
8992
# Windows: Use PowerShell for input
9093
execute_process(
91-
COMMAND powershell -NoProfile -Command "Write-Host -NoNewline '${PROMPT_TEXT}'; Read-Host"
94+
COMMAND powershell -NoProfile -Command "$Host.UI.ReadLine()"
9295
OUTPUT_VARIABLE USER_INPUT
9396
OUTPUT_STRIP_TRAILING_WHITESPACE
94-
ERROR_QUIET
9597
)
9698
else()
97-
# Unix: Use bash/sh for input
99+
# Unix: Read from stdin using shell
98100
execute_process(
99-
COMMAND bash -c "read -p '${PROMPT_TEXT}' input && echo -n \"$input\""
101+
COMMAND sh -c "read input && printf '%s' \"$input\""
100102
OUTPUT_VARIABLE USER_INPUT
101103
OUTPUT_STRIP_TRAILING_WHITESPACE
102-
ERROR_QUIET
103104
)
104105
endif()
105106

@@ -177,8 +178,23 @@ message("Include examples: ${ARG_EXAMPLES}")
177178
message("Include tests: ${ARG_TESTS}")
178179
message("")
179180

180-
# Create project directory
181-
set(PROJECT_DIR "${CMAKE_CURRENT_LIST_DIR}/${ARG_NAME}")
181+
# Get current working directory
182+
if(CMAKE_HOST_WIN32)
183+
execute_process(
184+
COMMAND powershell -NoProfile -Command "Get-Location | Select-Object -ExpandProperty Path"
185+
OUTPUT_VARIABLE CURRENT_DIR
186+
OUTPUT_STRIP_TRAILING_WHITESPACE
187+
)
188+
else()
189+
execute_process(
190+
COMMAND pwd
191+
OUTPUT_VARIABLE CURRENT_DIR
192+
OUTPUT_STRIP_TRAILING_WHITESPACE
193+
)
194+
endif()
195+
196+
# Create project directory in current working directory
197+
set(PROJECT_DIR "${CURRENT_DIR}/${ARG_NAME}")
182198
if(EXISTS "${PROJECT_DIR}")
183199
message(FATAL_ERROR "Directory '${ARG_NAME}' already exists!")
184200
endif()
@@ -365,10 +381,13 @@ message("\n=== Setup Complete! ===\n")
365381
message("Your library has been created in: ${ARG_NAME}/")
366382
message("\nNext steps:")
367383
message(" cd ${ARG_NAME}")
384+
message("\n # Generate template files (CMakePresets.json, CI workflows, etc.)")
385+
message(" cmake -B build -DCPP_LIBRARY_FORCE_INIT=ON")
386+
message("\n # Now you can use the presets:")
368387
message(" cmake --preset=test")
369388
message(" cmake --build --preset=test")
370389
message(" ctest --preset=test")
371-
message("\nTo regenerate template files (CMakePresets.json, CI workflows):")
390+
message("\nTo regenerate template files later:")
372391
message(" cmake --preset=init")
373392
message(" cmake --build --preset=init")
374393
message("\nFor more information, visit: https://github.com/stlab/cpp-library")

0 commit comments

Comments
 (0)