Skip to content

Commit ac98d3b

Browse files
authored
build: enhance FYPP error messaging and add defensive checks in stdlib.cmake (#1137)
* build: enhance fypp error messaging for better onboarding * address reviewer feedback: simplify error message and fix logic typo * Final changes * Suggested Changes * updated
1 parent 496ca5e commit ac98d3b

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ cmake_minimum_required(VERSION 3.14.0)
44
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/config/DefaultFlags.cmake)
55

66
project(fortran_stdlib
7-
LANGUAGES Fortran C
8-
DESCRIPTION "Community driven and agreed upon de facto standard library for Fortran"
7+
LANGUAGES Fortran C
8+
DESCRIPTION "Community driven and agreed upon de facto standard library for Fortran"
99
)
1010

1111
# Read version from file
@@ -116,8 +116,19 @@ endif()
116116

117117
# --- find preprocessor
118118
find_program(FYPP fypp)
119-
if(NOT FYPP)
120-
message(FATAL_ERROR "Preprocessor fypp not found! Please install fypp following the instructions in https://fypp.readthedocs.io/en/stable/fypp.html#installing")
119+
if(NOT FYPP OR "${FYPP}" MATCHES "NOTFOUND")
120+
message(FATAL_ERROR
121+
"\n [stdlib Build Error]: Preprocessor 'fypp' not found!\n"
122+
" ------------------------------------------------------------------------\n"
123+
" The fypp preprocessor is required to generate Fortran source from templates.\n\n"
124+
" Please install fypp following the instructions at https://github.com/aradi/fypp\n\n"
125+
" To diagnose your installation, please run the following in your terminal:\n"
126+
" Windows: 'where fypp' and 'where python'\n"
127+
" Linux/macOS: 'which fypp' and 'which python'\n\n"
128+
" Ensure the executable is in your PATH or set it manually during configuration:\n"
129+
" cmake -B build -DFYPP_EXECUTABLE=/path/to/fypp\n"
130+
" ------------------------------------------------------------------------\n"
131+
)
121132
endif()
122133

123134
# Custom preprocessor flags
@@ -156,4 +167,4 @@ install(EXPORT ${PROJECT_NAME}-targets
156167
)
157168

158169
# Export a pkg-config file
159-
include(${PROJECT_SOURCE_DIR}/config/export_pc.cmake)
170+
include(${PROJECT_SOURCE_DIR}/config/export_pc.cmake)

cmake/stdlib.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#
1111
function(preprocess preproc preprocopts srcext trgext srcfiles trgfiles)
1212

13+
# Defensive check: Ensure the preprocessor path is valid before defining custom commands.
14+
# This prevents "empty command" errors during the build phase.
15+
if(NOT preproc OR "${preproc}" MATCHES "NOTFOUND")
16+
message(FATAL_ERROR "preprocess function called with invalid preprocessor path: '${preproc}'")
17+
endif()
18+
1319
set(_trgfiles)
1420
foreach(srcfile IN LISTS srcfiles)
1521
get_filename_component(filename ${srcfile} NAME)
@@ -87,8 +93,8 @@ function(configure_stdlib_target target_name regular_sources_var fypp_files_var
8793
endif()
8894

8995
set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/mod_files/${target_name}/)
90-
#set(INSTALL_MOD_DIR "${CMAKE_INSTALL_MODULEDIR}/${target_name}")
9196
set(INSTALL_MOD_DIR "${CMAKE_INSTALL_MODULEDIR}")
97+
9298
# We need the module directory before we finish the configure stage since the
9399
# build interface might resolve before the module directory is generated by CMake
94100
if(NOT EXISTS "${LIB_MOD_DIR}")
@@ -115,7 +121,7 @@ endfunction()
115121
# Determine if a module will be compiled
116122
#
117123
# Defines a CMake function that creates an ON/OFF option for a given stdlib module,
118-
#sets a compile definition accordingly, and prints its enabled/disabled status.
124+
# sets a compile definition accordingly, and prints its enabled/disabled status.
119125
#
120126
# Args:
121127
# module [in]: Name of the module to be compiled
@@ -133,4 +139,4 @@ function(check_modular module)
133139
add_compile_definitions(STDLIB_${umodule}=0)
134140
endif()
135141

136-
endfunction()
142+
endfunction()

0 commit comments

Comments
 (0)