<commit_before>project(SAPHRON)
cmake_minimum_required(VERSION 2.8.5)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

# SAPHRON version number.
set(SAPHRON_VERSION_MAJOR "0")
set(SAPHRON_VERSION_MINOR "0")
set(SAPHRON_VERSION_TINY "8")  

# Default type is release
if (NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE "Release")
endif()

# Default is openmp.
set(SAPHRON_OPENMP true CACHE BOOL "Enable OpenMP parallelization")

set(SAPH_USE_LINAL false)
SET(ARMA_PATHS "" CACHE STRING "Search directory for Armadillo")

# BEGIN - Identify linear algebra dependencies.
include(FindArma)
#include(FindQuadMath)
#include(FindgFortran)
include(FindBLAS)
include(FindLAPACK)
include(FindMKL)

# If boost and MPI are found, turn on multi-walker
find_package(Boost
	1.55
	COMPONENTS mpi
)

find_package(MPI)

message(STATUS "")
message(STATUS "      ARMA_FOUND = ${ARMA_FOUND}"  )
#message(STATUS "  QUADMATH_FOUND = ${QUADMATH_FOUND}"  )
#message(STATUS "  GFORTRAN_FOUND = ${GFORTRAN_FOUND}"  )
message(STATUS "      BLAS_FOUND = ${BLAS_FOUND}"    )
message(STATUS "    LAPACK_FOUND = ${LAPACK_FOUND}"  )
message(STATUS "       MKL_FOUND = ${MKL_FOUND}"     )

if(MKL_FOUND)
	set(SAPH_LIBS ${SAPH_LIBS} ${MKL_LIBRARIES})
elseif(LAPACK_FOUND)
	set(SAPH_LIBS ${SAPH_LIBS} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN_LIBRARIES} ${QUADMATH_LIBRARIES})
endif()

message(STATUS "")
message(STATUS "*** SAPHRON will use the following libraries:")
message(STATUS "*** SAPH_LIBS = ${SAPH_LIBS}")
message(STATUS "")
# END - Identify linear algebra dependencies.

# Get Git Information. Taken from OpenMD.
find_package(Git)
if(GIT_FOUND) 
  include(GetGitRevisionDescription)
  get_git_head_revision(GIT_REFSPEC GIT_SHA1)
  MESSAGE(STATUS "Current revision is ${GIT_SHA1}")
  macro(make_release_tarball targetname releasename)
    add_custom_target(${targetname} COMMAND ${GIT_EXECUTABLE} archive --prefix="${releasename}/" --format=tar HEAD --output "${releasename}.tar")
  endmacro()
  make_release_tarball("openmd_release" "openmd-${VERSION_MAJOR}.${VERSION_MINOR}")
else()
  SET(GIT_SHA1 Release)
endif()
 
# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
include_directories("${PROJECT_BINARY_DIR}")

# Find Google Test Framework 
include(ExternalProject)
 
# Set default ExternalProject root directory
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/extern)
 
# Add gtest
# http://stackoverflow.com/questions/9689183/cmake-googletest
ExternalProject_Add(
	googletest
	URL http://googletest.googlecode.com/files/gtest-1.6.0.zip
	# TIMEOUT 10
	# # Force separate output paths for debug and release builds to allow easy
	# # identification of correct lib in subsequent TARGET_LINK_LIBRARIES commands
	# CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
	# -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
	# -Dgtest_force_shared_crt=ON
	# Disable install step
	INSTALL_COMMAND ""
	# Wrap download, configure and build steps in a script to log output
	LOG_DOWNLOAD ON
	LOG_CONFIGURE ON
	LOG_BUILD ON
)
 
# Specify include dir
ExternalProject_Get_Property(googletest source_dir)
set(GTEST_INCLUDE_DIR ${source_dir}/include)

