<commit_before>
# (2.8 has ExternalProject support)
cmake_minimum_required(VERSION 2.8)
include(ExternalProject)

option(TRACING "Sample statistics with VTrace at regular intervals." OFF)
option(PROFILING "Sample profile with GPerftools at regular intervals." OFF)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)

# if( NOT DEFINED ENV{CXX} )
#   message(FATAL_ERROR "you must set CC & CXX environment variables!")
# endif()

# set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.clang.3_4")

project(Grappa)

set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")

set(CMAKE_C_FLAGS_DEBUG "-O1 -DDEBUG -g -DGUARD_PAGES_ON_STACK")
set(CMAKE_CXX_FLAGS_DEBUG "-O1 -DDEBUG -g -DGUARD_PAGES_ON_STACK")

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
enable_testing()
# set(CMAKE_BUILD_TYPE RelWithDebInfo)
site_name(MACHINENAME)


###########################
# Use RUNPATH if available
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH  FALSE)
# use final INSTALL_RPATH even in build tree (this lets us manually add things to CMAKE_INSTALL_RPATH)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_RPATH}")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)

# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1") # not a system directory
  set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")

## Not setting runpath because having MPI libs in LD_LIBRARY_PATH was messing up VampirTrace's ability to find its own libs. Maybe there's another way to fix this, but it just seems more robust (for now) to not allow LD_LIBRARY_PATH to affect our libs (after configure uses it to find them).
# set runpath, too
# if(NOT APPLE)
#   set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags")
# endif()

##### </RUNPATH> ########


#############################################################################
# configure profiling and tracing
#############################################################################
if(TRACING)
  # TODO:Fix VampirTrace support
  message("-- Tracing enabled.")
  
  set(GOOGLE_PROFILER ON)

  add_definitions(-DVTRACE_SAMPLED -DVTRACE -DGOOGLE_PROFILER)

  ### TODO: one of these is correct
  include_directories("${THIRD_PARTY_ROOT}/include/vampirtrace")
  
  include_directories("${VAMPIR_ROOT}/include/vampirtrace")
  link_directories("${VAMPIR_ROOT}/lib")
  
  # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finstrument-functions")
  # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finstrument-functions")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -vt:inst manual")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -vt:inst manual")
  
  # list(APPEND GRAPPA_LIBS vt otf z papi dl m)
  
  # set(CMAKE_C_FLAGS "-vt:cc  ${CMAKE_C_FLAGS} -pthread")
  # set(CMAKE_CXX_FLAGS "-vt:cxx ${GCC_BASE}/bin/g++ ${CMAKE_CXX_FLAGS}")
  # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --as-needed --whole-archive -lvt --no-whole-archive --no-as-needed -lopen-trace-format -lz -lpapi -ldl -lm")

  if(NOT THIRD_PARTY_ROOT STREQUAL ${VAMPIR_ROOT})
    set(CMAKE_INSTALL_RPATH "${VAMPIR_ROOT}/lib:${CMAKE_INSTALL_RPATH}")
  endif()
endif()

if(PROFILING)
  message("-- Profiling enabled.")
  set(GOOGLE_PROFILER ON)
endif()

if( GOOGLE_PROFILER )
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
  add_definitions( -DGOOGLE_PROFILER )
endif()

# global C++ flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Winline -Wno-inline -mno-red-zone")
add_definitions("-DENABLE_RDMA_AGGREGATOR")

# TODO: use -stdlib=libc++ too?




#########################################
# Determine third party tools to build
set(third_party_docstring "Directory to look for/install third-party stuff to.")
if(NOT THIRD_PARTY_ROOT)
  set(THIRD_PARTY_ROOT "${CMAKE_BINARY_DIR}/third-party" CACHE PATH "${third_party_docstring}")
else()
  set(THIRD_PARTY_ROOT "${THIRD_PARTY_ROOT}" CACHE PATH "${third_party_docstring}")
endif()
include_directories("${THIRD_PARTY_ROOT}/include")
link_directories("${THIRD_PARTY_ROOT}/lib")
set(CMAKE_INSTALL_RPATH "${THIRD_PARTY_ROOT}/lib:${CMAKE_INSTALL_RPATH}")

######################################################################
# MPI
######################################################################
find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
list(APPEND GRAPPA_LIBS ${MPI_CXX_LIBRARIES})

######################################################################
# PMI: helpful for some systems with Slurm
######################################################################
find_library(PMI_FOUND pmi)
if(PMI_FOUND)
  list(APPEND GRAPPA_LIBS pmi)
