Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Check for json with pkg_config
  • Loading branch information
d3dsf committed Sep 3, 2026
commit fa178a8895e08555d01863ffacfac4b4fc560f0e
22 changes: 16 additions & 6 deletions config/config.NERSC.gfortran
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Test whether necessary variables are set
GR_ROOT ?= /global/project/projectdirs/atom/atom-install-cori/solps-libs/lib_gfortran
GLI_HOME ?= /global/project/projectdirs/atom/atom-install-cori/solps-libs/lib_gfortran
SOLPSLIB ?= ${SOLPSTOP}/lib/${HOST_NAME}.${COMPILER}
GR_ROOT ?= ${SOLPSLIB}/gr
GLI_HOME ?= ${SOLPSLIB}/gli/src/gks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as per the comment below. SOLPSLIB will only exist if one is compiling inside a SOLPS environment. But GR and GLI are separate module that come form outside SOLPS-ITER, so they have their own workspace and that is where one should expect to find the libraries.

LD_GR ?= -L${GR_ROOT} -lgr
LD_GKS ?= -L${GLI_HOME} -lgks
LD_NAG ?= -L${SOLPSLIB} -lblas -llapack
LD_GKS ?= -L${SOLPSLIB}/gli/src/gks -lgks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above.


CPP = cpp -traditional
CPP = CC -traditional
FC = ftn
CC = cc

Expand All @@ -27,6 +25,18 @@ LDLIBS =

INCMOD = -I

# Build with JSON if present
ifeq ($(shell `pkg-config --exists json-fortran`; echo $$?),0)
JSON_INC ?= $(shell pkg-config json-fortran --cflags)
LD_JSON ?= $(shell pkg-config json-fortran --libs)
else
Comment thread
hrdoktorx marked this conversation as resolved.
Resolved
ifndef SOLPS_CPP
DEFINES += -DNO_JSON
endif

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ifndef SOLPS_CPP basically means "if we are compiling a standa-lone Eirene instance outside the SOLPS environment". There is no reason why it could not also use JSON.

endif

INCLUDE += ${JSON_INC}

#!!!Local Variables:
#!!! mode: Makefile
#!!! End:
23 changes: 21 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,26 @@ set(EIRENE_POSTFIX "" CACHE STRING "EIRENE output names postfix")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# This is a bit convoluted but allows for some user error in the JSON library location
# First check for user defined paths
if(LibJSON)
# Ask pkg-config first, unless the user has pointed at a specific installation
if(NOT LibJSON AND NOT DEFINED ENV{JSONF_LIB_DIR})
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_JSONFORTRAN QUIET json-fortran)
if(PC_JSONFORTRAN_FOUND)
find_library(JSONFORTRAN_LIBRARY NAMES ${PC_JSONFORTRAN_LIBRARIES}
HINTS ${PC_JSONFORTRAN_LIBRARY_DIRS} NO_DEFAULT_PATH)
endif()
endif()
endif()

if(PC_JSONFORTRAN_FOUND AND JSONFORTRAN_LIBRARY AND EXISTS "${PC_JSONFORTRAN_INCLUDE_DIRS}/json_module.mod")
message(STATUS " Found LibJSON with pkg-config. Version: " ${PC_JSONFORTRAN_VERSION})
set(LibJSON ${JSONFORTRAN_LIBRARY})
set(jsonfortran_INCLUDE_DIRS ${PC_JSONFORTRAN_INCLUDE_DIRS})
set(jsonfortran_FOUND TRUE)
message(STATUS " LibJSON: " ${LibJSON})
# Then check for user defined paths
elseif(LibJSON)
message(STATUS " Searching for user defined LibJSON. Found " ${LibJSON} )
if(IS_DIRECTORY ${LibJSON})
if((EXISTS "${LibJSON}/libjsonfortran.a" OR EXISTS "${LibJSON}/libjsonfortran.so"))
Expand All @@ -78,7 +97,7 @@ if(LibJSON)
set(LibJSON "${LibJSON}/libjsonfortran.a")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably split this up so that an existing shared object then leads to forcing the linking against the statically linked library, which conda does not provide.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

set(jsonfortran_FOUND TRUE)
else()
message(WARNING "JSON Library libjsonfortran.a NOT found at " ${LibJSON})
message(WARNING "JSON Library ljsonfortran NOT found at " ${LibJSON})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the name here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I am linking against ljsonfortran.so (potentially)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the drop of the extension. But you were only looking for the existence of libjsonfortran.a or libjsonfortran.so, not ljsonfortran.

endif()
else() # Assume the library is included in the path
if(EXISTS ${LibJSON})
Expand Down