Skip to content

Commit

Permalink
Merge pull request #117 from awslabs/sjg/palace-library-dev
Browse files Browse the repository at this point in the history
Add library target libpalace.a/.so
  • Loading branch information
sebastiangrimberg authored Oct 23, 2023
2 parents b1f3136 + 6f6ae58 commit cdce1af
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 98 deletions.
105 changes: 56 additions & 49 deletions palace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,51 @@ elseif(NOT PALACE_WITH_SLEPC)
message(FATAL_ERROR "Build requires at least one of ARPACK or SLEPc dependencies")
endif()

# Add executable target
set(TARGET_NAME palace)
add_executable(${TARGET_NAME} "")
# Optionally configure static analysis
include(StaticAnalysisHelpers)
if(ANALYZE_SOURCES_CLANG_TIDY)
configure_clang_tidy()
else()
message(STATUS "Static analysis with clang-tidy not requested")
endif()
if(ANALYZE_SOURCES_CPPCHECK)
configure_cppcheck()
else()
message(STATUS "Static analysis with cppcheck not requested")
endif()

# Add library target
set(LIB_TARGET_NAME libpalace)
add_library(${LIB_TARGET_NAME} "")
target_include_directories(${LIB_TARGET_NAME} PUBLIC ${CMAKE_SOURCE_DIR})

# Add source files
target_sources(${TARGET_NAME}
PRIVATE ${CMAKE_SOURCE_DIR}/main.cpp
)
target_include_directories(${TARGET_NAME}
PRIVATE ${CMAKE_SOURCE_DIR}
)
add_subdirectory(drivers)
add_subdirectory(fem)
add_subdirectory(linalg)
add_subdirectory(models)
add_subdirectory(utils)

# Add executable target
set(TARGET_NAME palace)
add_executable(${TARGET_NAME} ${CMAKE_SOURCE_DIR}/main.cpp)
target_link_libraries(${TARGET_NAME} PRIVATE ${LIB_TARGET_NAME})

# Add binary extension for build architecture
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm")
set(TARGET_EXTENSION "arm64")
else()
set(TARGET_EXTENSION "x86_64")
endif()
set_target_properties(${TARGET_NAME}
PROPERTIES
OUTPUT_NAME "${TARGET_NAME}-${TARGET_EXTENSION}"
SUFFIX ".bin"
)
set_target_properties(${LIB_TARGET_NAME}
PROPERTIES OUTPUT_NAME "${TARGET_NAME}"
)