endif()

######################################################################
# Pthreads
######################################################################
if(NOT APPLE)
  find_library(PTHREADS_FOUND pthread REQUIRED)
  list(APPEND GRAPPA_LIBS pthread)
endif()

######################################################################
# POSIX realtime extensions
######################################################################
if(NOT APPLE)
  find_library(RT_FOUND rt REQUIRED)
  list(APPEND GRAPPA_LIBS rt)
endif()

######################################################################
# Google flags
# in theory, it may come from third-party or from system directories,
# but for simplicity now just use the one in third-party.
######################################################################
find_library(GFLAGS_FOUND libgflags.a gflags ${THIRD_PARTY_ROOT}/lib NO_CMAKE_SYSTEM_PATH)
message("GFLAGS_FOUND: ${GFLAGS_FOUND}")
list(APPEND GRAPPA_LIBS libgflags.a)

######################################################################
# Google logging (Grappa-customized)
######################################################################
find_library(GLOG_FOUND libglog.a glog ${THIRD_PARTY_ROOT}/lib NO_CMAKE_SYSTEM_PATH)
message("GLOG_FOUND: ${GLOG_FOUND}")
list(APPEND GRAPPA_LIBS libglog.a)
list(APPEND GRAPPA_ENV
  GLOG_logtostderr=1
  GLOG_v=1
)

######################################################################
# Graph500 Kronecker generator (Grappa-customized)
######################################################################
find_library(GRAPH500_FOUND libgraph500-generator.a graph500-generator ${THIRD_PARTY_ROOT}/graph500-generator NO_CMAKE_SYSTEM_PATH)
message("GRAPH500_FOUND: ${GRAPH500_FOUND}")
include_directories("${CMAKE_SOURCE_DIR}/third-party/graph500-generator")
link_directories("${THIRD_PARTY_ROOT}/graph500-generator")
list(APPEND GRAPPA_LIBS libgraph500-generator.a)

######################################################################
# Boost
######################################################################
set(BOOST_COMPONENTS filesystem system unit_test_framework)
<commit_msg>switch on verbose flag temporarily to debug integration tests<commit_after>
# (2.8 has ExternalProject support)
cmake_minimum_required(VERSION 2.8)
include(ExternalProject)

option(TRACING "Sample statistics with VTrace at regular intervals." OFF)
option(PROFILING "Sample profile with GPerftools at regular intervals." OFF)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)

# if( NOT DEFINED ENV{CXX} )
#   message(FATAL_ERROR "you must set CC & CXX environment variables!")
# endif()

# set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.clang.3_4")

project(Grappa)

set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")

set(CMAKE_C_FLAGS_DEBUG "-O1 -DDEBUG -g -DGUARD_PAGES_ON_STACK")
set(CMAKE_CXX_FLAGS_DEBUG "-O1 -DDEBUG -g -DGUARD_PAGES_ON_STACK")

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
enable_testing()
# set(CMAKE_BUILD_TYPE RelWithDebInfo)
site_name(MACHINENAME)


###########################
# Use RUNPATH if available
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH  FALSE)
# use final INSTALL_RPATH even in build tree (this lets us manually add things to CMAKE_INSTALL_RPATH)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_RPATH}")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)

# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1") # not a system directory
  set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")

## Not setting runpath because having MPI libs in LD_LIBRARY_PATH was messing up VampirTrace's ability to find its own libs. Maybe there's another way to fix this, but it just seems more robust (for now) to not allow LD_LIBRARY_PATH to affect our libs (after configure uses it to find them).
# set runpath, too
# if(NOT APPLE)
#   set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags")
# endif()

##### </RUNPATH> ########


#############################################################################
# configure profiling and tracing
#############################################################################
if(TRACING)
  # TODO:Fix VampirTrace support
  message("-- Tracing enabled.")
  
  set(GOOGLE_PROFILER ON)

  add_definitions(-DVTRACE_SAMPLED -DVTRACE -DGOOGLE_PROFILER)

  ### TODO: one of these is correct
  include_directories("${THIRD_PARTY_ROOT}/include/vampirtrace")
  
  include_directories("${VAMPIR_ROOT}/include/vampirtrace")
  link_directories("${VAMPIR_ROOT}/lib")
  
  # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finstrument-functions")
  # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finstrument-functions")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -vt:inst manual")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -vt:inst manual")
  
  # list(APPEND GRAPPA_LIBS vt otf z papi dl m)
  
  # set(CMAKE_C_FLAGS "-vt:cc  ${CMAKE_C_FLAGS} -pthread")
  # set(CMAKE_CXX_FLAGS "-vt:cxx ${GCC_BASE}/bin/g++ ${CMAKE_CXX_FLAGS}")
  # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --as-needed --whole-archive -lvt --no-whole-archive --no-as-needed -lopen-trace-format -lz -lpapi -ldl -lm")

  if(NOT THIRD_PARTY_ROOT STREQUAL ${VAMPIR_ROOT})
    set(CMAKE_INSTALL_RPATH "${VAMPIR_ROOT}/lib:${CMAKE_INSTALL_RPATH}")
  endif()
