diff --git a/CMake/build.cmake b/CMake/build.cmake index ba5771e3d..2496903d5 100644 --- a/CMake/build.cmake +++ b/CMake/build.cmake @@ -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) @@ -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( + "$<$>:-Wall;-Wextra>" + # Need to explicitly set optimization level to -O3 because some systems default to -O2 + "$<$:-O3>" + "$<$:-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) diff --git a/CMake/cuda.cmake b/CMake/cuda.cmake index 80b877abe..18e20b0d4 100644 --- a/CMake/cuda.cmake +++ b/CMake/cuda.cmake @@ -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) diff --git a/CMake/mpi.cmake b/CMake/mpi.cmake index db9079043..3a89c57e4 100644 --- a/CMake/mpi.cmake +++ b/CMake/mpi.cmake @@ -6,7 +6,7 @@ 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) @@ -14,7 +14,7 @@ elseif (ENABLE_CORI_GPU OR (NOT DEFINED ENABLE_CORI_GPU AND NOT ("$ENV{OPENMPI_D 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()