Skip to content

Commit

Permalink
Set build options at target level. Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwryankrattiger committed Nov 4, 2021
1 parent aa20d0f commit 1462186
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 76 deletions.
64 changes: 29 additions & 35 deletions CMake/build.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
include(CheckCXXCompilerFlag)

option(BUILD_SHARED_LIBS OFF "Build shared libraries by default")
option(BUILD_STATIC_EXECS OFF "Link executables statically")

if (BUILD_STATIC_EXECS)
set(BUILD_SHARED_LIBS OFF FORCE)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
set(LINK_SEARCH_START_STATIC TRUE)
set(LINK_SEARCH_END_STATIC TRUE)
Expand All @@ -15,46 +13,42 @@ if(NOT CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

# SENSEI should always be position independent
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# SENSEI requires minimum C++11
if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11)
set(CMAKE_CXX_STANDARD 11)
endif ()

if (NOT MSVC)
string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra")

# Need to explicitly set optimization level to -O3 because some systems default to -O2
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(optimization_flags " -mtune=native; -march=native")
foreach (flag ${optimization_flags})
check_cxx_compiler_flag(${flag} has_flag)
if(has_flag)
string(APPEND CMAKE_CXX_FLAGS_RELEASE ${flag})
endif ()
endforeach ()

if (BUILD_STATIC_EXECS)
string(APPEND CMAKE_CXX_FLAGS "-static -static-libgcc -static-libstdc++ -pthread -Wl,-Bstatic")
endif ()
endif ()

if (APPLE)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
string(APPEND CMAKE_CXX_FLAGS "-stdlib=libc++")
endif ()
endif ()

include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_BINARY_DIR})

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

