2022-07-18 23:58:15 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.12)
|
|
|
|
project(Cram C)
|
|
|
|
|
2022-07-23 00:00:02 +00:00
|
|
|
option(BUILD_CLI "Build command line executable" ON)
|
2022-07-25 18:53:35 +00:00
|
|
|
option(BUILD_SHARED_LIBS "Build shared library" OFF)
|
2022-07-18 23:58:15 +00:00
|
|
|
|
2023-05-28 00:06:45 +00:00
|
|
|
SET(LIB_MAJOR_VERSION "1")
|
2023-08-22 17:51:39 +00:00
|
|
|
SET(LIB_MINOR_VERSION "1")
|
2022-07-18 23:58:15 +00:00
|
|
|
SET(LIB_REVISION "0")
|
|
|
|
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
|
|
|
|
|
|
|
|
# Build Type
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
# By default, we use Release
|
|
|
|
message(STATUS "Setting build type to 'Release' as none was specified.")
|
|
|
|
set(CMAKE_BUILD_TYPE "Release" CACHE
|
|
|
|
STRING "Choose the type of build." FORCE
|
|
|
|
)
|
|
|
|
# Set the possible values of build type for cmake-gui
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
|
|
|
|
STRINGS "Debug" "Release" "RelWithDebInfo"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Platform Flags
|
|
|
|
if(APPLE)
|
|
|
|
set(CMAKE_MACOSX_RPATH ON)
|
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
|
|
|
|
set(LOBJC "objc")
|
|
|
|
elseif(WIN32)
|
|
|
|
# "Cram.dll", not "libCram.dll"
|
|
|
|
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
|
|
|
endif()
|
|
|
|
if(UNIX)
|
|
|
|
set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
|
|
|
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
|
|
|
set(CMAKE_INSTALL_RPATH ${BIN_RPATH})
|
|
|
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
|
|
|
|
endif()
|
|
|
|
|
2022-07-23 00:00:02 +00:00
|
|
|
if (WIN32)
|
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
2022-07-18 23:58:15 +00:00
|
|
|
endif()
|
|
|
|
|
2022-07-23 00:00:02 +00:00
|
|
|
file(GLOB SOURCE_FILES
|
2022-07-18 23:58:15 +00:00
|
|
|
#Public header
|
|
|
|
include/cram.h
|
|
|
|
#Source
|
2022-07-23 00:00:02 +00:00
|
|
|
lib/stb_image.h
|
|
|
|
lib/stb_ds.h
|
2022-07-18 23:58:15 +00:00
|
|
|
src/cram.c
|
|
|
|
)
|
|
|
|
|
2022-07-23 00:00:02 +00:00
|
|
|
set(LINKSTYLE PRIVATE)
|
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
set(LINKSTYLE PUBLIC)
|
|
|
|
endif()
|
|
|
|
|
2023-10-06 22:02:31 +00:00
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
add_library(Cram SHARED ${SOURCE_FILES})
|
|
|
|
else()
|
|
|
|
add_library(Cram STATIC ${SOURCE_FILES})
|
|
|
|
endif()
|
|
|
|
|
2022-07-23 00:00:02 +00:00
|
|
|
if(BUILD_CLI)
|
2022-08-11 17:26:11 +00:00
|
|
|
file(GLOB CLI_SOURCES
|
2022-07-23 00:00:02 +00:00
|
|
|
tools/cli/lib/stb_image_write.h
|
|
|
|
tools/cli/json_writer.h
|
|
|
|
tools/cli/main.c
|
|
|
|
)
|
|
|
|
|
2022-08-11 17:26:11 +00:00
|
|
|
if(WIN32)
|
2022-08-11 17:34:08 +00:00
|
|
|
list(APPEND CLI_SOURCES tools/cli/lib/windows/dirent.h)
|
2022-08-11 17:26:11 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
add_executable(cramcli ${CLI_SOURCES})
|
|
|
|
|
2022-07-23 00:00:02 +00:00
|
|
|
if(BUILD_SHARED_LIBS)
|
|
|
|
target_link_libraries(cramcli PUBLIC Cram)
|
|
|
|
else()
|
|
|
|
target_link_libraries(cramcli PRIVATE Cram)
|
|
|
|
endif()
|
2022-08-11 17:26:11 +00:00
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
target_include_directories(cramcli PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/cli/lib/windows>)
|
|
|
|
endif()
|
2022-07-23 00:00:02 +00:00
|
|
|
endif()
|
|
|
|
|
2023-10-06 22:02:31 +00:00
|
|
|
|
|
|
|
# Build flags
|
|
|
|
if(NOT MSVC)
|
|
|
|
set_property(TARGET Cram PROPERTY COMPILE_FLAGS "-std=gnu99 -Wall -Wno-strict-aliasing -pedantic")
|
|
|
|
target_link_libraries(Cram PUBLIC m)
|
2022-07-23 00:00:02 +00:00
|
|
|
endif()
|
|
|
|
|
2022-07-18 23:58:15 +00:00
|
|
|
# includes
|
|
|
|
target_include_directories(Cram PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lib>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
2022-07-23 00:00:02 +00:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/cli/lib>
|
2022-07-18 23:58:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Soname
|
|
|
|
set_target_properties(Cram PROPERTIES OUTPUT_NAME "Cram"
|
|
|
|
VERSION ${LIB_VERSION}
|
|
|
|
SOVERSION ${LIB_MAJOR_VERSION}
|
|
|
|
)
|