2018-03-17 19:53:38 +01:00
|
|
|
project(libfort)
|
|
|
|
|
|
|
|
# Required cmake version
|
2018-01-01 09:26:34 +01:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
2018-03-18 14:44:49 +01:00
|
|
|
# Built options
|
2018-03-17 19:53:38 +01:00
|
|
|
option(FORT_CXX_BUILD "Compile with c++ compiler instead of c" OFF)
|
2018-03-18 17:02:53 +01:00
|
|
|
set(FORT_BUILD_TYPE "common" CACHE STRING "Built types (possible values: common, asan, ubsan, coveralls)")
|
2018-03-18 14:44:49 +01:00
|
|
|
|
|
|
|
|
2018-03-18 17:02:53 +01:00
|
|
|
# Determine compiler (pos. values Clang, GNU, Intel, MSVC, AppleClang... (https://cmake.org/cmake/help/v3.0/variable/CMAKE_LANG_COMPILER_ID.html)
|
|
|
|
if(FORT_CXX_BUILD)
|
|
|
|
set(FORT_COMPILER ${CMAKE_CXX_COMPILER_ID})
|
|
|
|
else(FORT_CXX_BUILD)
|
|
|
|
set(FORT_COMPILER ${CMAKE_C_COMPILER_ID})
|
|
|
|
endif(FORT_CXX_BUILD)
|
|
|
|
|
2018-03-18 14:44:49 +01:00
|
|
|
|
2018-01-01 09:26:34 +01:00
|
|
|
|
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
|
|
|
|
|
|
include_directories(include)
|
|
|
|
include_directories(src)
|
|
|
|
|
2018-03-18 14:44:49 +01:00
|
|
|
|
|
|
|
# Turn on warnings
|
2018-03-18 17:02:53 +01:00
|
|
|
if(FORT_COMPILER STREQUAL "MSVC")
|
2018-03-18 14:56:14 +01:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4")
|
2018-03-18 17:02:53 +01:00
|
|
|
else(FORT_COMPILER STREQUAL "MSVC")
|
2018-03-18 14:56:14 +01:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g")
|
2018-03-18 17:02:53 +01:00
|
|
|
endif(FORT_COMPILER STREQUAL "MSVC")
|
2018-03-17 19:53:38 +01:00
|
|
|
|
|
|
|
|
2018-01-01 09:26:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-21 18:46:27 +01:00
|
|
|
FILE(GLOB_RECURSE FortHeaders "include/*.h" "tests/*.h" "src/*.h")
|
2018-01-01 09:26:34 +01:00
|
|
|
add_custom_target(headers SOURCES ${FortHeaders})
|
|
|
|
|
|
|
|
|
2018-01-17 19:22:57 +01:00
|
|
|
set(FORT_SOURCES
|
|
|
|
src/fort.c
|
|
|
|
src/vector.c
|
|
|
|
src/string_buffer.c
|
|
|
|
src/options.c
|
|
|
|
src/cell.c
|
|
|
|
src/row.c
|
|
|
|
src/table.c
|
2018-03-21 18:46:27 +01:00
|
|
|
src/fort_impl.c
|
|
|
|
src/wcwidth.c)
|
|
|
|
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2018-03-17 19:53:38 +01:00
|
|
|
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2018-03-18 10:17:33 +01:00
|
|
|
set(EXAMPLE_SOURCES
|
|
|
|
example/main.c)
|
2018-03-09 13:21:18 +01:00
|
|
|
add_executable(${PROJECT_NAME}_example
|
2018-03-18 10:17:33 +01:00
|
|
|
${EXAMPLE_SOURCES}
|
2018-01-01 09:26:34 +01:00
|
|
|
${FORT_SOURCES})
|
|
|
|
|
|
|
|
|
2018-03-18 10:17:33 +01:00
|
|
|
set(TEST_SOURCES
|
2018-01-01 09:26:34 +01:00
|
|
|
tests/test.c
|
|
|
|
tests/test_vector.c
|
2018-03-19 21:07:18 +01:00
|
|
|
tests/test_string_buffer.c
|
|
|
|
tests/test_table_geometry.c
|
|
|
|
tests/test_table_basic.c
|
|
|
|
tests/test_table_border_style.c
|
|
|
|
tests/test_table_options.c
|
|
|
|
tests/test_utility.c)
|
2018-03-18 10:17:33 +01:00
|
|
|
add_executable(${PROJECT_NAME}_test
|
|
|
|
${FORT_SOURCES}
|
|
|
|
${TEST_SOURCES})
|
2018-01-01 09:26:34 +01:00
|
|
|
|
|
|
|
|
2018-03-18 10:17:33 +01:00
|
|
|
if(FORT_CXX_BUILD)
|
|
|
|
SET_SOURCE_FILES_PROPERTIES( ${FORT_SOURCES} PROPERTIES LANGUAGE CXX)
|
|
|
|
SET_SOURCE_FILES_PROPERTIES( ${EXAMPLE_SOURCES} PROPERTIES LANGUAGE CXX)
|
|
|
|
SET_SOURCE_FILES_PROPERTIES( ${TEST_SOURCES} PROPERTIES LANGUAGE CXX)
|
|
|
|
endif(FORT_CXX_BUILD)
|
2018-01-01 09:26:34 +01:00
|
|
|
|
|
|
|
|
2018-03-18 13:32:02 +01:00
|
|
|
|
2018-03-18 14:44:49 +01:00
|
|
|
|
|
|
|
# Adding sanitizers
|
2018-03-18 17:02:53 +01:00
|
|
|
if(FORT_COMPILER STREQUAL "GNU" OR FORT_COMPILER STREQUAL "Clang")
|
|
|
|
# asan case
|
2018-03-18 14:44:49 +01:00
|
|
|
if(FORT_BUILD_TYPE STREQUAL "asan")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
2018-03-18 17:02:53 +01:00
|
|
|
if(FORT_COMPILER STREQUAL "GNU")
|
2018-03-18 14:44:49 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME}_example asan)
|
|
|
|
target_link_libraries(${PROJECT_NAME}_test asan)
|
2018-03-18 17:02:53 +01:00
|
|
|
endif(FORT_COMPILER STREQUAL "GNU")
|
2018-03-18 14:44:49 +01:00
|
|
|
endif(FORT_BUILD_TYPE STREQUAL "asan")
|
2018-03-18 17:02:53 +01:00
|
|
|
|
|
|
|
#ubsan case
|
2018-03-18 14:44:49 +01:00
|
|
|
if(FORT_BUILD_TYPE STREQUAL "ubsan")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize-recover") #to force fail
|
2018-03-18 17:02:53 +01:00
|
|
|
if(FORT_COMPILER STREQUAL "GNU")
|
2018-03-18 14:44:49 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME}_example ubsan)
|
|
|
|
target_link_libraries(${PROJECT_NAME}_test ubsan)
|
2018-03-18 17:02:53 +01:00
|
|
|
endif(FORT_COMPILER STREQUAL "GNU")
|
2018-03-18 14:44:49 +01:00
|
|
|
endif(FORT_BUILD_TYPE STREQUAL "ubsan")
|
|
|
|
|
2018-03-18 17:02:53 +01:00
|
|
|
#coveralls case
|
|
|
|
if(FORT_BUILD_TYPE STREQUAL "coveralls")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fprofile-arcs -ftest-coverage")
|
|
|
|
endif(FORT_BUILD_TYPE STREQUAL "coveralls")
|
|
|
|
|
|
|
|
endif(FORT_COMPILER STREQUAL "GNU" OR FORT_COMPILER STREQUAL "Clang")
|
2018-03-18 14:44:49 +01:00
|
|
|
|
|
|
|
|
2018-03-18 17:27:09 +01:00
|
|
|
# Hack for some gcc versions
|
|
|
|
if(FORT_COMPILER STREQUAL "GNU")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold")
|
|
|
|
endif(FORT_COMPILER STREQUAL "GNU")
|
|
|
|
|
2018-03-19 21:07:18 +01:00
|
|
|
|