• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# CMake build control file for safe numerics Library Examples
2
3cmake_minimum_required(VERSION 3.8.6)
4
5project("SafeIntegers")
6enable_language(CXX)
7
8########################################################
9# Create interface library
10#
11add_library(boost_safe_numerics INTERFACE)
12add_library(Boost::safe_numerics ALIAS boost_safe_numerics)
13
14target_include_directories(boost_safe_numerics INTERFACE "${Boost_INCLUDE_DIRS}")
15target_compile_features(boost_safe_numerics INTERFACE cxx_std_14)
16
17########################################################
18# Compiler settings - special settings for known compilers
19#
20
21set(CMAKE_CXX_STANDARD 14)
22set(CMAKE_CXX_STANDARD_REQUIRED ON)
23set(CMAKE_CXX_EXTENSIONS OFF)
24
25message(STATUS "compiler is ${CMAKE_CXX_COMPILER_ID}" )
26
27if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
28  add_definitions( -ftemplate-depth=255 )
29  add_compile_options(-Wnon-virtual-dtor -ansi -Wcast-align -Wchar-subscripts -Wall -Wextra -W -Wshadow -Wsign-compare )
30elseif( CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
31  add_definitions( /wd4996 /wd4068 )
32  # warning level 4 and all warnings as errors
33  add_compile_options(/W4 /WX)
34elseif( CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
35  add_definitions( -ftemplate-depth=255 )
36  add_compile_options(-Wnon-virtual-dtor -ansi -Wcast-align -Wchar-subscripts -Wall -Wextra -W -Wshadow -Wsign-compare )
37elseif( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
38  add_definitions( -ftemplate-depth=255 )
39  add_compile_options(-Wnon-virtual-dtor -ansi -Wcast-align -Wchar-subscripts -Wall -Wextra -W -Wshadow -Wsign-compare )
40endif()
41
42#
43# Project settings
44#
45
46find_package(Boost )
47
48if(Boost_FOUND)
49  if( CMAKE_HOST_APPLE )
50    set(Boost_ADDRESS_MODEL 64 CACHE STRING "32/64 bits")
51  endif()
52  message(STATUS "Boost directories found at ${Boost_INCLUDE_DIRS}")
53  message(STATUS "Boost version found is ${Boost_VERSION}")
54  include_directories("${Boost_INCLUDE_DIRS}")  # note: sets header search path?
55elseif()
56    message("Boost NOT Found!")
57endif()
58
59message(STATUS "include directories are:" )
60get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
61foreach(dir ${dirs})
62  message(STATUS "   ${dir}")
63endforeach()
64
65#use folders in organization of the IDE
66set(USE_FOLDERS TRUE)
67
68###########################
69# testing and submitting test results to the test dashboard
70
71if(0)
72
73## Create a file named CTestConfig.cmake adjacent to the current file.
74## This new file should contain the following:
75
76set(CTEST_PROJECT_NAME "Safe Numerics")
77set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
78
79set(CTEST_DROP_METHOD "http")
80set(CTEST_DROP_SITE "my.cdash.org")
81# set(CTEST_DROP_LOCATION "/cdash/submit.php?project=MyProject")
82set(CTEST_DROP_LOCATION "/index.php?project=Safe+Numerics")
83set(CTEST_DROP_SITE_CDASH TRUE)
84
85endif()
86
87function(test_run_pass base_name )
88  message(STATUS ${base_name})
89  add_executable(${base_name} ${base_name}.cpp)
90  add_test(NAME ${base_name} COMMAND ${base_name})
91endfunction(test_run_pass)
92
93function(test_compile_pass base_name )
94  message(STATUS ${base_name} - compile only)
95  add_library(${base_name} OBJECT ${base_name})
96endfunction(test_compile_pass)
97
98function(test_compile_fail base_name )
99  message(STATUS ${base_name})
100  # Add failing-to-compile targets
101  add_executable(${base_name} ${base_name}.cpp)
102
103  # Avoid building these targets normally
104  set_target_properties(${base_name} PROPERTIES
105    EXCLUDE_FROM_ALL TRUE
106    EXCLUDE_FROM_DEFAULT_BUILD TRUE
107  )
108
109  # Add the tests.  These invoke "cmake --build ..." which is a
110  # cross-platform way of building the given target.
111  add_test(NAME ${base_name}
112    COMMAND ${CMAKE_COMMAND} --build . --target ${base_name} --config $<CONFIGURATION>
113    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
114  )
115
116  # Expect these tests to fail
117  # (i.e. cmake --build should return a non-zero value)
118  set_tests_properties(${base_name} PROPERTIES WILL_FAIL TRUE)
119endfunction( test_compile_fail base_name )
120
121########################################################
122# End Compiler settings
123#
124
125enable_testing()
126
127add_subdirectory("include/boost/safe_numerics")
128add_subdirectory("example")
129add_subdirectory("test")
130
131