endif()

if(PROFILING)
  message("-- Profiling enabled.")
  set(GOOGLE_PROFILER ON)
endif()

if( GOOGLE_PROFILER )
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
  add_definitions( -DGOOGLE_PROFILER )
endif()

# global C++ flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Winline -Wno-inline -mno-red-zone")
add_definitions("-DENABLE_RDMA_AGGREGATOR")

# TODO: use -stdlib=libc++ too?




#########################################
# Determine third party tools to build
set(third_party_docstring "Directory to look for/install third-party stuff to.")
if(NOT THIRD_PARTY_ROOT)
  set(THIRD_PARTY_ROOT "${CMAKE_BINARY_DIR}/third-party" CACHE PATH "${third_party_docstring}")
else()
  set(THIRD_PARTY_ROOT "${THIRD_PARTY_ROOT}" CACHE PATH "${third_party_docstring}")
endif()
include_directories("${THIRD_PARTY_ROOT}/include")
link_directories("${THIRD_PARTY_ROOT}/lib")
set(CMAKE_INSTALL_RPATH "${THIRD_PARTY_ROOT}/lib:${CMAKE_INSTALL_RPATH}")

######################################################################
# MPI
######################################################################
find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
list(APPEND GRAPPA_LIBS ${MPI_CXX_LIBRARIES})

######################################################################
# PMI: helpful for some systems with Slurm
######################################################################
find_library(PMI_FOUND pmi)
if(PMI_FOUND)
  list(APPEND GRAPPA_LIBS pmi)
endif()

######################################################################
# Pthreads
######################################################################
if(NOT APPLE)
  find_library(PTHREADS_FOUND pthread REQUIRED)
  list(APPEND GRAPPA_LIBS pthread)
endif()

######################################################################
# POSIX realtime extensions
######################################################################
if(NOT APPLE)
  find_library(RT_FOUND rt REQUIRED)
  list(APPEND GRAPPA_LIBS rt)
endif()

######################################################################
# Google flags
# in theory, it may come from third-party or from system directories,
# but for simplicity now just use the one in third-party.
######################################################################
find_library(GFLAGS_FOUND libgflags.a gflags ${THIRD_PARTY_ROOT}/lib NO_CMAKE_SYSTEM_PATH)
message("GFLAGS_FOUND: ${GFLAGS_FOUND}")
list(APPEND GRAPPA_LIBS libgflags.a)

######################################################################
# Google logging (Grappa-customized)
######################################################################
find_library(GLOG_FOUND libglog.a glog ${THIRD_PARTY_ROOT}/lib NO_CMAKE_SYSTEM_PATH)
message("GLOG_FOUND: ${GLOG_FOUND}")
list(APPEND GRAPPA_LIBS libglog.a)
list(APPEND GRAPPA_ENV
  GLOG_logtostderr=1
  GLOG_v=1
)

######################################################################
# Graph500 Kronecker generator (Grappa-customized)
######################################################################
find_library(GRAPH500_FOUND libgraph500-generator.a graph500-generator ${THIRD_PARTY_ROOT}/graph500-generator NO_CMAKE_SYSTEM_PATH)
message("GRAPH500_FOUND: ${GRAPH500_FOUND}")
include_directories("${CMAKE_SOURCE_DIR}/third-party/graph500-generator")
link_directories("${THIRD_PARTY_ROOT}/graph500-generator")
list(APPEND GRAPPA_LIBS libgraph500-generator.a)

######################################################################
# Boost
######################################################################
set(BOOST_COMPONENTS filesystem system unit_test_framework)
set(VERBOSE TRUE)

{'fraction_non_alphanumeric': 0.27604740904079383, 'fraction_numerical': 0.006339581036383682, 'mean_word_length': 8.087664370695054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2169776', 'n_tokens_mistral': 4990, 'n_tokens_neox': 4550, 'n_words': 950}