Skip to content

Commit

Permalink
use shared_lib
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Feb 15, 2024
1 parent 69cd9ee commit f668254
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ src/externals/mct/config.status
*.py[cod]
build
bld
*.egg-info
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ This section shows you how to install eCLM on your local machine. If you are a u

### Minimum system requirements

#### CentOS-8

* MPI 3.1
* netCDF-C 4.7.4
* netCDF-Fortran 4.5.2
Expand All @@ -23,6 +25,17 @@ This section shows you how to install eCLM on your local machine. If you are a u
- GCC 9.3.0
- Intel 19.1.2

#### Ubuntu-22.04

- `OpenMPI`: 4.1.2
- `netCDF-C`: 4.8.1
- `netCDF-Fortran`: 4.6.0
- `PnetCDF`: 1.12.1
- `CMake`: 3.22.1
- `gcc`: 11.4.0
- `mpicc`: 11.4.0


### Building eCLM

1. Configure CMake build options.
Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ INSTALL_DIR="eclm"
cmake -S src -B "$BUILD_DIR" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_C_COMPILER=mpicc \
-DCMAKE_Fortran_FLAGS="-fallow-argument-mismatch -fallow-invalid-boz" \
-DCMAKE_Fortran_FLAGS="-fallow-argument-mismatch -fallow-invalid-boz -fPIC" \
-DCMAKE_Fortran_COMPILER=mpifort

cd bld
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required (VERSION 3.16.3)
project (eCLM LANGUAGES C Fortran)

set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fPIC -shared")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -shared")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -shared")

if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
Expand Down
5 changes: 3 additions & 2 deletions src/clm5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
project (clm LANGUAGES Fortran)

add_library(${PROJECT_NAME} STATIC)
# add_library(${PROJECT_NAME} STATIC)
add_library(${PROJECT_NAME} SHARED)

