Skip to content
Snippets Groups Projects
CMakeLists.txt 1.68 KiB
Newer Older
cmake_minimum_required(VERSION 3.17)
project(game_of_life C)
baptiste.coudray's avatar
baptiste.coudray committed

set(CMAKE_C_STANDARD 11)

if (CMAKE_BUILD_TYPE MATCHES Debug)
    set(GCC_COMPILE_FLAGS "-Wall -Wextra -Wconversion -pedantic")
baptiste.coudray's avatar
baptiste.coudray committed
elseif (CMAKE_BUILD_TYPE MATCHES Release)
    set(GCC_COMPILE_FLAGS "-O2")
baptiste.coudray's avatar
baptiste.coudray committed
endif ()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    execute_process(COMMAND sdl2-config --cflags OUTPUT_VARIABLE SDL2_C_FLAGS)
    include_directories(${SDL2_C_FLAGS})
endif ()
baptiste.coudray's avatar
baptiste.coudray committed

if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    include_directories(/usr/local/include)
endif ()

find_package(MPI REQUIRED)
include_directories(${MPI_C_INCLUDE_PATH})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GCC_COMPILE_FLAGS}")

add_custom_command(
        OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/gol.h ${CMAKE_CURRENT_SOURCE_DIR}/gol.c
        COMMAND futhark opencl ${CMAKE_CURRENT_SOURCE_DIR}/gol.fut --library
        DEPENDS gol.fut
)
add_custom_target(futhark_opencl DEPENDS gol.h gol.c)

add_executable(game_of_life_opencl main.c gfx.h gfx.c gol.h gol.c)
add_dependencies(game_of_life_opencl futhark_opencl)

if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    target_link_libraries(game_of_life_opencl "-framework OpenCL" SDL2 ${MPI_C_LIBRARIES})
endif ()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    target_link_libraries(game_of_life_opencl OpenCL SDL2 m ${MPI_C_LIBRARIES})
endif ()

add_executable(game_of_life_opencl_bench benchmark/main.c gol.h gol.c)
add_dependencies(game_of_life_opencl_bench futhark_opencl)

if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    target_link_libraries(game_of_life_opencl_bench "-framework OpenCL" ${MPI_C_LIBRARIES})
endif ()

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    target_link_libraries(game_of_life_opencl_bench OpenCL m ${MPI_C_LIBRARIES})
endif ()