Skip to content

Commit

Permalink
Updates to which and how CXX flags are set
Browse files Browse the repository at this point in the history
Use `add_compiler_options` instead of modifying the CMAKE_CXX_FLAGS directly
Use CMAKE_<OPTION> to better support HPC compilers
Remove micro architecture flags that are not supported by target system compilers (Fujitsu, Spock/Frontier, etc.)
  • Loading branch information
kwryankrattiger committed Nov 12, 2021
1 parent e150b55 commit 7ff877a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
45 changes: 20 additions & 25 deletions CMake/build.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
option(BUILD_SHARED_LIBS OFF "Build shared libraries by default")
option(BUILD_STATIC_EXECS OFF "Link executables statically")
option(BUILD_SHARED_LIBS ON "Build shared libraries (default: ON)")
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 @@ -13,32 +14,26 @@ if(NOT CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

if (NOT MSVC)
if (NOT CMAKE_CXX_FLAGS)
set(tmp "-fPIC -std=c++11 -Wall -Wextra")
if (BUILD_STATIC_EXECS)
set(tmp "${tmp} -static -static-libgcc -static-libstdc++ -pthread -Wl,-Bstatic")
endif()
if ((APPLE) AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
set(tmp "${tmp} -stdlib=libc++")
endif()
if ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
set(tmp "${tmp} -O3 -march=native -mtune=native")
endif()
set(CMAKE_CXX_FLAGS "${tmp}"
CACHE STRING "SENSEI build defaults"
FORCE)
endif()
endif()
if (BUILD_STATIC_EXECS)
string(APPEND CMAKE_CXX_FLAGS "-static -static-libgcc -static-libstdc++ -pthread -Wl,-Bstatic")
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}")

add_compile_options(
"$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-Wall;-Wextra>"
# Need to explicitly set optimization level to -O3 because some systems default to -O2
"$<$<CONFIG:Release>:-O3>"
"$<$<CXX_COMPILER_ID:AppleClang>:-stdlib=libc++>")

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)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2 changes: 1 addition & 1 deletion CMake/cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if(ENABLE_CUDA)

message(STATUS "Created CUDA target ${CUDA_TGT_TARGET}")

target_compile_features(${CUDA_TGT_TARGET} PUBLIC cxx_std_17)
target_compile_features(${CUDA_TGT_TARGET} PUBLIC cxx_std_11)

set_target_properties(${CUDA_TGT_TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(${CUDA_TGT_TARGET} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
Expand Down
4 changes: 2 additions & 2 deletions CMake/mpi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ if (ENABLE_CRAY_MPICH OR (NOT DEFINED ENABLE_CRAY_MPICH AND NOT ("$ENV{CRAY_MPIC
set(MPI_C_INCLUDE_PATH ${CRAY_MPICH_INCLUDE_DIRS} CACHE STRING "MPI include directories")
set(MPI_C_LIBRARIES ${CRAY_MPICH_LDFLAGS} CACHE STRING "MPI link dependencies")
set(MPIEXEC srun CACHE STRING "Platform MPI run equivalent")
set(MPI_C_FOUND CACHE BOOL TRUE "status of MPI config")
set(MPI_C_FOUND TRUE)
elseif (ENABLE_CORI_GPU OR (NOT DEFINED ENABLE_CORI_GPU AND NOT ("$ENV{OPENMPI_DIR}" STREQUAL "")))
set(ENV{PKG_CONFIG_PATH} "$ENV{OPENMPI_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
find_package(PkgConfig QUIET)
pkg_check_modules(CORI_GPU REQUIRED QUIET ompi)
set(MPI_C_INCLUDE_PATH ${CORI_GPU_INCLUDE_DIRS} CACHE STRING "MPI include directories")
set(MPI_C_LIBRARIES ${CORI_GPU_LDFLAGS} CACHE STRING "MPI link dependencies")
set(MPIEXEC srun CACHE STRING "Platform MPI run equivalent")
set(MPI_C_FOUND CACHE BOOL ON "status of MPI config")
set(MPI_C_FOUND ON)
else()
find_package(MPI COMPONENTS C)
endif()
Expand Down

0 comments on commit 7ff877a

Please sign in to comment.