ExternalProject_Get_Property(googletest binary_dir)
set(GTEST_LIBRARY_PATH ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a)
set(GTEST_LIBRARY_MAIN_PATH ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a)
set(GTEST_LIBRARY gtest)
add_library(${GTEST_LIBRARY} UNKNOWN IMPORTED)
set_property(TARGET ${GTEST_LIBRARY} PROPERTY IMPORTED_LOCATION
${GTEST_LIBRARY_PATH} )
add_dependencies(${GTEST_LIBRARY} googletest) 

message(STATUS "")
message(STATUS "*** Google Test Framework will be used for unit tests")
message(STATUS "*** GTEST_LIBRARY_PATH = ${GTEST_LIBRARY_PATH}")
message(STATUS "*** GTEST_INCLUDE_DIR  = ${GTEST_INCLUDE_DIR}")
message(STATUS "")
# End gtest

include_directories("${PROJECT_SOURCE_DIR}/src")
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${ARMA_INCLUDE}")

set(SOURCE
	src/Constraints/Constraint.cpp
	src/DensityOfStates/DOSOrderParameter.cpp
	src/ForceFields/ForceField.cpp
	src/ForceFields/ForceFieldManager.cpp
	src/JSON/jsoncpp.cpp
	src/JSON/schema.cpp
	src/Moves/Move.cpp
	src/Observers/DLMFileObserver.cpp
	src/Observers/JSONObserver.cpp
	src/Observers/XYZObserver.cpp
	src/Particles/Particle.cpp
	src/Simulation/SimObservable.cpp
	src/Simulation/SimObserver.cpp
	src/Simulation/DOSSimulation.cpp
	src/Simulation/Simulation.cpp
	src/Simulation/StandardSimulation.cpp
	src/Utils/Histogram.cpp
	src/Worlds/World.cpp
	src/Validator/RequirementLoader.cpp
)


# Add schema builder
add_custom_target(
    schema ALL
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/__bogus.h
    )

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/__bogus.h
                   WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
                   COMMAND python schema/buildschema.py
                   COMMENT "Generating schema source files"
                   )

add_library(libsaphron ${SOURCE})
set_target_properties(libsaphron PROPERTIES PREFIX "")
target_link_libraries(libsaphron ${SAPH_LIBS})
add_dependencies(libsaphron schema)

add_executable(saphron 
	src/main.cpp 
	src/Simulation/SimBuilder.cpp
)
target_link_libraries(saphron ${SAPH_LIBS} libsaphron)

# Require C++11
set_property(TARGET libsaphron PROPERTY CXX_STANDARD 11)
set_property(TARGET libsaphron PROPERTY CXX_STANDARD_REQUIRED ON)

# Configure flags 
# - Globals
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -pthread -std=c++11")
set_target_properties(libsaphron saphron PROPERTIES COMPILE_FLAGS "-Wall -Wextra")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed")

if(SAPHRON_OPENMP)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fopenmp")
	message(STATUS "*** OpenMP Parallelization enabled!")
endif()

set(MULTI_WALKER OFF)
if(Boost_FOUND AND MPI_CXX_FOUND)
	include_directories(${MPI_CXX_INCLUDE_PATH})
	include_directories(${Boost_INCLUDE_DIRS})
	add_definitions(${MPI_CXX_COMPILE_FLAGS})
	link_directories(${MPI_CXX_LIBRARIES})
	target_link_libraries(libsaphron ${MPI_CXX_LIBRARIES} ${Boost_LIBRARIES})
	message(STATUS "*** MPI multi-walker DOS enabled!")
	message(STATUS "")
	set(MULTI_WALKER ON)
endif()