message(STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
message(STATUS "BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}")
message(STATUS "BUILD_STATIC_EXECS=${BUILD_STATIC_EXECS}")

function (_sensei_set_target_properties name)
target_compile_features(${name} PUBLIC cxx_std_11)
target_compile_options(${name} PUBLIC
-Wall -Wextra
# Need to explicitly set optimization level to -O3 because some systems default to -O2
$<$<STREQUAL:$<UPPER_CASE:${CMAKE_BUILD_TYPE}>,"Release">:"-03">
$<$<STREQUAL:$<CXX_COMPILER_ID>,"AppleClang">:"-stdlib=libc++">)
set_target_properties(${name} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
CXX_STANDARD 11
CXX_EXTENSIONS OFF)
endfunction (_sensei_set_target_properties)

function (sensei_add_executable name)
add_executable(${name} ${ARGN})
_sensei_set_target_properties(${name})
endfunction (sensei_add_executable)

function (sensei_add_library name)
add_library(${name} ${ARGN})
_sensei_set_target_properties(${name})
set_target_properties(${name} PROPERTIES
POSITION_INDEPENDENT_CODE ON)
endfunction (sensei_add_library)
2 changes: 1 addition & 1 deletion CMake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function (senseiAddTest T_NAME)
if (T_EXEC_NAME)
set(EXEC_NAME ${T_EXEC_NAME})
endif()
add_executable(${EXEC_NAME} ${T_SOURCES})
sensei_add_executable(${EXEC_NAME} ${T_SOURCES})
if (T_LIBS)
target_link_libraries(${EXEC_NAME} ${T_LIBS})
endif()
Expand Down
2 changes: 1 addition & 1 deletion endpoints/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ if(ENABLE_HDF5)
list(APPEND endPointLibs sHDF5)
endif()

add_executable(SENSEIEndPoint SENSEIEndPoint.cpp)
sensei_add_executable(SENSEIEndPoint SENSEIEndPoint.cpp)
target_link_libraries(SENSEIEndPoint PRIVATE ${endPointLibs})
install(TARGETS SENSEIEndPoint RUNTIME DESTINATION bin)
2 changes: 1 addition & 1 deletion miniapps/kripke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if(ENABLE_OPENMP)
list(APPEND libs openmp)
endif()

add_executable(kripke_p ${KRIPKE_SOURCES})
sensei_add_executable(kripke_p ${KRIPKE_SOURCES})
target_link_libraries(kripke_p ${libs})


Expand Down
2 changes: 1 addition & 1 deletion miniapps/mandelbrot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (ENABLE_SENSEI)
list(APPEND libs sensei)
endif()

add_executable(mandelbrot ${sources})
sensei_add_executable(mandelbrot ${sources})
target_link_libraries(mandelbrot PRIVATE ${libs})

add_subdirectory(testing)
16 changes: 8 additions & 8 deletions miniapps/mandelbrot/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
if (BUILD_TESTING)

senseiAddTest(testMandelbrotHistogram
COMMAND mandelbrot -i 2 -l 2
COMMAND $<TARGET_FILE:mandelbrot> -i 2 -l 2
-f ${CMAKE_CURRENT_SOURCE_DIR}/mandelbrot_histogram.xml)

senseiAddTest(testMandelbrotHistogramPar
PARALLEL ${TEST_NP}
COMMAND mandelbrot -i 2 -l 2
COMMAND $<TARGET_FILE:mandelbrot> -i 2 -l 2
-f ${CMAKE_CURRENT_SOURCE_DIR}/mandelbrot_histogram.xml)

senseiAddTest(testMandelbrotVTKWriter
COMMAND mandelbrot -i 2 -l 2
COMMAND $<TARGET_FILE:mandelbrot> -i 2 -l 2
-f ${CMAKE_CURRENT_SOURCE_DIR}/mandelbrot_vtkwriter.xml
FEATURES VTK_IO VTK_MPI)

senseiAddTest(testMandelbrotVTKWriterPar
PARALLEL ${TEST_NP}
COMMAND mandelbrot -i 2 -l 2
COMMAND $<TARGET_FILE:mandelbrot> -i 2 -l 2
-f ${CMAKE_CURRENT_SOURCE_DIR}/mandelbrot_vtkwriter.xml
FEATURES VTK_IO VTK_MPI)

Expand All @@ -27,13 +27,13 @@ if (BUILD_TESTING)

senseiAddTest(testMandelbrotCatalyst
COMMAND
mandelbrot -i 2 -l 2
$<TARGET_FILE:mandelbrot> -i 2 -l 2
-f ${CMAKE_CURRENT_SOURCE_DIR}/mandelbrot_catalyst.xml
FEATURES CATALYST)

senseiAddTest(testMandelbrotCatalystPar
PARALLEL ${TEST_NP}
COMMAND mandelbrot -i 2 -l 2
COMMAND $<TARGET_FILE:mandelbrot> -i 2 -l 2
-f ${CMAKE_CURRENT_SOURCE_DIR}/mandelbrot_catalyst.xml
FEATURES CATALYST)

Expand All @@ -43,13 +43,13 @@ if (BUILD_TESTING)
endif()

senseiAddTest(testMandelbrotLibsim
COMMAND mandelbrot -i 2 -l 2
COMMAND $<TARGET_FILE:mandelbrot> -i 2 -l 2
-f ${CMAKE_CURRENT_SOURCE_DIR}/mandelbrot_libsim.xml
FEATURES LIBSIM)

senseiAddTest(testMandelbrotLibsimPar
PARALLEL ${TEST_NP}
COMMAND mandelbrot -i 2 -l 2
COMMAND $<TARGET_FILE:mandelbrot> -i 2 -l 2
-f ${CMAKE_CURRENT_SOURCE_DIR}/mandelbrot_libsim.xml
FEATURES LIBSIM)

Expand Down
2 changes: 1 addition & 1 deletion miniapps/oscillators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (OSCILLATOR_CUDA)
PROPERTIES LANGUAGE CUDA)
endif()

add_executable(oscillator ${sources})
sensei_add_executable(oscillator ${sources})
target_link_libraries(oscillator ${libs})

if (OSCILLATOR_CUDA)
Expand Down
26 changes: 13 additions & 13 deletions miniapps/oscillators/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
if (BUILD_TESTING)

senseiAddTest(testOscillatorHistogram
COMMAND oscillator -t 1 -b ${TEST_NP} -g 1
COMMAND $<TARGET_FILE:oscillator> -t 1 -b ${TEST_NP} -g 1
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_histogram.xml
${CMAKE_CURRENT_SOURCE_DIR}/simple.osc)

senseiAddTest(testOscillatorHistogramPar
PARALLEL ${TEST_NP}
COMMAND oscillator -t 1 -b ${TEST_NP} -g 1
COMMAND $<TARGET_FILE:oscillator> -t 1 -b ${TEST_NP} -g 1
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_histogram.xml
${CMAKE_CURRENT_SOURCE_DIR}/simple.osc)

senseiAddTest(testOscillatorAutocorrelation
COMMAND oscillator -t 1 -b ${TEST_NP} -g 1
COMMAND $<TARGET_FILE:oscillator> -t 1 -b ${TEST_NP} -g 1
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_autocorrelation.xml
${CMAKE_CURRENT_SOURCE_DIR}/simple.osc)

senseiAddTest(testOscillatorAutocorrelationPar
PARALLEL ${TEST_NP}
COMMAND oscillator -t 1 -b ${TEST_NP} -g 1
COMMAND $<TARGET_FILE:oscillator> -t 1 -b ${TEST_NP} -g 1
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_autocorrelation.xml
${CMAKE_CURRENT_SOURCE_DIR}/simple.osc)

