2019-05-26 09:13:58 +02:00
|
|
|
cmake_minimum_required(VERSION 3.0)
|
2019-04-15 20:38:07 +02:00
|
|
|
|
2020-01-10 19:40:06 +01:00
|
|
|
project(libfort VERSION 0.4.0)
|
2019-05-26 09:13:58 +02:00
|
|
|
|
|
|
|
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)"
|
2019-05-26 09:22:12 +02:00
|
|
|
"\\1.\\2" libfort_SOVERSION
|
|
|
|
${libfort_VERSION})
|
2018-03-17 19:53:38 +01:00
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
|
2018-01-01 09:26:34 +01:00
|
|
|
|
2019-04-26 22:41:28 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Build options
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
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)
|
2019-08-29 08:12:58 +02:00
|
|
|
option(FORT_ENABLE_UTF8 "Enable utf8 support" ON)
|
2019-04-21 09:29:02 +02:00
|
|
|
set(FORT_BUILD_TYPE "common" CACHE STRING "Build type")
|
|
|
|
|
|
|
|
set_property(CACHE FORT_BUILD_TYPE PROPERTY STRINGS
|
|
|
|
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})
|
2019-04-12 20:25:23 +02:00
|
|
|
else()
|
2018-03-18 17:02:53 +01:00
|
|
|
set(FORT_COMPILER ${CMAKE_C_COMPILER_ID})
|
2019-04-12 20:25:23 +02:00
|
|
|
endif()
|
2018-03-18 17:02:53 +01:00
|
|
|
|
2018-03-18 14:44:49 +01:00
|
|
|
|
2018-01-01 09:26:34 +01:00
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
|
|
|
2019-05-19 18:09:11 +02:00
|
|
|
message(STATUS "libfort build options: "
|
|
|
|
" wchar support = ${FORT_ENABLE_WCHAR}; "
|
|
|
|
" build type = ${FORT_BUILD_TYPE}")
|
|
|
|
|
2019-05-19 18:54:26 +02:00
|
|
|
# for fort.hpp
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
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")
|
2019-04-12 20:25:23 +02:00
|
|
|
else()
|
2018-11-17 08:44:35 +01:00
|
|
|
set(ADDITIONAL_WARNINGS "\
|
2019-04-12 20:30:13 +02:00
|
|
|
-Wall \
|
|
|
|
-Wextra \
|
2018-11-17 08:44:35 +01:00
|
|
|
-Wdouble-promotion \
|
|
|
|
-Wshadow \
|
|
|
|
-Wformat=2 \
|
|
|
|
-Wno-variadic-macros \
|
|
|
|
-Wcast-align \
|
2018-11-17 09:53:03 +01:00
|
|
|
-Wstrict-aliasing=2 \
|
|
|
|
-Wstrict-overflow=5 \
|
|
|
|
-Wfloat-equal \
|
|
|
|
-Wwrite-strings \
|
2018-11-17 08:44:35 +01:00
|
|
|
")
|
2018-11-17 09:53:03 +01:00
|
|
|
if("${FORT_COMPILER}" STREQUAL "GNU")
|
2019-04-12 20:25:23 +02:00
|
|
|
set(ADDITIONAL_WARNINGS "${ADDITIONAL_WARNINGS} \
|
2019-04-12 20:30:13 +02:00
|
|
|
-Wtrampolines \
|
2019-04-12 20:25:23 +02:00
|
|
|
-Wlogical-op")
|
|
|
|
endif()
|
2018-11-17 08:44:35 +01:00
|
|
|
|
2019-04-12 20:25:23 +02:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_WARNINGS} -Wpedantic")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADDITIONAL_WARNINGS}")
|
|
|
|
endif()
|
2018-03-17 19:53:38 +01:00
|
|
|
|
2019-04-21 11:31:45 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Sanitizers
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if("${FORT_COMPILER}" STREQUAL "GNU" OR "${FORT_COMPILER}" STREQUAL "Clang")
|
|
|
|
# asan case
|
|
|
|
if(FORT_BUILD_TYPE STREQUAL "asan")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
|
|
|
if("${FORT_COMPILER}" STREQUAL "GNU")
|
2019-04-26 22:20:43 +02:00
|
|
|
set(FORT_LINK_LIBRARIES asan)
|
2019-04-21 11:31:45 +02:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
#ubsan case
|
|
|
|
if(FORT_BUILD_TYPE STREQUAL "ubsan")
|
|
|
|
# -fno-sanitize-recover option is used to force faild
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
|
|
|
|
if("${FORT_COMPILER}" STREQUAL "GNU")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize-recover")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize-recover")
|
2019-04-26 22:20:43 +02:00
|
|
|
set(FORT_LINK_LIBRARIES ubsan)
|
2019-04-26 22:11:09 +02:00
|
|
|
|
2019-04-21 11:31:45 +02:00
|
|
|
elseif("${FORT_COMPILER}" STREQUAL "Clang")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize-recover=all")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize-recover=all")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
#coveralls case
|
|
|
|
if(FORT_BUILD_TYPE STREQUAL "coveralls")
|
|
|
|
set(COVERAGE_FLAGS "-g -fprofile-arcs -ftest-coverage")
|
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS}")
|
2019-09-15 10:18:51 +02:00
|
|
|
#target_link_libraries(${PROJECT_NAME}_ex_cpp gcov)
|
2019-04-21 11:31:45 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Hack for some gcc versions
|
2019-05-24 19:25:13 +02:00
|
|
|
if("${FORT_COMPILER}" STREQUAL "GNU"
|
|
|
|
AND NOT "${FORT_BUILD_TYPE}" STREQUAL "common")
|
2019-04-21 11:31:45 +02:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold")
|
|
|
|
endif()
|
|
|
|
|
2019-04-27 15:00:20 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Disable NDEBUG for all builds
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
foreach(flags_var_to_scrub
|
|
|
|
CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL
|
|
|
|
CMAKE_C_FLAGS_RELEASE
|
|
|
|
CMAKE_C_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_C_FLAGS_MINSIZEREL
|
|
|
|
)
|
2019-04-27 15:21:24 +02:00
|
|
|
string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
|
2019-04-27 15:00:20 +02:00
|
|
|
"${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
2019-04-26 22:11:09 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
2019-09-21 09:38:56 +02:00
|
|
|
# Add wchar and UTF-8 support for the build
|
2019-04-26 22:11:09 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
2019-08-29 08:12:58 +02:00
|
|
|
if(NOT FORT_ENABLE_WCHAR)
|
|
|
|
add_definitions(-DFT_CONGIG_DISABLE_WCHAR)
|
|
|
|
endif()
|
|
|
|
if(NOT FORT_ENABLE_UTF8)
|
|
|
|
add_definitions(-DFT_CONGIG_DISABLE_UTF8)
|
2019-04-26 22:11:09 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(FORT_HAVE_WCHAR "${FORT_ENABLE_WCHAR}" CACHE STRING "fort option")
|
2019-08-29 08:12:58 +02:00
|
|
|
set(FORT_HAVE_UTF8 "${FORT_ENABLE_UTF8}" CACHE STRING "fort option")
|
|
|
|
|
2019-04-26 22:11:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Subdirectories
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
add_subdirectory(lib)
|
|
|
|
add_subdirectory(src)
|
|
|
|
add_subdirectory(tests)
|
2019-09-21 11:58:23 +02:00
|
|
|
add_subdirectory(examples)
|
2019-04-26 22:11:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Sources and executables
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
file(GLOB_RECURSE FortHeaders
|
|
|
|
"lib/*.h"
|
|
|
|
"lib/*.hpp"
|
|
|
|
"tests/*.h"
|
|
|
|
"tests/*.hpp"
|
|
|
|
"src/*.h")
|
|
|
|
add_custom_target(headers SOURCES ${FortHeaders})
|
|
|
|
|
|
|
|
|
2018-09-01 18:42:57 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
2019-09-21 09:38:56 +02:00
|
|
|
# Set preprocessor macros for all test builds.
|
2018-09-01 18:42:57 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
2019-04-26 22:11:09 +02:00
|
|
|
|
2018-09-01 18:42:57 +02:00
|
|
|
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
|
|
|
# ------------------------------------------------------------------------------
|
2019-09-21 09:38:56 +02:00
|
|
|
# Setup text formatting via astyle.
|
2018-03-31 12:33:37 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if(FORT_ENABLE_ASTYLE)
|
|
|
|
list(APPEND ASTYLE_CMAKE_ARGS
|
|
|
|
"-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}"
|
|
|
|
)
|
|
|
|
|
2019-04-12 20:25:23 +02:00
|
|
|
externalproject_add(
|
2018-03-31 12:33:37 +02:00
|
|
|
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
|
2019-09-28 10:02:34 +02:00
|
|
|
${CMAKE_SOURCE_DIR}/lib/*.hpp
|
2018-05-06 15:50:08 +02:00
|
|
|
${CMAKE_SOURCE_DIR}/lib/*.c
|
|
|
|
${CMAKE_SOURCE_DIR}/src/*.h
|
2019-09-28 10:02:34 +02:00
|
|
|
${CMAKE_SOURCE_DIR}/src/*.hpp
|
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
|
2018-11-24 21:14:26 +01:00
|
|
|
${CMAKE_SOURCE_DIR}/tests/*.hpp
|
2018-05-06 15:50:08 +02:00
|
|
|
${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()
|
2019-04-21 09:29:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2019-09-21 09:38:56 +02:00
|
|
|
# Add examples and unit tests to ctest driver.
|
2019-04-21 09:29:02 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enable_testing()
|
2019-09-21 09:38:56 +02:00
|
|
|
list(APPEND ${PROJECT_NAME}_ctests
|
|
|
|
${${PROJECT_NAME}_tests}
|
|
|
|
${${PROJECT_NAME}_examples})
|
|
|
|
foreach(exe ${${PROJECT_NAME}_ctests})
|
|
|
|
add_test(NAME ${exe} COMMAND ${exe})
|
|
|
|
endforeach()
|
2020-02-10 21:00:47 +01:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Exported targets for outer applications.
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
export(
|
|
|
|
TARGETS fort
|
2020-02-10 21:06:05 +01:00
|
|
|
FILE ${PROJECT_NAME}-targets.cmake
|
2020-02-10 21:00:47 +01:00
|
|
|
)
|
|
|
|
|