cmake_minimum_required (VERSION 2.8.3)
project (Partition)

# Put the final executable in the bin/ directory.
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_LIST_DIR}/bin)

# define PARTITION_CORE to build a leaner partition-only version of the RNA class.
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D PARTITION_CORE")

# Turn the ENABLE_SMP option on to include support for the multi-processor version
# of partition, which requires the OpenMP library.
option (ENABLE_SMP "Build multi-processor version of partition" ON)

# include list of cpp source files.
include(partition-sources.cmake)

if (ENABLE_SMP)
  # Verify the OpenMP library and only add partition-smp if it is found.
  find_package(OpenMP)
  if (OPENMP_FOUND)
    add_executable(partition-smp ${PARTITION_SOURCES})
    # Add the 'SMP' preprocessor definition
    target_compile_definitions(partition-smp PUBLIC SMP)
    # Add the '-fopenmp' compiler flag 
    target_compile_options(partition-smp PUBLIC "${OpenMP_CXX_FLAGS}")
    # Add the '-fopenmp' flag to the linker also.
    target_link_libraries(partition-smp PUBLIC "${OpenMP_CXX_FLAGS}")
    # Also add libraries required for OpenMP (may be blank, depending on compiler)
    target_link_libraries(partition-smp PUBLIC "${OpenMP_CXX_LIB_NAMES}")
  endif(OPENMP_FOUND)
endif (ENABLE_SMP)

# add the `partition` executable
add_executable(partition ${PARTITION_SOURCES})
