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

Configure target flags without modifying global space #20

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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)")
Copy link
Contributor

Choose a reason for hiding this comment

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

default to produce static libraries

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")
burlen marked this conversation as resolved.
Show resolved Hide resolved
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")
kwryankrattiger marked this conversation as resolved.
Show resolved Hide resolved
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