senseiAddTest(testOscillatorVTKWriter
COMMAND oscillator -t 1 -b ${TEST_NP} -g 1
COMMAND $<TARGET_FILE:oscillator> -t 1 -b ${TEST_NP} -g 1
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_vtkwriter.xml
${CMAKE_CURRENT_SOURCE_DIR}/simple.osc
FEATURES VTK_IO)

senseiAddTest(testOscillatorVTKWriterPar
PARALLEL ${TEST_NP}
COMMAND oscillator -t 1 -b ${TEST_NP} -g 1
COMMAND $<TARGET_FILE:oscillator> -t 1 -b ${TEST_NP} -g 1
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_vtkwriter.xml
${CMAKE_CURRENT_SOURCE_DIR}/simple.osc
FEATURES VTK_IO)
Expand All @@ -41,14 +41,14 @@ if (BUILD_TESTING)
endif()

senseiAddTest(testOscillatorCatalyst
COMMAND oscillator -t 1 -b ${TEST_NP} -g 1
COMMAND $<TARGET_FILE:oscillator> -t 1 -b ${TEST_NP} -g 1
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_catalyst.xml
${CMAKE_CURRENT_SOURCE_DIR}/simple.osc
FEATURES CATALYST)

senseiAddTest(testOscillatorCatalystPar
PARALLEL ${TEST_NP}
COMMAND oscillator -t 1 -b ${TEST_NP} -g 1
COMMAND $<TARGET_FILE:oscillator> -t 1 -b ${TEST_NP} -g 1
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_catalyst.xml
${CMAKE_CURRENT_SOURCE_DIR}/simple.osc
FEATURES CATALYST)
Expand All @@ -59,14 +59,14 @@ if (BUILD_TESTING)
endif()

senseiAddTest(testOscillatorLibsim
COMMAND oscillator -t 1 -b ${TEST_NP} -g 1
COMMAND $<TARGET_FILE:oscillator> -t 1 -b ${TEST_NP} -g 1
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_libsim.xml
${CMAKE_CURRENT_SOURCE_DIR}/simple.osc
FEATURES LIBSIM)

senseiAddTest(testOscillatorLibsimPar
PARALLEL ${TEST_NP}
COMMAND oscillator -t 1 -b ${TEST_NP} -g 1
COMMAND $<TARGET_FILE:oscillator> -t 1 -b ${TEST_NP} -g 1
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_libsim.xml
${CMAKE_CURRENT_SOURCE_DIR}/simple.osc
FEATURES LIBSIM)
Expand All @@ -77,14 +77,14 @@ if (BUILD_TESTING)
endif()

senseiAddTest(testOscillatorAscent
COMMAND oscillator -t 2 -b ${TEST_NP} -g 0
COMMAND $<TARGET_FILE:oscillator> -t 2 -b ${TEST_NP} -g 0
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_ascent.xml
${CMAKE_CURRENT_SOURCE_DIR}/random_2d_64.osc
FEATURES ASCENT)

senseiAddTest(testOscillatorAscentPar
PARALLEL ${TEST_NP}
COMMAND oscillator -t 2 -b ${TEST_NP} -g 0
COMMAND $<TARGET_FILE:oscillator> -t 2 -b ${TEST_NP} -g 0
-f ${CMAKE_CURRENT_SOURCE_DIR}/oscillator_ascent.xml
${CMAKE_CURRENT_SOURCE_DIR}/random_2d_64.osc
FEATURES ASCENT)
Expand All @@ -93,7 +93,7 @@ if (BUILD_TESTING)
#if (ENABLE_CATALYST)
# add_test(NAME testCatalystSlice
# COMMAND ${CMAKE_COMMAND}
# -DCATALYST_TEST_DRIVER:FILEPATH=$<TARGET_FILE:oscillator>
# -DCATALYST_TEST_DRIVER:FILEPATH=$<TARGET_FILE:$<TARGET_FILE:oscillator>>
# -DIMAGE_TESTER:FILEPATH=$<TARGET_FILE:CompareImages>
# -DCATALYST_TEST_DIR:PATH=${CMAKE_BINARY_DIR}/Testing
# -DCATALYST_TEST_DATA=${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
2 changes: 1 addition & 1 deletion miniapps/vortex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ if (ENABLE_SENSEI)
list(APPEND libs sensei)
endif()

add_executable(vortex ${sources})
sensei_add_executable(vortex ${sources})
target_link_libraries(vortex PRIVATE ${libs})
6 changes: 3 additions & 3 deletions sensei/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if (ENABLE_ADIOS2)
endif()
endif()

