root/CMakeLists.txt @ 094cf64d
| 094cf64d | david.sorber | CMAKE_MINIMUM_REQUIRED(VERSION 3.22)
|
|
PROJECT("test_gui")
|
|||
CMAKE_POLICY(SET CMP0054 NEW)
|
|||
# This is a neat trick to prevent in source builds
|
|||
IF (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
|
|||
MESSAGE(FATAL_ERROR "Prevented in-tree build. This is bad practice; you "
|
|||
"should be running cmake from inside a build directory.")
|
|||
ENDIF()
|
|||
################################################################################
|
|||
# OS Flavor Detection
|
|||
################################################################################
|
|||
# Use /etc/os-release to determine Linux flavor and version
|
|||
EXECUTE_PROCESS(COMMAND bash -c "grep \"^NAME=\" /etc/os-release | cut -c7- | rev | cut -c2- | rev"
|
|||
OUTPUT_VARIABLE DISTRIB_ID
|
|||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|||
)
|
|||
EXECUTE_PROCESS(COMMAND bash -c "grep \"^VERSION_ID=\" /etc/os-release | cut -c13- | rev | cut -c2- | rev"
|
|||
OUTPUT_VARIABLE DISTRIB_RELEASE
|
|||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|||
)
|
|||
# Output the parsed ID and release version
|
|||
MESSAGE(STATUS "DISTRIB_ID: " ${DISTRIB_ID})
|
|||
MESSAGE(STATUS "DISTRIB_RELEASE: " ${DISTRIB_RELEASE})
|
|||
################################################################################
|
|||
# Build Configuration
|
|||
################################################################################
|
|||
# Do not let CMake add the build directory path to RPATH. This means that CL/SL
|
|||
# cannot be run from the build directory and must be properly installed.
|
|||
SET(CMAKE_SKIP_BUILD_RPATH TRUE)
|
|||
# Do not allow CMake to find libraries in /usr/local as that's where things
|
|||
# like CUDA end up (e.g. /usr/local/cuda-11.3/)
|
|||
# BIG NOTE: CMAKE_IGNORE_PATH must be a list of full paths *NOT* prefixes
|
|||
SET(CMAKE_IGNORE_PATH "/usr/local/;/usr/local/lib;/usr/local/lib/cmake;"
|
|||
"/usr/local/cuda/targets/x86_64-linux/lib")
|
|||
# Uncomment this line to enable AddressSanitizer; remember to also disable
|
|||
# tcmalloc. NOTE: although the gold linker is faster for general usage it has
|
|||
# several bugs when used with LTO and has therefore been removed from the
|
|||
# line below (-fuse-ld=gold).
|
|||
# SET(CMAKE_CXX_FLAGS "-fsanitize=undefined -fno-sanitize=vptr -fno-omit-frame-pointer")
|
|||
# SET(CMAKE_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer")
|
|||
# SET(CMAKE_CXX_FLAGS "-fsanitize=thread -fno-omit-frame-pointer")
|
|||
#
|
|||
# Set the compile flags
|
|||
#
|
|||
SET(CMAKE_CXX_STANDARD 17)
|
|||
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||
# NOTE: gnu extensions are essentially required for proper 128 bit integer support
|
|||
# See: https://quuxplusone.github.io/blog/2019/02/28/is-int128-integral/
|
|||
SET(CMAKE_CXX_EXTENSIONS ON)
|
|||
SET(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
|||
SET(CMAKE_C_STANDARD 11)
|
|||
SET(CMAKE_C_STANDARD_REQUIRED ON)
|
|||
SET(CMAKE_C_VISIBILITY_PRESET hidden)
|
|||
SET(COMPILE_FLAGS "-g -O3 -march=haswell -mtune=generic")
|
|||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILE_FLAGS}")
|
|||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}")
|
|||
################################################################################
|
|||
# Dependencies
|
|||
################################################################################
|
|||
#FIND_FILE(SDL2_INCLUDE_DIR NAME SDL.h HINTS SDL2)
|
|||
#FIND_LIBRARY(SDL2_LIBRARY NAME SDL2)
|
|||
FIND_PACKAGE(SDL2 REQUIRED)
|
|||
MESSAGE(STATUS "SDL2 include path: ${SDL2_INCLUDE_DIRS}")
|
|||
################################################################################
|
|||
# Include paths
|
|||
################################################################################
|
|||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/imgui)
|
|||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/backend)
|
|||
################################################################################
|
|||
# Source
|
|||
################################################################################
|
|||
SET(imgui_sources
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/imgui/imgui.cpp
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/imgui/imgui_demo.cpp
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/imgui/imgui_draw.cpp
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/imgui/imgui_tables.cpp
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/imgui/imgui_widgets.cpp
|
|||
)
|
|||
SET(backend_sources
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/imgui_impl_sdl2.cpp
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/imgui_impl_sdlrenderer2.cpp
|
|||
)
|
|||
################################################################################
|
|||
# Target: example
|
|||
################################################################################
|
|||
SET(example_sources
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
|
|||
)
|
|||
ADD_EXECUTABLE(example
|
|||
${imgui_sources}
|
|||
${backend_sources}
|
|||
${example_sources})
|
|||
TARGET_INCLUDE_DIRECTORIES(example PUBLIC ${SDL2_INCLUDE_DIRS})
|
|||
TARGET_LINK_LIBRARIES(example ${SDL2_LIBRARIES})
|