# Build config header
configure_file (
  "${PROJECT_SOURCE_DIR}/src/config.h.in"
  "${PROJECT_BINARY_DIR}/config.h"<commit_msg>Added manual override to MPI<commit_after>project(SAPHRON)
cmake_minimum_required(VERSION 2.8.5)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

# SAPHRON version number.
set(SAPHRON_VERSION_MAJOR "0")
set(SAPHRON_VERSION_MINOR "0")
set(SAPHRON_VERSION_TINY "8")  

# Default type is release
if (NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE "Release")
endif()

# Default is openmp.
set(SAPHRON_OPENMP true CACHE BOOL "Enable OpenMP parallelization")

# Default is MPI.
set(SAPHRON_MPI true CACHE BOOL "Enable MPI parallelization")

set(SAPH_USE_LINAL false)
SET(ARMA_PATHS "" CACHE STRING "Search directory for Armadillo")

# BEGIN - Identify linear algebra dependencies.
include(FindArma)
#include(FindQuadMath)
#include(FindgFortran)
include(FindBLAS)
include(FindLAPACK)
include(FindMKL)

# If boost and MPI are found, turn on multi-walker
find_package(Boost
	1.55
	COMPONENTS mpi
)

find_package(MPI)

message(STATUS "")
message(STATUS "      ARMA_FOUND = ${ARMA_FOUND}"  )
#message(STATUS "  QUADMATH_FOUND = ${QUADMATH_FOUND}"  )
#message(STATUS "  GFORTRAN_FOUND = ${GFORTRAN_FOUND}"  )
message(STATUS "      BLAS_FOUND = ${BLAS_FOUND}"    )
message(STATUS "    LAPACK_FOUND = ${LAPACK_FOUND}"  )
message(STATUS "       MKL_FOUND = ${MKL_FOUND}"     )

if(MKL_FOUND)
	set(SAPH_LIBS ${SAPH_LIBS} ${MKL_LIBRARIES})
elseif(LAPACK_FOUND)
	set(SAPH_LIBS ${SAPH_LIBS} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${GFORTRAN_LIBRARIES} ${QUADMATH_LIBRARIES})
endif()

message(STATUS "")
message(STATUS "*** SAPHRON will use the following libraries:")
message(STATUS "*** SAPH_LIBS = ${SAPH_LIBS}")
message(STATUS "")
# END - Identify linear algebra dependencies.

# Get Git Information. Taken from OpenMD.
find_package(Git)
if(GIT_FOUND) 
  include(GetGitRevisionDescription)
  get_git_head_revision(GIT_REFSPEC GIT_SHA1)
  MESSAGE(STATUS "Current revision is ${GIT_SHA1}")
  macro(make_release_tarball targetname releasename)
    add_custom_target(${targetname} COMMAND ${GIT_EXECUTABLE} archive --prefix="${releasename}/" --format=tar HEAD --output "${releasename}.tar")
  endmacro()
  make_release_tarball("openmd_release" "openmd-${VERSION_MAJOR}.${VERSION_MINOR}")
else()
  SET(GIT_SHA1 Release)
endif()
 
# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
include_directories("${PROJECT_BINARY_DIR}")

# Find Google Test Framework 
include(ExternalProject)
 
# Set default ExternalProject root directory
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/extern)
 
# Add gtest
# http://stackoverflow.com/questions/9689183/cmake-googletest
ExternalProject_Add(
	googletest
	URL http://googletest.googlecode.com/files/gtest-1.6.0.zip
	# TIMEOUT 10
	# # Force separate output paths for debug and release builds to allow easy
	# # identification of correct lib in subsequent TARGET_LINK_LIBRARIES commands
	# CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
	# -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
	# -Dgtest_force_shared_crt=ON
	# Disable install step
	INSTALL_COMMAND ""
	# Wrap download, configure and build steps in a script to log output
	LOG_DOWNLOAD ON
	LOG_CONFIGURE ON
	LOG_BUILD ON
)
 
# Specify include dir
ExternalProject_Get_Property(googletest source_dir)
set(GTEST_INCLUDE_DIR ${source_dir}/include)

