Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when USER_HEADER is not found #1264

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions make/program
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,21 @@ $(STAN_TARGETS) : %$(EXE) : $(STAN)src/stan/model/model_header$(STAN_FLAGS)_$(CX
endif
endif

ifneq ($(findstring allow_undefined,$(STANCFLAGS))$(findstring allow-undefined,$(STANCFLAGS)),)
ifneq ($(findstring allow-undefined,$(STANCFLAGS)),)

USER_HEADER ?= $(dir $(STAN_TARGETS))user_header.hpp
$(STAN_TARGETS) : CXXFLAGS_PROGRAM += -include $(USER_HEADER)
##
# Give a better error message if the USER_HEADER is not found
##
$(USER_HEADER):
@echo 'ERROR: Missing user header.'
@echo 'Because --allow-undefined is set, we need a C++ header file to include.'
@echo 'We tried to find the user header at:'
@echo ' $(USER_HEADER)'
@echo ''
@echo 'You can also set the USER_HEADER variable to the path of your C++ file.'
@exit 1
endif

##
Expand All @@ -55,7 +68,7 @@ ifeq ($(KEEP_OBJECT), true)
.PRECIOUS: %.o
endif

%.o : %.hpp
%.o : %.hpp $(USER_HEADER)
@echo ''
@echo '--- Compiling C++ code ---'
$(COMPILE.cpp) $(CXXFLAGS_PROGRAM) -x c++ -o $(subst \,/,$*).o $(subst \,/,$<)
Expand Down
1 change: 0 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ MATH ?= $(STAN)lib/stan_math/
RAPIDJSON ?= $(STAN)lib/rapidjson_1.1.0/
CLI11 ?= lib/CLI11-1.9.1/
INC_FIRST ?= -I src -I $(STAN)src -I $(RAPIDJSON) -I $(CLI11)
USER_HEADER ?= $(dir $<)user_header.hpp

## Detect operating system
ifneq ($(OS),Windows_NT)
Expand Down