1 # -*- mode: CMake; tab-width: 2; indent-tabs-mode: nil; -*-
2 #---------------------------------------------------------------------------------------------------
3 # Copyright (C) 2022 Marcus Geelnard
5 # Redistribution and use in source and binary forms, with or without modification, are permitted
6 # provided that the following conditions are met:
8 # 1. Redistributions of source code must retain the above copyright notice, this list of
9 # conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright notice, this list of
12 # conditions and the following disclaimer in the documentation and/or other materials provided
13 # with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
22 # WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 #---------------------------------------------------------------------------------------------------
25 cmake_minimum_required(VERSION 3.10)
26 project(mfat LANGUAGES C)
28 # Enable clang tooling etc.
29 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
31 # We build everything against the C99 standard.
32 set(CMAKE_C_STANDARD 99)
33 set(C_STANDARD_REQUIRED ON)
34 set(CMAKE_C_EXTENSIONS OFF)
36 # Configuration options.
37 set(MFAT_ENABLE_DEBUG OFF CACHE BOOL "Enable debug printing")
38 set(MFAT_ENABLE_WRITE ON CACHE BOOL "Enable write suport")
39 set(MFAT_ENABLE_MBR ON CACHE BOOL "Enable MBR suport")
40 set(MFAT_ENABLE_GPT ON CACHE BOOL "Enable GPT suport")
41 set(MFAT_NUM_CACHED_BLOCKS "2" CACHE STRING "Number of blocks to cache")
42 set(MFAT_NUM_FDS "4" CACHE STRING "Maximum number of file descriptors")
43 set(MFAT_NUM_PARTITIONS "4" CACHE STRING "Maximum number of partitions")
45 list(APPEND defines "MFAT_ENABLE_DEBUG=$<BOOL:${MFAT_ENABLE_DEBUG}>")
46 list(APPEND defines "MFAT_ENABLE_WRITE=$<BOOL:${MFAT_ENABLE_WRITE}>")
47 list(APPEND defines "MFAT_ENABLE_MBR=$<BOOL:${MFAT_ENABLE_MBR}>")
48 list(APPEND defines "MFAT_ENABLE_GPT=$<BOOL:${MFAT_ENABLE_GPT}>")
49 list(APPEND defines "MFAT_NUM_CACHED_BLOCKS=${MFAT_NUM_CACHED_BLOCKS}")
50 list(APPEND defines "MFAT_NUM_FDS=${MFAT_NUM_FDS}")
51 list(APPEND defines "MFAT_NUM_PARTITIONS=${MFAT_NUM_PARTITIONS}")
53 # Define compiler warnings.
54 if((CMAKE_C_COMPILER_ID STREQUAL "GNU") OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
55 list(APPEND options -Wall -Wextra -Wpedantic -Werror)
57 list(APPEND options /W4 /WX)
61 add_library(mfat mfat.c mfat.h)
62 target_compile_definitions(mfat PRIVATE ${defines})
63 target_compile_options(mfat PRIVATE ${options})
64 target_include_directories(mfat PUBLIC .)
67 add_subdirectory(examples)