Skip to content

Commit

Permalink
Merge pull request #1264 from stan-dev/makefiles/user-header-improvem…
Browse files Browse the repository at this point in the history
…ents

Improve error message when USER_HEADER is not found
  • Loading branch information
WardBrian authored May 3, 2024
2 parents 7bd4f98 + dc9ac3d commit 58e171d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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

0 comments on commit 58e171d

Please sign in to comment.