ExternalProject_Get_Property(googletest binary_dir)
set(GTEST_LIBRARY_PATH ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a)
set(GTEST_LIBRARY_MAIN_PATH ${binary_dir}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a)
set(GTEST_LIBRARY gtest)
add_library(${GTEST_LIBRARY} UNKNOWN IMPORTED)
set_property(TARGET ${GTEST_LIBRARY} PROPERTY IMPORTED_LOCATION
${GTEST_LIBRARY_PATH} )
add_dependencies(${GTEST_LIBRARY} googletest) 

message(STATUS "")
message(STATUS "*** Google Test Framework will be used for unit tests")
message(STATUS "*** GTEST_LIBRARY_PATH = ${GTEST_LIBRARY_PATH}")
message(STATUS "*** GTEST_INCLUDE_DIR  = ${GTEST_INCLUDE_DIR}")
message(STATUS "")
# End gtest

include_directories("${PROJECT_SOURCE_DIR}/src")
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${ARMA_INCLUDE}")

set(SOURCE
	src/Constraints/Constraint.cpp
	src/DensityOfStates/DOSOrderParameter.cpp
	src/ForceFields/ForceField.cpp
	src/ForceFields/ForceFieldManager.cpp
	src/JSON/jsoncpp.cpp
	src/JSON/schema.cpp
	src/Moves/Move.cpp
	src/Observers/DLMFileObserver.cpp
	src/Observers/JSONObserver.cpp
	src/Observers/XYZObserver.cpp
	src/Particles/Particle.cpp
	src/Simulation/SimObservable.cpp
	src/Simulation/SimObserver.cpp
	src/Simulation/DOSSimulation.cpp
	src/Simulation/Simulation.cpp
	src/Simulation/StandardSimulation.cpp
	src/Utils/Histogram.cpp
	src/Worlds/World.cpp
	src/Validator/RequirementLoader.cpp
)


# Add schema builder
add_custom_target(
    schema ALL
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/__bogus.h
    )

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/__bogus.h
                   WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
                   COMMAND python schema/buildschema.py
                   COMMENT "Generating schema source files"
                   )

add_library(libsaphron ${SOURCE})
set_target_properties(libsaphron PROPERTIES PREFIX "")
target_link_libraries(libsaphron ${SAPH_LIBS})
add_dependencies(libsaphron schema)

add_executable(saphron 
	src/main.cpp 
	src/Simulation/SimBuilder.cpp
)
target_link_libraries(saphron ${SAPH_LIBS} libsaphron)

# Require C++11
set_property(TARGET libsaphron PROPERTY CXX_STANDARD 11)
set_property(TARGET libsaphron PROPERTY CXX_STANDARD_REQUIRED ON)

# Configure flags 
# - Globals
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -pthread -std=c++11")
set_target_properties(libsaphron saphron PROPERTIES COMPILE_FLAGS "-Wall -Wextra")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed")

if(SAPHRON_OPENMP)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fopenmp")
	message(STATUS "*** OpenMP Parallelization enabled!")
endif()

set(MULTI_WALKER OFF)
if(Boost_FOUND AND MPI_CXX_FOUND AND SAPHRON_MPI)
	include_directories(${MPI_CXX_INCLUDE_PATH})
	include_directories(${Boost_INCLUDE_DIRS})
	add_definitions(${MPI_CXX_COMPILE_FLAGS})
	link_directories(${MPI_CXX_LIBRARIES})
	target_link_libraries(libsaphron ${MPI_CXX_LIBRARIES} ${Boost_LIBRARIES})
	message(STATUS "*** MPI multi-walker DOS enabled!")
	message(STATUS "")
	set(MULTI_WALKER ON)
endif()

# Build config header
configure_file (
  "${PROJECT_SOURCE_DIR}/src/config.h.in"
  "${PROJECT_BINARY_DIR}/config.h"
{'fraction_non_alphanumeric': 0.10577070258686667, 'fraction_numerical': 0.004592071024031839, 'mean_word_length': 6.466857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2678454', 'n_tokens_mistral': 4994, 'n_tokens_neox': 4708, 'n_words': 833}