33 lines
1.0 KiB
CMake
33 lines
1.0 KiB
CMake
cmake_minimum_required(VERSION 3.10)
|
|
|
|
# Set the project name and specify the languages
|
|
project(simworld LANGUAGES C)
|
|
|
|
# Set compiler flags
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat=2 -Wshadow -Wwrite-strings -Wstrict-prototypes")
|
|
|
|
# Specify the source directory
|
|
set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
|
|
|
|
# Create a list of source files
|
|
file(GLOB_RECURSE SOURCES ${SOURCE_DIR}/*.c)
|
|
|
|
# Create the executable from the source files
|
|
add_executable(${PROJECT_NAME} ${SOURCES})
|
|
|
|
# Dependencies
|
|
find_package(PkgConfig REQUIRED)
|
|
pkg_check_modules(LUA REQUIRED lua)
|
|
|
|
target_link_libraries(${PROJECT_NAME} ${LUA_LIBRARIES})
|
|
target_include_directories(${PROJECT_NAME} PRIVATE ${LUA_INCLUDE_DIRS})
|
|
|
|
# `#define DEBUG` if `cmake -DCMAKE_BUILD_TYPE=debug`
|
|
if(CMAKE_BUILD_TYPE STREQUAL "debug")
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_DEBUG)
|
|
else()
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
|
|
target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_RELEASE)
|
|
endif()
|