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-31 12:33:37 +02:00
|
|
|
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
|
2018-01-01 09:26:34 +01:00
|
|
|
|
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-31 12:33:37 +02:00
|
|
|
option(FORT_ENABLE_ASTYLE "Enable astyle" OFF)
|
2018-11-16 20:25:40 +01:00
|
|
|
option(FORT_ENABLE_WCHAR "Enable wchar support" ON)
|
2018-04-01 12:40:56 +02:00
|
|
|
set(FORT_BUILD_TYPE "common" CACHE STRING "Build types(common, asan, ubsan, coveralls)")
|
2018-03-18 14:44:49 +01:00
|
|
|
|
|
|
|
|
2018-04-01 12:40:56 +02:00
|
|
|
# Determine compiler (pos. values Clang, GNU, Intel, MSVC, AppleClang...
|
|
|
|
# (https://cmake.org/cmake/help/v3.0/variable/CMAKE_LANG_COMPILER_ID.html)
|
2018-03-18 17:02:53 +01:00
|
|
|
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)
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
|
2018-04-16 20:01:45 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Add WChar support for the build
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-11-16 19:16:05 +01:00
|
|
|
if(FORT_ENABLE_WCHAR)
|
|
|
|
add_definitions(-DFT_CONGIG_HAVE_WCHAR)
|
|
|
|
endif(FORT_ENABLE_WCHAR)
|
|
|
|
|
2018-04-16 20:01:45 +02:00
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Includes
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-05-06 15:50:08 +02:00
|
|
|
include_directories(lib)
|
2018-01-01 09:26:34 +01:00
|
|
|
include_directories(src)
|
2018-05-06 15:21:45 +02:00
|
|
|
include_directories(tests)
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2018-03-18 14:44:49 +01:00
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
|
|
|
|
|
2018-04-16 20:01:45 +02:00
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Warnings
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-04-16 20:39:29 +02:00
|
|
|
if("${FORT_COMPILER}" STREQUAL "MSVC")
|
2018-03-18 14:56:14 +01:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4")
|
2018-04-01 15:20:15 +02:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W4")
|
2018-04-16 20:39:29 +02:00
|
|
|
else("${FORT_COMPILER}" STREQUAL "MSVC")
|
2018-11-17 08:44:35 +01:00
|
|
|
set(ADDITIONAL_WARNINGS "\
|
|
|
|
-Wduplicated-cond \
|
|
|
|
-Wlogical-op \
|
|
|
|
-Wdouble-promotion \
|
|
|
|
-Wshadow \
|
|
|
|
-Wformat=2 \
|
|
|
|
-Wno-variadic-macros \
|
|
|
|
-Wcast-align \
|
|
|
|
")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -Wextra -Werror -std=c99 -Wpedantic ${ADDITIONAL_WARNINGS}")
|
|
|
|
|
|
|
|
set(ADDITIONAL_WARNINGS "${ADDITIONAL_WARNINGS} -Wuseless-cast ")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -Wextra -Werror -std=c++11 ${ADDITIONAL_WARNINGS}")
|
2018-04-16 20:39:29 +02:00
|
|
|
endif("${FORT_COMPILER}" STREQUAL "MSVC")
|
2018-03-17 19:53:38 +01:00
|
|
|
|
|
|
|
|
2018-01-01 09:26:34 +01:00
|
|
|
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Sources and executables
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2018-05-06 15:50:08 +02:00
|
|
|
FILE(GLOB_RECURSE FortHeaders "lib/*.h" "lib/*.hpp" "tests/*.h" "src/*.h")
|
2018-01-01 09:26:34 +01:00
|
|
|
add_custom_target(headers SOURCES ${FortHeaders})
|
|
|
|
|
|
|
|
|
2018-05-06 15:36:53 +02:00
|
|
|
set(FORT_DEV_SOURCES
|
|
|
|
src/fort_impl.c
|
2018-01-17 19:22:57 +01:00
|
|
|
src/vector.c
|
|
|
|
src/string_buffer.c
|
2018-11-03 21:50:30 +01:00
|
|
|
src/properties.c
|
2018-01-17 19:22:57 +01:00
|
|
|
src/cell.c
|
|
|
|
src/row.c
|
|
|
|
src/table.c
|
2018-05-06 15:36:53 +02:00
|
|
|
src/fort_utils.c
|
2018-03-21 18:46:27 +01:00
|
|
|
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-05-06 21:51:41 +02:00
|
|
|
lib/fort.c)
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2018-04-01 10:36:52 +02:00
|
|
|
set(EXAMPLE_CPP_SOURCES
|
|
|
|
example/main.cpp)
|
|
|
|
add_executable(${PROJECT_NAME}_example_cpp
|
|
|
|
${EXAMPLE_CPP_SOURCES}
|
2018-05-06 21:51:41 +02:00
|
|
|
lib/fort.c)
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2018-05-06 15:21:45 +02:00
|
|
|
set(TEST_SOURCES_DEV
|
|
|
|
tests/main_test.c
|
|
|
|
tests/wb_tests/test_vector.c
|
|
|
|
tests/wb_tests/test_string_buffer.c
|
|
|
|
tests/wb_tests/test_table_geometry.c
|
|
|
|
tests/bb_tests/test_table_basic.c
|
|
|
|
tests/bb_tests/test_table_border_style.c
|
2018-11-03 21:50:30 +01:00
|
|
|
tests/bb_tests/test_table_properties.c
|
2018-05-06 15:21:45 +02:00
|
|
|
tests/bb_tests/test_memory_errors.c
|
2018-05-06 15:28:18 +02:00
|
|
|
tests/test_utils.c)
|
2018-05-06 15:21:45 +02:00
|
|
|
add_executable(${PROJECT_NAME}_test_dev
|
2018-05-06 15:36:53 +02:00
|
|
|
${FORT_DEV_SOURCES}
|
2018-05-06 15:21:45 +02:00
|
|
|
${TEST_SOURCES_DEV})
|
|
|
|
|
|
|
|
target_compile_definitions(${PROJECT_NAME}_test_dev
|
|
|
|
PUBLIC FORT_WB_TESTING_ENABLED=1)
|
|
|
|
|
2018-03-18 10:17:33 +01:00
|
|
|
set(TEST_SOURCES
|
2018-05-06 15:21:45 +02:00
|
|
|
tests/main_test.c
|
|
|
|
tests/bb_tests/test_table_basic.c
|
|
|
|
tests/bb_tests/test_table_border_style.c
|
2018-11-03 21:50:30 +01:00
|
|
|
tests/bb_tests/test_table_properties.c
|
2018-05-06 15:21:45 +02:00
|
|
|
tests/bb_tests/test_memory_errors.c
|
2018-05-06 15:28:18 +02:00
|
|
|
tests/test_utils.c)
|
2018-03-18 10:17:33 +01:00
|
|
|
add_executable(${PROJECT_NAME}_test
|
2018-05-06 15:50:08 +02:00
|
|
|
lib/fort.c
|
2018-03-18 10:17:33 +01:00
|
|
|
${TEST_SOURCES})
|
2018-01-01 09:26:34 +01:00
|
|
|
|
|
|
|
|
2018-07-25 21:37:10 +02:00
|
|
|
set(TEST_SOURCES_CPP
|
|
|
|
tests/main_test_cpp.cpp
|
|
|
|
tests/bb_tests_cpp/test_table_basic.cpp
|
|
|
|
tests/test_utils.c)
|
|
|
|
add_executable(${PROJECT_NAME}_test_cpp
|
|
|
|
lib/fort.c
|
|
|
|
${TEST_SOURCES_CPP})
|
|
|
|
|
2018-03-18 10:17:33 +01:00
|
|
|
if(FORT_CXX_BUILD)
|
2018-05-06 15:36:53 +02:00
|
|
|
SET_SOURCE_FILES_PROPERTIES( ${FORT_DEV_SOURCES} PROPERTIES LANGUAGE CXX)
|
2018-03-18 10:17:33 +01:00
|
|
|
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-09-01 18:42:57 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Set preprocessor macros for all test builds
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
target_compile_definitions(${PROJECT_NAME}_test_dev PRIVATE FT_TEST_BUILD=1)
|
|
|
|
target_compile_definitions(${PROJECT_NAME}_test_cpp PRIVATE FT_TEST_BUILD=1)
|
|
|
|
target_compile_definitions(${PROJECT_NAME}_test PRIVATE FT_TEST_BUILD=1)
|
2018-03-18 13:32:02 +01:00
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
2018-04-01 12:40:56 +02:00
|
|
|
# Sanitizers
|
2018-03-31 12:33:37 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
2018-03-18 14:44:49 +01:00
|
|
|
|
2018-04-16 20:39:29 +02:00
|
|
|
if("${FORT_COMPILER}" STREQUAL "GNU" OR "${FORT_COMPILER}" STREQUAL "Clang")
|
2018-03-18 17:02:53 +01:00
|
|
|
# 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-04-01 15:12:43 +02:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
2018-04-16 20:39:29 +02: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-04-01 15:12:43 +02:00
|
|
|
target_link_libraries(${PROJECT_NAME}_example_cpp asan)
|
2018-04-16 20:39:29 +02: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")
|
2018-04-01 12:40:56 +02:00
|
|
|
# -fno-sanitize-recover option is used to force faild
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize-recover")
|
2018-04-01 15:12:43 +02:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize-recover")
|
2018-04-16 20:39:29 +02:00
|
|
|
if("${FORT_COMPILER}" STREQUAL "GNU")
|
2018-03-18 14:44:49 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME}_example ubsan)
|
2018-04-01 10:36:52 +02:00
|
|
|
target_link_libraries(${PROJECT_NAME}_example_cpp ubsan)
|
2018-03-18 14:44:49 +01:00
|
|
|
target_link_libraries(${PROJECT_NAME}_test ubsan)
|
2018-04-16 20:39:29 +02:00
|
|
|
endif("${FORT_COMPILER}" STREQUAL "GNU")
|
|
|
|
endif("${FORT_COMPILER}" STREQUAL "ubsan")
|
2018-03-18 14:44:49 +01:00
|
|
|
|
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")
|
2018-04-01 15:12:43 +02:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
|
|
|
|
#target_link_libraries(${PROJECT_NAME}_example_cpp gcov)
|
2018-03-18 17:02:53 +01:00
|
|
|
endif(FORT_BUILD_TYPE STREQUAL "coveralls")
|
|
|
|
|
2018-04-16 20:39:29 +02:00
|
|
|
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
|
2018-04-16 20:39:29 +02:00
|
|
|
if("${FORT_COMPILER}" STREQUAL "GNU")
|
2018-03-18 17:27:09 +01:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold")
|
2018-04-01 15:20:15 +02:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold")
|
2018-04-16 20:39:29 +02:00
|
|
|
endif("${FORT_COMPILER}" STREQUAL "GNU")
|
2018-03-18 17:27:09 +01:00
|
|
|
|
2018-03-19 21:07:18 +01:00
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Astyle
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if(FORT_ENABLE_ASTYLE)
|
|
|
|
list(APPEND ASTYLE_CMAKE_ARGS
|
|
|
|
"-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}"
|
|
|
|
)
|
|
|
|
|
|
|
|
ExternalProject_Add(
|
|
|
|
astyle
|
|
|
|
GIT_REPOSITORY https://github.com/Bareflank/astyle.git
|
|
|
|
GIT_TAG v1.2
|
|
|
|
GIT_SHALLOW 1
|
|
|
|
CMAKE_ARGS ${ASTYLE_CMAKE_ARGS}
|
|
|
|
PREFIX ${CMAKE_BINARY_DIR}/external/astyle/prefix
|
|
|
|
TMP_DIR ${CMAKE_BINARY_DIR}/external/astyle/tmp
|
|
|
|
STAMP_DIR ${CMAKE_BINARY_DIR}/external/astyle/stamp
|
|
|
|
DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/external/astyle/download
|
|
|
|
SOURCE_DIR ${CMAKE_BINARY_DIR}/external/astyle/src
|
|
|
|
BINARY_DIR ${CMAKE_BINARY_DIR}/external/astyle/build
|
|
|
|
)
|
|
|
|
|
|
|
|
list(APPEND ASTYLE_ARGS
|
|
|
|
--style=kr
|
|
|
|
--lineend=linux
|
|
|
|
--suffix=none
|
|
|
|
--pad-oper
|
|
|
|
--unpad-paren
|
|
|
|
--align-pointer=name
|
|
|
|
--align-reference=name
|
|
|
|
--indent-switches
|
|
|
|
--keep-one-line-statements
|
|
|
|
--keep-one-line-blocks
|
|
|
|
--pad-header
|
|
|
|
--convert-tabs
|
|
|
|
--min-conditional-indent=0
|
|
|
|
--indent=spaces=4
|
2018-05-06 15:50:08 +02:00
|
|
|
${CMAKE_SOURCE_DIR}/lib/*.h
|
|
|
|
${CMAKE_SOURCE_DIR}/lib/*.c
|
|
|
|
${CMAKE_SOURCE_DIR}/src/*.h
|
2018-03-31 12:33:37 +02:00
|
|
|
${CMAKE_SOURCE_DIR}/src/*.c
|
|
|
|
${CMAKE_SOURCE_DIR}/tests/*.c
|
2018-05-06 15:50:08 +02:00
|
|
|
${CMAKE_SOURCE_DIR}/tests/*.h
|
|
|
|
${CMAKE_SOURCE_DIR}/tests/bb_tests/*.c
|
|
|
|
${CMAKE_SOURCE_DIR}/tests/wb_tests/*.c
|
2018-07-26 21:25:22 +02:00
|
|
|
${CMAKE_SOURCE_DIR}/tests/bb_tests_cpp/*.cpp
|
2018-03-31 12:33:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
if(NOT WIN32 STREQUAL "1")
|
|
|
|
add_custom_target(
|
|
|
|
format
|
|
|
|
COMMAND ${CMAKE_BINARY_DIR}/bin/astyle ${ASTYLE_ARGS}
|
|
|
|
COMMENT "running astyle"
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
add_custom_target(
|
|
|
|
format
|
|
|
|
COMMAND ${CMAKE_BINARY_DIR}/bin/astyle.exe ${ASTYLE_ARGS}
|
|
|
|
COMMENT "running astyle"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
endif()
|