Advertisement
Creepinson

Untitled

Apr 5th, 2021
1,522
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
  2. project(ChatlabGame)
  3.  
  4. # Add .lib files
  5. link_directories(${CMAKE_SOURCE_DIR}/lib)
  6.  
  7. # Configure assets header file
  8. configure_file(src/helpers/RootDir.h.in src/helpers/RootDir.h)
  9. include_directories(${CMAKE_BINARY_DIR}/src)
  10.  
  11. # Define source files
  12. file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp")
  13. file(GLOB_RECURSE HEADERS RELATIVE ${CMAKE_SOURCE_DIR} "src/*.h")
  14.  
  15. # Define the executable
  16. add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
  17.  
  18. include_directories(
  19.         "${CMAKE_SOURCE_DIR}/src"
  20.         "${CMAKE_SOURCE_DIR}/lib"
  21. )
  22.  
  23. # We need a CMAKE_DIR with some code to find external dependencies
  24. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/lib/")
  25.  
  26. # glfw
  27. add_subdirectory(lib/glfw EXCLUDE_FROM_ALL)
  28.  
  29. # glew
  30. add_subdirectory(lib/glew EXCLUDE_FROM_ALL)
  31. target_include_directories(${PROJECT_NAME} PRIVATE
  32.         ${CMAKE_SOURCE_DIR}/lib/glew/include
  33.         )
  34. FIND_PACKAGE(GLEW)
  35.  
  36. # Put all libraries into a variable
  37. set(LIBS glfw GL GLEW)
  38.  
  39. # Define the include DIRs
  40. include_directories(
  41.         "${CMAKE_SOURCE_DIR}/src"
  42.         "${CMAKE_SOURCE_DIR}/include"
  43. )
  44.  
  45. # Define the link libraries
  46. target_link_libraries(${PROJECT_NAME} ${LIBS})
  47.  
  48. set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)
  49.  
  50.  
  51. # Create virtual folders to make it look nicer in VS
  52. if (MSVC_IDE)
  53.     # Macro to preserve source files hierarchy in the IDE
  54.     macro(GroupSources curdir)
  55.         file(GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*)
  56.  
  57.         foreach (child ${children})
  58.             if (IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${curdir}/${child})
  59.                 GroupSources(${curdir}/${child})
  60.             else ()
  61.                 string(REPLACE "/" "\\" groupname ${curdir})
  62.                 string(REPLACE "src" "Sources" groupname ${groupname})
  63.                 source_group(${groupname} FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child})
  64.             endif ()
  65.         endforeach ()
  66.     endmacro()
  67.  
  68.     # Run macro
  69.     GroupSources(src)
  70. endif ()
  71.  
  72. # Copy dlls
  73. if (WIN32)
  74.     add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
  75.             COMMAND ${CMAKE_COMMAND} -E copy_directory
  76.             "${PROJECT_SOURCE_DIR}/dlls"
  77.             $<TARGET_FILE_DIR:${PROJECT_NAME}>)
  78. endif ()
  79.  
Advertisement
RAW Paste Data Copied
Advertisement