Skip to content

Commit

Permalink
updated CMakelists.txt to use new sundials_install_examples macro w; …
Browse files Browse the repository at this point in the history
…new parse tuple macro; and adjusted example tuples accordingly
  • Loading branch information
shahbajsohal committed Jul 7, 2023
1 parent 4e84eec commit 21c6f9a
Showing 1 changed file with 44 additions and 69 deletions.
113 changes: 44 additions & 69 deletions examples/nvector/pthreads/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@

# Examples using SUNDIALS pthread nvector
set(nvector_pthreads_examples
"test_nvector_pthreads\;1000 1 0\;"
"test_nvector_pthreads\;1000 2 0\;"
"test_nvector_pthreads\;1000 4 0\;"
"test_nvector_pthreads\;10000 1 0\;"
"test_nvector_pthreads\;10000 2 0\;"
"test_nvector_pthreads\;10000 4 0\;"
"test_nvector_pthreads.c\; \"1000 1 0\" \; \"\" "
"test_nvector_pthreads.c\; \"1000 2 0\" \; \"\" "
"test_nvector_pthreads.c\; \"1000 4 0\" \; \"\" "
"test_nvector_pthreads.c\; \"10000 1 0\" \; \"\" "
"test_nvector_pthreads.c\; \"10000 2 0\" \; \"\" "
"test_nvector_pthreads.c\; \"10000 4 0\" \; \"\" "
)

# Dependencies for nvector examples
set(nvector_examples_dependencies
test_nvector
test_nvector.c
test_nvector.h
)
# Adding extra files
set(nvector_examples_files
../test_nvector.c
../test_nvector.h
)

# If building F2003 tests
if (BUILD_FORTRAN_MODULE_INTERFACE)
Expand All @@ -52,17 +58,19 @@ set(SUNDIALS_LIBS ${NVECS_LIB} ${EXE_EXTRA_LINK_LIBS})

# Add the build and install targets for each example
foreach(example_tuple ${nvector_pthreads_examples})

# parse the example tuple
list(GET example_tuple 0 example)
list(GET example_tuple 1 example_args)
list(GET example_tuple 2 example_type)

# parse the example tuple using sundials_parse_tuple macro
sundials_parse_tuple( nvector_pthreads_examples
FILENAME_VAR example
PARAMS_VAR example_args
TYPE_VAR example_type
)

# check if this example has already been added, only need to add
# example source files once for testing with different inputs
if(NOT TARGET ${example})
# example source files
add_executable(${example} ${example}.c)
add_executable(${example} ${example})

# link vector test utilties
target_link_libraries(${example} PRIVATE test_nvector_obj)
Expand All @@ -87,23 +95,17 @@ foreach(example_tuple ${nvector_pthreads_examples})
EXAMPLE_TYPE ${example_type}
NODIFF)

# install example source files
if(EXAMPLES_INSTALL)
install(FILES ${example}.c
../test_nvector.c
../test_nvector.h
DESTINATION ${EXAMPLES_INSTALL_PATH}/nvector/pthreads)
endif()

endforeach(example_tuple ${nvector_pthreads_examples})

# Add the build and install targets for each example
foreach(example_tuple ${nvector_pthreads_fortran_examples})

# parse the example tuple
list(GET example_tuple 0 example)
list(GET example_tuple 1 example_args)
list(GET example_tuple 2 example_type)
# parse the example tuple using sundials_parse_tuple macro
sundials_parse_tuple( nvector_openmp_fortran_examples
FILENAME_VAR example
PARAMS_VAR example_args
TYPE_VAR example_type
)

# check if this example has already been added, only need to add
# example source files once for testing with different inputs
Expand Down Expand Up @@ -136,51 +138,24 @@ foreach(example_tuple ${nvector_pthreads_fortran_examples})

endforeach(example_tuple ${nvector_pthreads_fortran_examples})

# create Makfile and CMakeLists.txt for examples
if(EXAMPLES_INSTALL)

# Install the README file
install(FILES DESTINATION ${EXAMPLES_INSTALL_PATH}/nvector/pthreads)

# Prepare substitution variables for Makefile and/or CMakeLists templates
set(SOLVER_LIB "sundials_nvecpthreads")

examples2string(nvector_pthreads_examples EXAMPLES)
examples2string(nvector_examples_dependencies EXAMPLES_DEPENDENCIES)

# Regardless of the platform we're on, we will generate and install
# CMakeLists.txt file for building the examples. This file can then
# be used as a template for the user's own programs.

# generate CMakelists.txt in the binary directory
configure_file(
${PROJECT_SOURCE_DIR}/examples/templates/cmakelists_pthreads_C_ex.in
${PROJECT_BINARY_DIR}/examples/nvector/pthreads/CMakeLists.txt
@ONLY
)

# install CMakelists.txt
install(
FILES ${PROJECT_BINARY_DIR}/examples/nvector/pthreads/CMakeLists.txt
DESTINATION ${EXAMPLES_INSTALL_PATH}/nvector/pthreads
)

# On UNIX-type platforms, we also generate and install a makefile for
# building the examples. This makefile can then be used as a template
# for the user's own programs.

if(UNIX)
# generate Makefile and place it in the binary dir
configure_file(
${PROJECT_SOURCE_DIR}/examples/templates/makefile_pthreads_C_ex.in
${PROJECT_BINARY_DIR}/examples/nvector/pthreads/Makefile_ex
@ONLY
)
# install the configured Makefile_ex as Makefile
install(
FILES ${PROJECT_BINARY_DIR}/examples/nvector/pthreads/Makefile_ex
DESTINATION ${EXAMPLES_INSTALL_PATH}/nvector/pthreads
RENAME Makefile
)
endif()
sundials_install_examples(nvector nvector_pthreads_examples
CMAKE_TEMPLATE
cmakelists_C_pthreads_ex.in
MAKE_TEMPLATE
makefile_pthreads_C_ex.in
SUNDIALS_TARGETS
nvecpthreads
DESTINATION
nvector/pthreads
EXAMPLES_DEPENDENCIES
${nvector_examples_dependencies}
EXTRA_FILES
${nvector_examples_files}
TEST_INSTALL
pthreads
)

endif()

0 comments on commit 21c6f9a

Please sign in to comment.