aboutsummaryrefslogtreecommitdiffstats
path: root/examples/CMakeLists.txt
blob: 0430e9f285a71cc4f59d1a1d150c130af945e768 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
include_directories(
  ${PROJECT_SOURCE_DIR}/include
)

# These examples use the standard separate compilation
file(GLOB SOURCES_IDIOMATIC_TARGETS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")

string( REPLACE ".cpp" "" BASENAMES_IDIOMATIC_TARGETS "${SOURCES_IDIOMATIC_TARGETS}" )

set( SDL_TARGETS_IDIOMATIC_TARGETS "" )
set( SDL_TARGETS_IDIOMATIC_FILES "" )
foreach( name ${BASENAMES_IDIOMATIC_TARGETS} )
    set(target ${name})
    set( SDL_TARGETS_IDIOMATIC_TARGETS "${SDL_TARGETS_IDIOMATIC_TARGETS};${target}" )
    add_executable(${target} ${name}.cpp)
    target_link_libraries(${target} ${SDL2_LIBS} ${CMAKE_THREAD_LIBS_INIT})
    if (DEFINED EMSCRIPTEN)
        configure_file(${name}.html ${name}.html COPYONLY)
        set( SDL_TARGETS_IDIOMATIC_FILES "${SDL_TARGETS_IDIOMATIC_FILES};${CMAKE_CURRENT_BINARY_DIR}/${name}.wasm;${name}.html" )
    endif()
endforeach()

if (NOT DEFINED EMSCRIPTEN)
    set( SFML_TARGETS_IDIOMATIC_TARGETS "" )
    if(USE_SFML)
        foreach( name ${BASENAMES_IDIOMATIC_TARGETS} )
            set( SFML_TARGETS_IDIOMATIC_TARGETS "${SFML_TARGETS_IDIOMATIC_TARGETS};${name}_sfml" )
            target_link_libraries(${name}_sfml sfml-graphics sfml-window sfml-system ${CMAKE_THREAD_LIBS_INIT})
        endforeach()
    endif(USE_SFML)
endif()

install(TARGETS ${SDL_TARGETS_IDIOMATIC_TARGETS} ${SFML_TARGETS_IDIOMATIC_TARGETS} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${SDL_TARGETS_IDIOMATIC_FILES} ${SFML_TARGETS_IDIOMATIC_FILES} DESTINATION ${CMAKE_INSTALL_BINDIR})