target_compile_definitions(${PROJECT_NAME} PRIVATE NDEBUG)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
Expand Down Expand Up @@ -324,4 +325,4 @@ if(LAPACK_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE LAPACK::LAPACK)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE csm_share)
install (TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
3 changes: 2 additions & 1 deletion src/csm_share/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
project (csm_share LANGUAGES C Fortran)

add_library(${PROJECT_NAME} STATIC)
# add_library(${PROJECT_NAME} STATIC)
add_library(${PROJECT_NAME} SHARED)

# TODO: NUM_COMP_INST_<COMP> should be adjusted for ensemble runs. See the ff. for more info:
# https://esmci.github.io/cime/versions/cesm2.2/html/users_guide/multi-instance.html
Expand Down
4 changes: 2 additions & 2 deletions src/datm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project (datm LANGUAGES Fortran)

add_library(${PROJECT_NAME} STATIC)
add_library(${PROJECT_NAME} SHARED)

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
Expand All @@ -12,4 +12,4 @@ target_sources(${PROJECT_NAME}
atm_comp_mct.F90
)
target_link_libraries(${PROJECT_NAME} PRIVATE csm_share)
install (TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
12 changes: 6 additions & 6 deletions src/externals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ file(MAKE_DIRECTORY ${GPTL_BLD_DIR}/include ${GPTL_BLD_DIR}/lib)
set(GPTL_MACROS_FILE ${GPTL_BLD_DIR}/Macros.make)
file(WRITE ${GPTL_MACROS_FILE} " MPICC := ${CMAKE_C_COMPILER}\n")
file(APPEND ${GPTL_MACROS_FILE} " MPIFC := ${CMAKE_Fortran_COMPILER}\n")
file(APPEND ${GPTL_MACROS_FILE} " CLAGS := ${CMAKE_C_FLAGS}\n")
file(APPEND ${GPTL_MACROS_FILE} " FFLAGS := ${CMAKE_Fortran_FLAGS}\n")
file(APPEND ${GPTL_MACROS_FILE} " CLAGS := ${CMAKE_C_FLAGS} -fPIC -shared\n")
file(APPEND ${GPTL_MACROS_FILE} " FFLAGS := ${CMAKE_Fortran_FLAGS} -fPIC -shared\n")
file(APPEND ${GPTL_MACROS_FILE} "CPPDEFS := -DFORTRANUNDERSCORE\n")

ExternalProject_Add(gptl_external
Expand All @@ -26,15 +26,15 @@ ExternalProject_Add(gptl_external
SHAREDPATH=${GPTL_BLD_DIR}
INSTALL_COMMAND ""
BUILD_ALWAYS YES
BUILD_BYPRODUCTS ${GPTL_BLD_DIR}/lib/libgptl.a
BUILD_BYPRODUCTS ${GPTL_BLD_DIR}/lib/libgptl.so
)

add_library(gptl INTERFACE IMPORTED GLOBAL)
target_include_directories(gptl INTERFACE ${GPTL_BLD_DIR}/include)
target_link_directories(gptl INTERFACE ${GPTL_BLD_DIR}/lib)
target_link_libraries(gptl INTERFACE libgptl.a)
target_link_libraries(gptl INTERFACE libgptl.so)
add_dependencies(gptl gptl_external)
install (FILES ${GPTL_BLD_DIR}/lib/libgptl.a TYPE LIB)
install (FILES ${GPTL_BLD_DIR}/lib/libgptl.so TYPE LIB)


# ===========
Expand Down Expand Up @@ -75,4 +75,4 @@ endif()
# ===========
# PIO
# ===========
add_subdirectory(pio1)
add_subdirectory(pio1)
2 changes: 1 addition & 1 deletion src/externals/gptl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ SET(SRCS_C GPTLget_memusage.c
SET(SRCS_F90 perf_mod.F90
perf_utils.F90)

ADD_LIBRARY(timing ${SRCS_F90} ${SRCS_C})
ADD_LIBRARY(timing SHARED ${SRCS_F90} ${SRCS_C})
8 changes: 5 additions & 3 deletions src/externals/gptl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ OBJS = gptl.o GPTLutil.o GPTLget_memusage.o GPTLprint_memusage.o \
AR ?= ar
ARFLAGS ?= ruv

libgptl.a: $(OBJS)
libgptl.so: $(OBJS)
$(AR) $(ARFLAGS) $@ $(OBJS)


CFLAGS=-fPIC -shared
FFLAGS=-fPIC -shared

.c.o:
$(CC) -c $(INCLDIR) $(INCS) $(CFLAGS) $(CPPDEFS) $<
Expand All @@ -69,10 +71,10 @@ clean:
$(RM) -f *.f *.f90 *.d *.$(MOD_SUFFIX) $(OBJS)


install: libgptl.a
install: libgptl.so
cp -p $(GPTL_DIR)/gptl.h $(SHAREDPATH)/include
cp -p *.$(MOD_SUFFIX) $(SHAREDPATH)/include
cp -p libgptl.a $(SHAREDPATH)/lib
cp -p libgptl.so $(SHAREDPATH)/lib


perf_mod.o: perf_utils.o
Expand Down
1 change: 1 addition & 0 deletions src/externals/mct/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ autom4te.cache
*.o
*.mod
lib*.a
lib*.so
data
2 changes: 1 addition & 1 deletion src/externals/mct/benchmarks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ clean:

# DEPENDENCIES:

$(OBJS_ALL): $(MCTPATH)/libmct.a
$(OBJS_ALL): $(MCTPATH)/libmct.so



Expand Down
6 changes: 3 additions & 3 deletions src/externals/mct/configure
Original file line number Diff line number Diff line change
Expand Up @@ -5482,7 +5482,7 @@ elif echo $ac_fc_version_output | grep -i sx >/dev/null 2>&1; then
fi

# Test to see if fortran compiler supports the flag
# -fallow-argument-mismatch flag introduced in gfortran 10.
# -fallow-argument-mismatch -shared -fPIC flag introduced in gfortran 10.
#
# Also allow support for NAG compiler using the -mismatch_all flag.
#
Expand All @@ -5496,14 +5496,14 @@ Program test
USE ISO_C_BINDING, ONLY: C_PTRDIFF_T
End Program
EOF
doit='$FC -c ${FCFLAGS} ${FCFLAGS_f90} -fallow-argument-mismatch conftest.f90'
doit='$FC -c ${FCFLAGS} ${FCFLAGS_f90} -fallow-argument-mismatch -shared -fPIC conftest.f90'
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$doit\""; } >&5
(eval $doit) 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
nf_allow_mismatch=yes
FCFLAGS="${FCFLAGS} -fallow-argument-mismatch"
FCFLAGS="${FCFLAGS} -fallow-argument-mismatch -shared -fPIC "
else
nf_allow_mismatch=no
fi
Expand Down
6 changes: 3 additions & 3 deletions src/externals/mct/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ elif echo $ac_fc_version_output | grep -i sx >/dev/null 2>&1; then
fi

# Test to see if fortran compiler supports the flag
# -fallow-argument-mismatch flag introduced in gfortran 10.
# -fallow-argument-mismatch -shared -fPIC flag introduced in gfortran 10.
#
# Also allow support for NAG compiler using the -mismatch_all flag.
#
Expand All @@ -472,10 +472,10 @@ Program test
USE ISO_C_BINDING, ONLY: C_PTRDIFF_T
End Program
EOF
doit='$FC -c ${FCFLAGS} ${FCFLAGS_f90} -fallow-argument-mismatch conftest.f90'
doit='$FC -c ${FCFLAGS} ${FCFLAGS_f90} -fallow-argument-mismatch -shared -fPIC conftest.f90'
if AC_TRY_EVAL(doit); then
nf_allow_mismatch=yes
FCFLAGS="${FCFLAGS} -fallow-argument-mismatch"
FCFLAGS="${FCFLAGS} -fallow-argument-mismatch -shared -fPIC "
else
nf_allow_mismatch=no
fi
Expand Down
11 changes: 5 additions & 6 deletions src/externals/mct/mct/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ OBJS_ALL = $(SRCS_F90:.F90=.o)
include ../Makefile.conf

# TARGETS
all: lib$(MODULE).so

all: lib$(MODULE).a

lib$(MODULE).a: $(OBJS_ALL)
lib$(MODULE).so: $(OBJS_ALL)
$(RM) $@
$(AR) $@ $(OBJS_ALL)
$(RANLIB) $@
Expand All @@ -63,19 +62,19 @@ MCTFLAGS = $(INCFLAG)$(MPEUPATH)


clean:
${RM} *.o *.mod lib$(MODULE).a
${RM} *.o *.mod lib$(MODULE).so

install: all
$(MKINSTALLDIRS) $(libdir) $(includedir)
$(INSTALL) lib$(MODULE).a -m 644 $(libdir)
$(INSTALL) lib$(MODULE).so -m 644 $(libdir)
@for modfile in *.mod; do \
echo $(INSTALL) $$modfile -m 644 $(includedir); \
$(INSTALL) $$modfile -m 644 $(includedir); \
done

# DEPENDENCIES

$(OBJS_ALL): $(MPEUPATH)/libmpeu.a
$(OBJS_ALL): $(MPEUPATH)/libmpeu.so

m_AttrVect.o:
m_Accumulator.o: m_AttrVect.o
Expand Down
8 changes: 4 additions & 4 deletions src/externals/mct/mpeu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ OBJS_ALL = $(SRCS_C:.c=.o) \

# TARGETS

all: lib$(MODULE).a
all: lib$(MODULE).so

lib$(MODULE).a: $(OBJS_ALL)
lib$(MODULE).so: $(OBJS_ALL)
$(RM) $@
$(AR) $@ $(OBJS_ALL)
$(RANLIB) $@
Expand All @@ -71,11 +71,11 @@ MPEUFLAGS =
$(FC) -c $(INCPATH) $(FPPDEFS) $(FCFLAGS) $(MPEUFLAGS) $<

clean:
${RM} *.o *.mod lib$(MODULE).a
${RM} *.o *.mod lib$(MODULE).so

install: all
$(MKINSTALLDIRS) $(libdir) $(includedir)
$(INSTALL) lib$(MODULE).a -m 644 $(libdir)
$(INSTALL) lib$(MODULE).so -m 644 $(libdir)
@for modfile in *.mod; do \
echo $(INSTALL) $$modfile -m 644 $(includedir); \
$(INSTALL) $$modfile -m 644 $(includedir); \
Expand Down
6 changes: 3 additions & 3 deletions src/externals/mct/mpi-serial/configure
Original file line number Diff line number Diff line change
Expand Up @@ -5018,7 +5018,7 @@ elif echo $ac_fc_version_output | grep -i nag >/dev/null 2>&1; then
fi

# Test to see if fortran compiler supports the flag
# -fallow-argument-mismatch flag introduced in gfortran 10.
# -fallow-argument-mismatch -shared -fPIC flag introduced in gfortran 10.
#
# Also allow support for NAG compiler using the -mismatch_all flag.
#
Expand All @@ -5032,14 +5032,14 @@ Program test
USE ISO_C_BINDING, ONLY: C_PTRDIFF_T
End Program
EOF
doit='$FC -c ${FCFLAGS} ${FCFLAGS_f90} -fallow-argument-mismatch conftest.f90'
doit='$FC -c ${FCFLAGS} ${FCFLAGS_f90} -fallow-argument-mismatch -shared -fPIC conftest.f90'
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$doit\""; } >&5
(eval $doit) 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
nf_allow_mismatch=yes
FCFLAGS="${FCFLAGS} -fallow-argument-mismatch"
FCFLAGS="${FCFLAGS} -fallow-argument-mismatch -shared -fPIC "
else
nf_allow_mismatch=no
fi
Expand Down
6 changes: 3 additions & 3 deletions src/externals/mct/mpi-serial/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ elif echo $ac_fc_version_output | grep -i nag >/dev/null 2>&1; then
fi

# Test to see if fortran compiler supports the flag
# -fallow-argument-mismatch flag introduced in gfortran 10.
# -fallow-argument-mismatch -shared -fPIC flag introduced in gfortran 10.
#
# Also allow support for NAG compiler using the -mismatch_all flag.
#
Expand All @@ -98,10 +98,10 @@ Program test
USE ISO_C_BINDING, ONLY: C_PTRDIFF_T
End Program
EOF
doit='$FC -c ${FCFLAGS} ${FCFLAGS_f90} -fallow-argument-mismatch conftest.f90'
doit='$FC -c ${FCFLAGS} ${FCFLAGS_f90} -fallow-argument-mismatch -shared -fPIC conftest.f90'
if AC_TRY_EVAL(doit); then
nf_allow_mismatch=yes
FCFLAGS="${FCFLAGS} -fallow-argument-mismatch"
FCFLAGS="${FCFLAGS} -fallow-argument-mismatch -shared -fPIC "
else
nf_allow_mismatch=no
fi
Expand Down
4 changes: 2 additions & 2 deletions src/externals/pio1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project(pio C Fortran)
add_library(${PROJECT_NAME} STATIC)
add_library(${PROJECT_NAME} SHARED)

find_file(TESTFILE NAMES TryCSizeOf.f90 PATHS ${CMAKE_MODULE_PATH} NO_DEFAULT_PATH)
get_filename_component(TESTFILEPATH ${TESTFILE} PATH)
Expand Down Expand Up @@ -153,4 +153,4 @@ endforeach()

target_sources(${PROJECT_NAME} PRIVATE ${SRCS_F90} ${SRCS_C} ${TEMPSRCF90})

install (TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
4 changes: 2 additions & 2 deletions src/mosart/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project (mosart LANGUAGES Fortran)

add_library(${PROJECT_NAME} STATIC)
add_library(${PROJECT_NAME} SHARED)

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
Expand All @@ -23,4 +23,4 @@ target_sources(${PROJECT_NAME} PRIVATE
)

target_link_libraries(${PROJECT_NAME} PRIVATE csm_share)
install (TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

0 comments on commit f668254

Please sign in to comment.