Skip to content

Commit

Permalink
Created a new pthreads template that follows new naming covention and…
Browse files Browse the repository at this point in the history
… template style
  • Loading branch information
shahbajsohal committed Jul 7, 2023
1 parent 9b8d30e commit 4e84eec
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions examples/templates/cmakelists_C_pthreads_ex.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# -----------------------------------------------------------------
# Programmer(s): Radu Serban @ LLNL
# David J. Gardner @ LLNL
# -----------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2023, Lawrence Livermore National Security
# and Southern Methodist University.
# All rights reserved.
#
# See the top-level LICENSE and NOTICE files for details.
#
# SPDX-License-Identifier: BSD-3-Clause
# SUNDIALS Copyright End
# -----------------------------------------------------------------
# CMakeLists.txt for @SOLVER@ C PThreads examples.
#
# This file is generated from a template using variables
# set at configuration time. It can be used as a template for
# other user CMakeLists configuration files.
# -----------------------------------------------------------------

# Set the minimum required cmake version
cmake_minimum_required(VERSION @CMAKE_VERSION@)

# Set cache variables for compilers and flags
set(CMAKE_C_COMPILER
@_EXAMPLES_C_COMPILER@
CACHE FILEPATH "C compiler")

set(CMAKE_C_FLAGS
"@CMAKE_C_FLAGS@"
CACHE STRING "C compiler flags")

if("@CMAKE_C_STANDARD@")
set(CMAKE_C_STANDARD "@CMAKE_C_STANDARD@"
CACHE STRING "C standard")
endif()

# Specify project name and languages
project(@SOLVER@_C_pthreads_examples C)

# Enable testing
include(CTest)

# find PThreads library
find_package(Threads REQUIRED)

@EXAMPLES_FIND_PACKAGE@
# ------------------------------------------------------------------------------

# Specify the path to SUNDIALSConfig.cmake
set(SUNDIALS_DIR
"@CMAKE_INSTALL_PREFIX@/@SUNDIALS_INSTALL_CMAKEDIR@"
CACHE PATH "Location of SUNDIALSConfig.cmake")

# Find SUNDIALS
find_package(SUNDIALS
COMPONENTS @EXAMPLES_CMAKE_COMPONENTS@
REQUIRED NO_DEFAULT_PATH)

# Set the SUNDIALS targets
set(SUNDIALS_TARGETS
@EXAMPLES_CMAKE_TARGETS@)

# Set any additional libraries needed
set(EXTRA_LIBS
@EXAMPLES_EXTRA_LIBS@
CACHE STRING "Additional libraries")

# Additional includes
include_directories(. @EXTRA_INCLUDES@)

# ------------------------------------------------------------------------------

# Set the names of the examples to be built and their dependencies
set(examples @EXAMPLES@)
set(examples_args @ALL_EXAMPLES_ARGS@)
set(examples_dependencies @EXAMPLES_DEPENDENCIES@)

list(LENGTH examples n_elems) # Total number of the elements in the every list
math(EXPR len "${n_elems}-1") # The last index in the every list

# Create targets for each example
foreach(idx RANGE ${len})

list(GET examples ${idx} example)
list(GET examples_args ${idx} example_args)

# get filename without extension
get_filename_component(example_target ${example} NAME_WE)

# create target with example source files
if(NOT TARGET ${example_target})
add_executable(${example_target} ${example} ${examples_dependencies})
endif()

# libraries to link against
target_link_libraries(${example_target}
${SUNDIALS_TARGETS} ${EXTRA_LIBS} Threads::Threads)

# add the example to ctest
if("${example_args}" STREQUAL "")
set(test_name ${example})
else()
string(REGEX REPLACE " " "_" test_name ${example}_${example_args})
endif()
separate_arguments(example_args_wo_quotes UNIX_COMMAND "${example_args}")
add_test(NAME ${test_name} COMMAND ${example_target} ${example_args_wo_quotes})

endforeach()

0 comments on commit 4e84eec

Please sign in to comment.