# Add JIT source file path definition for libCEED
set_property(
SOURCE ${CMAKE_SOURCE_DIR}/main.cpp
Expand All @@ -178,8 +206,8 @@ if(NOT DEFINED CONSTEXPR_SQRT_SUPPORT_CACHE)
set(CONSTEXPR_SQRT_SUPPORT_CACHE ${CONSTEXPR_SQRT_SUPPORT} CACHE INTERNAL "")
endif()
if(CONSTEXPR_SQRT_SUPPORT_CACHE)
target_compile_definitions(${TARGET_NAME}
PRIVATE PALACE_WITH_CONSTEXPR_SQRT
target_compile_definitions(${LIB_TARGET_NAME}
PUBLIC PALACE_WITH_CONSTEXPR_SQRT
)
endif()
if(NOT DEFINED STD_FS_LIBRARIES_CACHE)
Expand All @@ -190,49 +218,41 @@ if(NOT DEFINED STD_FS_LIBRARIES_CACHE)
set(STD_FS_LIBRARIES_CACHE ${STD_FS_LIBRARIES} CACHE INTERNAL "")
endif()
if(NOT "${STD_FS_LIBRARIES_CACHE}" STREQUAL "")
target_link_libraries(${TARGET_NAME}
PRIVATE ${STD_FS_LIBRARIES_CACHE}
target_link_libraries(${LIB_TARGET_NAME}
PUBLIC ${STD_FS_LIBRARIES_CACHE}
)
endif()

# Link with third-party dependencies
if(PALACE_WITH_SLEPC)
target_link_libraries(${TARGET_NAME}
PRIVATE ${SLEPC_TARGET} ${PETSC_TARGET}
target_link_libraries(${LIB_TARGET_NAME}
PUBLIC ${SLEPC_TARGET} ${PETSC_TARGET}
)
target_compile_definitions(${TARGET_NAME}
PRIVATE PALACE_WITH_SLEPC
target_compile_definitions(${LIB_TARGET_NAME}
PUBLIC PALACE_WITH_SLEPC
)
endif()
if(PALACE_WITH_ARPACK)
target_link_libraries(${TARGET_NAME}
PRIVATE PARPACK::PARPACK ARPACK::ARPACK ${MPI_Fortran_LIBRARIES}
target_link_libraries(${LIB_TARGET_NAME}
PUBLIC PARPACK::PARPACK ARPACK::ARPACK ${MPI_Fortran_LIBRARIES}
)
target_compile_definitions(${TARGET_NAME}
PRIVATE PALACE_WITH_ARPACK
target_compile_definitions(${LIB_TARGET_NAME}
PUBLIC PALACE_WITH_ARPACK
)
endif()
if(PALACE_WITH_OPENMP)
target_link_libraries(${TARGET_NAME}
PRIVATE OpenMP::OpenMP_CXX
target_link_libraries(${LIB_TARGET_NAME}
PUBLIC OpenMP::OpenMP_CXX
)
endif()
target_link_libraries(${TARGET_NAME}
PRIVATE mfem ${LIBCEED_TARGET} nlohmann_json::nlohmann_json fmt::fmt Eigen3::Eigen MPI::MPI_CXX
)

# Add binary extension for build architecture
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm")
set(TARGET_EXTENSION "arm64")
else()
set(TARGET_EXTENSION "x86_64")
endif()
set_target_properties(${TARGET_NAME} PROPERTIES
OUTPUT_NAME "${TARGET_NAME}-${TARGET_EXTENSION}"
SUFFIX ".bin"
target_link_libraries(${LIB_TARGET_NAME}
PUBLIC mfem ${LIBCEED_TARGET} nlohmann_json::nlohmann_json fmt::fmt Eigen3::Eigen MPI::MPI_CXX
)

# Install target and helper scripts
install(TARGETS
${LIB_TARGET_NAME}
)
install(TARGETS
${TARGET_NAME}
RUNTIME DESTINATION bin
Expand All @@ -257,19 +277,6 @@ install(DIRECTORY
# Add tests (disabled by default)
add_subdirectory(../test/unit ${CMAKE_BINARY_DIR}/test/unit EXCLUDE_FROM_ALL)

# Optionally configure static analysis
include(StaticAnalysisHelpers)
if(ANALYZE_SOURCES_CLANG_TIDY)
configure_clang_tidy(${TARGET_NAME})
else()
message(STATUS "Static analysis with clang-tidy not requested")
endif()
if(ANALYZE_SOURCES_CPPCHECK)
configure_cppcheck(${TARGET_NAME})
else()
message(STATUS "Static analysis with cppcheck not requested")
endif()

# Status messages for build settings
message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Building for architecture: ${CMAKE_SYSTEM_PROCESSOR}")
Expand Down
12 changes: 4 additions & 8 deletions palace/cmake/StaticAnalysisHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if(__static_analysis_helpers)
endif()
set(__static_analysis_helpers YES)

function(configure_clang_tidy _target_name)
function(configure_clang_tidy)
find_program(CLANG_TIDY_EXE
NAMES clang-tidy
)
Expand Down Expand Up @@ -55,16 +55,14 @@ function(configure_clang_tidy _target_name)
)
endif()
endif()
set_target_properties(${_target_name} PROPERTIES
CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}"
)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}" CACHE STRING "" FORCE)
else()
message(WARNING "Static analysis with clang-tidy requested, but skipped because the \
executable clang-tidy was not found")
endif()
endfunction()

function(configure_cppcheck _target_name)
function(configure_cppcheck)
find_program(CPPCHECK_EXE
NAMES cppcheck
)
Expand All @@ -84,9 +82,7 @@ function(configure_cppcheck _target_name)
"--enable=warning,style,performance,portability"
"--suppressions-list=${CMAKE_BINARY_DIR}/CMakeFiles/cppcheck/suppressions.txt"
)
set_target_properties(${_target_name} PROPERTIES
CXX_CPPCHECK "${CPPCHECK_COMMAND}"
)
set(CMAKE_CXX_CPPCHECK "${CPPCHECK_COMMAND}" CACHE STRING "" FORCE)
else()
message(WARNING "Static analysis with cppcheck requested, but skipped because the \
executable cppcheck was not found")
Expand Down
2 changes: 1 addition & 1 deletion palace/drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Add source files and subdirectories.
#

target_sources(${TARGET_NAME}
target_sources(${LIB_TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/basesolver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/drivensolver.cpp
Expand Down
2 changes: 1 addition & 1 deletion palace/fem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Add source files and subdirectories.
#

target_sources(${TARGET_NAME}
target_sources(${LIB_TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/bilinearform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/coefficient.cpp
Expand Down
2 changes: 1 addition & 1 deletion palace/linalg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Add source files and subdirectories.
#

target_sources(${TARGET_NAME}
target_sources(${LIB_TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/amg.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ams.cpp
Expand Down
2 changes: 1 addition & 1 deletion palace/models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Add source files and subdirectories.
#

target_sources(${TARGET_NAME}
target_sources(${LIB_TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/curlcurloperator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/domainpostoperator.cpp
Expand Down
2 changes: 1 addition & 1 deletion palace/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Add source files and subdirectories.
#

target_sources(${TARGET_NAME}
target_sources(${LIB_TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/configfile.cpp
${CMAKE_CURRENT_SOURCE_DIR}/geodata.cpp
Expand Down
38 changes: 2 additions & 36 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,11 @@ FetchContent_Declare(Catch2
FetchContent_MakeAvailable(Catch2)

# Add executable target
add_executable(unit-tests "")

# Add source files
target_sources(unit-tests
PRIVATE
add_executable(unit-tests
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test-libceed.cpp
${CMAKE_SOURCE_DIR}/fem/bilinearform.cpp
${CMAKE_SOURCE_DIR}/fem/fespace.cpp
${CMAKE_SOURCE_DIR}/fem/integrator.cpp
${CMAKE_SOURCE_DIR}/fem/integ/curlcurl.cpp
${CMAKE_SOURCE_DIR}/fem/integ/curlcurlmass.cpp
${CMAKE_SOURCE_DIR}/fem/integ/diffusion.cpp
${CMAKE_SOURCE_DIR}/fem/integ/diffusionmass.cpp
${CMAKE_SOURCE_DIR}/fem/integ/divdiv.cpp
${CMAKE_SOURCE_DIR}/fem/integ/divdivmass.cpp
${CMAKE_SOURCE_DIR}/fem/integ/grad.cpp
${CMAKE_SOURCE_DIR}/fem/integ/mass.cpp
${CMAKE_SOURCE_DIR}/fem/integ/mixedveccurl.cpp
${CMAKE_SOURCE_DIR}/fem/integ/mixedvecgrad.cpp
${CMAKE_SOURCE_DIR}/fem/integ/vecfemass.cpp
${CMAKE_SOURCE_DIR}/fem/libceed/basis.cpp
${CMAKE_SOURCE_DIR}/fem/libceed/operator.cpp
${CMAKE_SOURCE_DIR}/fem/libceed/restriction.cpp
${CMAKE_SOURCE_DIR}/fem/libceed/utils.cpp
)
target_include_directories(unit-tests
PRIVATE ${CMAKE_SOURCE_DIR}
)
target_link_libraries(unit-tests PRIVATE ${LIB_TARGET_NAME} Catch2::Catch2)

# Add JIT source file path definition for libCEED
set_property(
Expand All @@ -56,15 +32,5 @@ set_property(
APPEND PROPERTY COMPILE_DEFINITIONS "PALACE_TEST_MESH_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/mesh\""
)

# Link with third-party dependencies
if(PALACE_WITH_OPENMP)
target_link_libraries(unit-tests
PRIVATE OpenMP::OpenMP_CXX
)
endif()
target_link_libraries(unit-tests
PRIVATE mfem ${LIBCEED_TARGET} MPI::MPI_CXX Catch2::Catch2
)

# Status messages for test target
message(STATUS "Configured unit-tests target for unit tests using Catch2")

0 comments on commit cdce1af

Please sign in to comment.