add_library(senseiCore ${senseiCore_sources} ${senseiCore_cuda_sources})
sensei_add_library(senseiCore ${senseiCore_sources} ${senseiCore_cuda_sources})

if (ENABLE_CUDA)
sensei_cuda_target(TARGET senseiCore SOURCES ${senseiCore_cuda_sources})
Expand Down Expand Up @@ -111,7 +111,7 @@ if (ENABLE_ADIOS2)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/python)

add_library(_PythonAnalysis SHARED
sensei_add_library(_PythonAnalysis SHARED
${CMAKE_CURRENT_BINARY_DIR}/_PythonAnalysis.cxx)

# include the directory containing _PythonAnalysis in the rpath
Expand Down Expand Up @@ -158,7 +158,7 @@ if (ENABLE_ADIOS2)
# sensei
# world facing library that users will link to
# contains senseiCore classes, PythonAnalysis, and ConfigurableAnalysis
add_library(sensei ${sensei_sources})
sensei_add_library(sensei ${sensei_sources})

target_include_directories(sensei PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand Down
18 changes: 9 additions & 9 deletions sensei/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@ if (BUILD_TESTING)
##############################################################################
senseiAddTest(testHistogramSerial
SOURCES testHistogram.cpp LIBS sensei EXEC_NAME testHistogram
COMMAND $<TARGET_NAME:testHistogram>
COMMAND $<TARGET_FILE:testHistogram>
LABELS HISTO)

senseiAddTest(testHistogramParallel
PARALLEL ${TEST_NP}
COMMAND $<TARGET_NAME:testHistogram>
COMMAND $<TARGET_FILE:testHistogram>
PROPERTIES
LABELS HISTO)

##############################################################################
senseiAddTest(testHDF5Write
SOURCES testHDF5.cpp LIBS sensei EXEC_NAME testHDF5
PARALLEL ${TEST_NP}
COMMAND $<TARGET_NAME:testHDF5> w 4 n h5test
COMMAND $<TARGET_FILE:testHDF5> w 4 n h5test
FEATURES HDF5)

senseiAddTest(testHDF5Read
PARALLEL ${TEST_NP}
COMMAND $<TARGET_NAME:testHDF5> r h5test.n${TEST_NP}
COMMAND $<TARGET_FILE:testHDF5> r h5test.n${TEST_NP}
FEATURES HDF5
PROPERTIES
DEPENDS testHDF5Write)

##############################################################################
senseiAddTest(testHDF5WriteStreaming
PARALLEL ${TEST_NP}
COMMAND $<TARGET_NAME:testHDF5> w 4 s h5stream
COMMAND $<TARGET_FILE:testHDF5> w 4 s h5stream
FEATURES HDF5
PROPERTIES
LABELS STREAMING)

senseiAddTest(testHDF5ReadStreaming
PARALLEL ${TEST_NP}
COMMAND $<TARGET_NAME:testHDF5> r h5stream.n${TEST_NP} s
COMMAND $<TARGET_FILE:testHDF5> r h5stream.n${TEST_NP} s
FEATURES HDF5
PROPERTIES
DEPENDS testHDF5WriteStreaming
Expand All @@ -45,7 +45,7 @@ if (BUILD_TESTING)
##############################################################################
senseiAddTest(testProgrammableDataAdaptor
PARALLEL 1
COMMAND $<TARGET_NAME:testProgrammableDataAdaptor>
COMMAND $<TARGET_FILE:testProgrammableDataAdaptor>
SOURCES testProgrammableDataAdaptor.cpp
LIBS sensei)

Expand All @@ -59,13 +59,13 @@ if (BUILD_TESTING)
senseiAddTest(testPythonAnalysis
SOURCES testPythonAnalysis.cpp LIBS sensei EXEC_NAME testPythonAnalysis
COMMAND
$<TARGET_NAME:testPythonAnalysis> ${CMAKE_CURRENT_SOURCE_DIR}/testPythonAnalysis.xml
$<TARGET_FILE:testPythonAnalysis> ${CMAKE_CURRENT_SOURCE_DIR}/testPythonAnalysis.xml
FEATURES PYTHON VTK_IO)

senseiAddTest(testPythonAnalysisParallel
PARALLEL ${TEST_NP}
COMMAND
$<TARGET_NAME:testPythonAnalysis> ${CMAKE_CURRENT_SOURCE_DIR}/testPythonAnalysis.xml
$<TARGET_FILE:testPythonAnalysis> ${CMAKE_CURRENT_SOURCE_DIR}/testPythonAnalysis.xml
FEATURES PYTHON VTK_IO)

##############################################################################
Expand Down
Loading

0 comments on commit 1462186

Please sign in to comment.