Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch over fully to modern CMake targets and updates for testing against Trilinos (#299) #479

Merged
merged 35 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
21c919f
Fix some typos in comments
bartlettroscoe May 26, 2022
a99bf60
Fix the comment line for a test block
bartlettroscoe May 26, 2022
d9646f0
Standardize comments (#299)
bartlettroscoe May 3, 2022
a7c2282
Add "" initializers for several vars (#299)
bartlettroscoe May 3, 2022
e8bb3d7
Snapshot FindTPLNetcdf.cmake from Trilinos 8c1028df724 with small mod…
bartlettroscoe May 18, 2022
bed095e
Switch to relying on TRIBITS_TESTONLY_LIB property only (#299)
bartlettroscoe May 4, 2022
ca3f5e3
Switch to linking against <Package>::all_libs (#299)
bartlettroscoe May 3, 2022
969abad
WIP: Comment out old TriBITS manual manipulation of includes and libs…
bartlettroscoe May 3, 2022
2e51918
Factor out new module TribitsConfigureFile.cmake (#63, #299)
bartlettroscoe May 5, 2022
31fbaea
WIP: Remove old TriBITS manual manipulation of includes and libs (#299)
bartlettroscoe May 5, 2022
ed1597c
Factor out TribitsAddLibrary.cmake for tribits_add_library() (#299)
bartlettroscoe May 5, 2022
5011e8b
tribits_add_library(): Factor out functions and some cleanup (#299)
bartlettroscoe May 6, 2022
81f7f44
Add test for ADD_DIR_TO_NAME (#299)
bartlettroscoe May 13, 2022
f4752b3
Rename local var to test tribits_create_name_from_current_source_dire…
bartlettroscoe May 13, 2022
d7a81de
Fix return arg in tribits_create_name_from_current_source_directory()…
bartlettroscoe May 13, 2022
24a2a8e
tribits_add_executable(): Factor out functions and cleanup (#299)
bartlettroscoe May 6, 2022
dcb616f
Remove comments about being hard to maintain (#299)
bartlettroscoe May 7, 2022
cb6bdbd
Remove all obsolete doc references to include dirs and lib dirs (#299)
bartlettroscoe May 7, 2022
d430376
TribitsExampleProject2: Remove hacked dependencies on indirect TPLs (…
bartlettroscoe May 13, 2022
7ef19a1
Update changelog for final switch to modern CMake targets (#299)
bartlettroscoe May 13, 2022
6ddc67a
Add changelog note about no longer setting dir property INCLUDE_DIREC…
bartlettroscoe May 17, 2022
a9cdb79
Add changelog note for setting <Package>_ENABLE_<depPkg> for required…
bartlettroscoe May 17, 2022
b1895f7
Handle <Project>_EXTRA_LINK_FLAGS as extra TPL that everything depend…
bartlettroscoe May 26, 2022
a168af1
Add back include_guard(GLOBAL) (#299)
bartlettroscoe May 27, 2022
618284a
WIP: Set <Project>_INCLUDE_DIRS in <Project>Config.cmake for the inst…
bartlettroscoe May 27, 2022
ebe89e3
Add test for TribitsExampleApp with MPI enabled (#299)
bartlettroscoe May 27, 2022
e2dbc66
WIP: Make SimpleCxx package dependent on MPI (#299)
bartlettroscoe May 28, 2022
a831472
Fix tests for adding MPI to SimpleCxx and adding back install include…
bartlettroscoe May 28, 2022
4051847
WIP: Add test to expose defect with MPI::all_libs (#299)
bartlettroscoe May 28, 2022
9206994
Have TPL MPI produce MPI::all_libs and MPIConfig.cmake (#299)
bartlettroscoe May 27, 2022
700f916
Remove worthless `if (TARGET <Pkg>::all_libs)` checks (#299)
bartlettroscoe May 28, 2022
4a2ecc0
Merge remote-tracking branch 'github/master' into 299-switch-to-moder…
bartlettroscoe Jun 8, 2022
f240850
Exclude MPI tests when MPI not available (#299)
bartlettroscoe Jun 8, 2022
4758901
Only link to <Package>_TEST_ENABLED_DEPENDENCIES for TESTONLY libs (#…
bartlettroscoe Jun 8, 2022
21d3c4b
Fuse foreach() loops for LIB and TEST dependencies (#299)
bartlettroscoe Jun 8, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function(TribitsExampleProject2_find_tpl_parts sharedOrStatic findingTplsMethod)
"set[(]Package3_ENABLE_Tpl3 ON[)]"

TEST_2
MESSAGE "Build verbose to check the link line of Package3"
MESSAGE "Build verbose to check the link lines"
CMND ${CMAKE_COMMAND} ARGS --build . -v
PASS_REGULAR_EXPRESSION_ALL
"[-]o packages/package1/src/package1-prg .* ${tplInstallBaseDir}/install_tpl1/lib/libtpl1${libextregex}"
Expand Down
4 changes: 2 additions & 2 deletions test/core/ExamplesUnitTests/TribitsExampleProject_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2918,10 +2918,10 @@ tribits_add_advanced_test( TribitsExampleProject_compiler_flags
)
# NOTE: The above tests checks the compiler flags that are set by TriBITS for
# the various use cases. This is a hard test to make portable because we
# really need to check that the comiler options are set all the way down. To
# really need to check that the compiler options are set all the way down. To
# make this more portable, we only do this on Linux systems and only with GCC.
#
# We actaully build known targets with 'make VERBOSE=1 <target>' and then grep
# We actually build known targets with 'make VERBOSE=1 <target>' and then grep
# the output to make sure the compiler flags drill down all the way to the
# actual targets.
#
Expand Down
50 changes: 47 additions & 3 deletions tribits/common_tpls/FindTPLNetcdf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
set(REQUIRED_HEADERS netcdf.h)
set(REQUIRED_LIBS_NAMES netcdf)

if (TPL_ENABLE_MPI)
set(REQUIRED_LIBS_NAMES ${REQUIRED_LIBS_NAMES} pnetcdf)
endif()

#
# Second, search for Netcdf components (if allowed) using the standard
# find_package(NetCDF ...).
Expand All @@ -62,7 +66,7 @@ if (Netcdf_ALLOW_PREFIND)
"${CMAKE_CURRENT_LIST_DIR}/find_modules"
"${CMAKE_CURRENT_LIST_DIR}/utils"
)

find_package(NetCDF)

if (NetCDF_FOUND)
Expand All @@ -71,7 +75,7 @@ if (Netcdf_ALLOW_PREFIND)
"True if netcdf enables netcdf-4")
set(TPL_Netcdf_Enables_PNetcdf ${NetCDF_NEEDS_PNetCDF} CACHE BOOL
"True if netcdf enables pnetcdf")
set(TPL_Netcdf_PARALLEL ${NetCDF_PARALLEL} CACHE BOOL
set(TPL_Netcdf_PARALLEL ${NetCDF_PARALLEL} CACHE INTERNAL
"True if netcdf compiled with parallel enabled")
set(TPL_Netcdf_LIBRARY_DIRS ${_hdf5_LIBRARY_SEARCH_DIRS} CACHE PATH
"${DOCSTR} library files")
Expand All @@ -80,7 +84,20 @@ if (Netcdf_ALLOW_PREFIND)
set(TPL_Netcdf_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} CACHE PATH
"${DOCSTR} header files.")
endif()

else()
# Curl library is only required if DAP is enabled; should detect inside
# FindNetCDF.cmake, but that is not being called... SEMS has DAP enabled;
# many HPC systems don't, but they override these settings...
find_program(NC_CONFIG "nc-config")
if (NC_CONFIG)
execute_process(COMMAND "nc-config --has-dap2"
OUTPUT_VARIABLE NETCDF_HAS_DAP2)
execute_process(COMMAND "nc-config --has-dap4"
OUTPUT_VARIABLE NETCDF_HAS_DAP4)
endif()
if ((NOT NC_CONFIG) OR NETCDF_HAS_DAP2 OR NETCDF_HAS_DAP4)
set(REQUIRED_LIBS_NAMES ${REQUIRED_LIBS_NAMES} curl)
endif()
endif()

#
Expand All @@ -95,3 +112,30 @@ tribits_tpl_find_include_dirs_and_libraries( Netcdf
# variables TPL_Netcdf_INCLUDE_DIRS and TPL_Netcdf_LIBRARIES and then print
# them out (and set some other standard variables as well). This is the final
# "hook" into the TriBITS TPL system.

# If the `find_package(NetCDF)` is not run, then this may not be set
# Need to determine how this is set in the library that is being used...

if ("${TPL_Netcdf_PARALLEL}" STREQUAL "")
assert_defined(TPL_Netcdf_INCLUDE_DIRS)
find_path(meta_path
NAMES "netcdf_meta.h"
HINTS ${TPL_Netcdf_INCLUDE_DIRS}
NO_DEFAULT_PATH)

if (meta_path)
# Search meta for NC_HAS_PARALLEL setting...
# Note that there is both NC_HAS_PARALLEL and NC_HAS_PARALLEL4, only want first...
file(STRINGS "${meta_path}/netcdf_meta.h" netcdf_par_string REGEX "NC_HAS_PARALLEL ")
string(REGEX MATCH "[01]" netcdf_par_val "${netcdf_par_string}")
if (netcdf_par_val EQUAL 1)
set(TPL_Netcdf_PARALLEL True CACHE INTERNAL
"True if netcdf compiled with parallel enabled")
endif()
endif()
if ("${TPL_Netcdf_PARALLEL}" STREQUAL "")
set(TPL_Netcdf_PARALLEL False CACHE INTERNAL
"True if netcdf compiled with parallel enabled")
endif()
endif()
message(STATUS "TPL_Netcdf_PARALLEL is ${TPL_Netcdf_PARALLEL}")
35 changes: 30 additions & 5 deletions tribits/core/package_arch/TribitsAddExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ include(TribitsAddExecutableTestHelpers)
include(TribitsCommonArgsHelpers)
include(TribitsAddTestHelpers)
include(TribitsGeneralMacros)
include(TribitsLibIsTestOnly)
include(TribitsReportInvalidTribitsUsage)

include(PrintVar)
Expand Down Expand Up @@ -473,7 +474,8 @@ function(tribits_add_executable EXE_NAME)
# Assert that TESTONLYLIBS only contains TESTONLY libs!
foreach(TESTONLYLIB ${PARSE_TESTONLYLIBS})
set(PREFIXED_LIB "${${PROJECT_NAME}_LIBRARY_NAME_PREFIX}${TESTONLYLIB}")
if (NOT ${PREFIXED_LIB}_INCLUDE_DIRS)
tribits_lib_is_testonly(${PREFIXED_LIB} libIsTestOnlyLib)
if (NOT libIsTestOnlyLib)
message(FATAL_ERROR "ERROR: '${TESTONLYLIB}' in TESTONLYLIBS not a TESTONLY lib!"
" If this a regular library in this SE package or in an dependent upstream SE"
" package then TriBITS will link automatically to it. If you remove this and it"
Expand All @@ -493,7 +495,8 @@ function(tribits_add_executable EXE_NAME)
# libs!
foreach(IMPORTEDLIB ${PARSE_IMPORTEDLIBS})
set(PREFIXED_LIB "${${PROJECT_NAME}_LIBRARY_NAME_PREFIX}${IMPORTEDLIB}")
if (${PREFIXED_LIB}_INCLUDE_DIRS)
tribits_lib_is_testonly(${PREFIXED_LIB} libIsTestOnlyLib)
if (libIsTestOnly)
message(FATAL_ERROR
"ERROR: Lib '${IMPORTEDLIB}' being passed through"
" IMPORTEDLIBS is not allowed to be a TESTONLY lib!"
Expand Down Expand Up @@ -523,7 +526,8 @@ function(tribits_add_executable EXE_NAME)
# Convert from old DEPLIBS to TESTONLYLIBS and IMPORTEDLIBS
foreach(DEPLIB ${PARSE_DEPLIBS})
set(PREFIXED_LIB "${${PROJECT_NAME}_LIBRARY_NAME_PREFIX}${DEPLIB}")
if (${PREFIXED_LIB}_INCLUDE_DIRS)
tribits_lib_is_testonly(${PREFIXED_LIB} libIsTestOnlyLib)
if (libIsTestOnlyLib)
message(WARNING "WARNING: Passing TESTONLY lib '${DEPLIB}' through DEPLIBS"
" is deprecated! Instead, please pass through TESTONLYLIBS instead!"
" DEPLIBS is deprecated!")
Expand All @@ -550,7 +554,8 @@ function(tribits_add_executable EXE_NAME)

foreach(TESTONLYLIB_IN ${PARSE_TESTONLYLIBS})
set(TESTONLYLIB "${LIBRARY_NAME_PREFIX}${TESTONLYLIB_IN}")
if (${TESTONLYLIB}_INCLUDE_DIRS)
tribits_lib_is_testonly(${TESTONLYLIB} libIsTestOnlyLib)
if (libIsTestOnlyLib)
if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
message(STATUS "Adding include directories ${TESTONLYLIB}_INCLUDE_DIRS ...")
endif()
Expand Down Expand Up @@ -647,7 +652,27 @@ function(tribits_add_executable EXE_NAME)
message("-- ${EXE_NAME}:LINK_LIBS='${LINK_LIBS}'")
endif()

target_link_libraries(${EXE_BINARY_NAME} PUBLIC ${LINK_LIBS})
#
# Link ${EXE_BINARY_NAME} to direct upstream libraries
#

target_link_libraries(${EXE_BINARY_NAME} PUBLIC ${${PACKAGE_NAME}_LIBRARIES})
foreach(depPkg IN LISTS ${PACKAGE_NAME}_LIB_ENABLED_DEPENDENCIES)
if (TARGET ${depPkg}::all_libs)
target_link_libraries(${EXE_BINARY_NAME} PUBLIC ${depPkg}::all_libs)
endif()
endforeach()
foreach(depPkg IN LISTS ${PACKAGE_NAME}_TEST_ENABLED_DEPENDENCIES)
if (TARGET ${depPkg}::all_libs)
target_link_libraries(${EXE_BINARY_NAME} PUBLIC ${depPkg}::all_libs)
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see a lot of instances where you have the exact same logic for two different lists. You can combine both lists in foreach(IN LISTS). For example:

foreach(depPkg IN LISTS ${PACKAGE_NAME}_LIB_ENABLED_DEPENDENCIES ${PACKAGE_NAME}_TEST_ENABLED_DEPENDENCIES)
  if(TARGET ${depPkg}::all_libs)
    target_link_libraries(${EXE_BINARY_NAME} PUBLIC ${depPkg}::all_libs)
  endif()
endforeach()

Copy link
Member Author

Choose a reason for hiding this comment

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

That is a good point. Please flag other instances you see like this

endforeach()
foreach(testOnlyLib ${PARSE_TESTONLYLIBS})
target_link_libraries(${EXE_BINARY_NAME} PUBLIC
"${LIBRARY_NAME_PREFIX}${testOnlyLib}")
endforeach()

#target_link_libraries(${EXE_BINARY_NAME} PUBLIC ${LINK_LIBS})

assert_defined(${PROJECT_NAME}_LINK_SEARCH_START_STATIC)
if (${PROJECT_NAME}_LINK_SEARCH_START_STATIC)
Expand Down
8 changes: 4 additions & 4 deletions tribits/core/package_arch/TribitsGlobalMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2087,10 +2087,10 @@ macro(tribits_configure_enabled_packages)
# A) Global variable initialization
#

global_null_set(${PROJECT_NAME}_INCLUDE_DIRS)
global_null_set(${PROJECT_NAME}_LIBRARY_DIRS)
global_null_set(${PROJECT_NAME}_LIBRARIES)
global_null_set(${PROJECT_NAME}_ETI_PACKAGES)
global_null_set(${PROJECT_NAME}_INCLUDE_DIRS "")
global_null_set(${PROJECT_NAME}_LIBRARY_DIRS "")
global_null_set(${PROJECT_NAME}_LIBRARIES "")
global_null_set(${PROJECT_NAME}_ETI_PACKAGES "")

#
# B) Define the source and binary directories for all of the packages that
Expand Down
77 changes: 77 additions & 0 deletions tribits/core/package_arch/TribitsLibIsTestOnly.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# @HEADER
# ************************************************************************
#
# TriBITS: Tribal Build, Integrate, and Test System
# Copyright 2013 Sandia Corporation
#
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the Corporation nor the names of the
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ************************************************************************
# @HEADER

include_guard()


# @FUNCTION: tribits_set_lib_is_testonly()
#
# See if a library is a TESTONLY library
#
# Usage::
#
# tribits_set_lib_is_testonly(<libName>)
#
# This sets the ``TRIBITS_TESTONLY_LIB`` on the library target ``<libName>``.
#
function(tribits_set_lib_is_testonly libName)
set_target_properties(${libName} PROPERTIES TRIBITS_TESTONLY_LIB TRUE)
endfunction()


# @FUNCTION: tribits_lib_is_testonly()
#
# See if a library is a TESTONLY library
#
# Usage::
#
# tribits_lib_is_testonly(<libName> <libIsTestOnlyOut>)
#
# This will only return ``TRUE`` in `` <libIsTestOnlyOut>`` if ``<libName>``
# is a target and the target property ``TRIBITS_TESTONLY_LIB`` is set to
# ``TRUE``.
#
function(tribits_lib_is_testonly libName libIsTestOnlyOut)
if (TARGET ${libName})
get_target_property(libIsTestOnly ${libName} TRIBITS_TESTONLY_LIB)
else()
set(libIsTestOnly FALSE)
endif()
set(${libIsTestOnlyOut} ${libIsTestOnly} PARENT_SCOPE)
endfunction()
Loading