|
| 1 | +cmake_minimum_required(VERSION 3.11) # FetchContent requires CMake 3.11 |
| 2 | +project(chaiscript_extras) |
| 3 | + |
| 4 | +# MINGW does not yet support C++11's concurrency features |
| 5 | +if(MINGW) |
| 6 | + option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" FALSE) |
| 7 | +else() |
| 8 | + option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" TRUE) |
| 9 | +endif() |
| 10 | + |
| 11 | +option(BUILD_IN_CPP17_MODE "Build with C++17 flags" FALSE) |
| 12 | + |
| 13 | +if(CMAKE_COMPILER_IS_GNUCC) |
| 14 | + option(ENABLE_COVERAGE "Enable Coverage Reporting in GCC" FALSE) |
| 15 | + |
| 16 | + if(ENABLE_COVERAGE) |
| 17 | + add_definitions(--coverage -O0) |
| 18 | + set(LINKER_FLAGS "${LINKER_FLAGS} --coverage") |
| 19 | + endif() |
| 20 | +endif() |
| 21 | + |
| 22 | +if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 23 | + option(ENABLE_THREAD_SANITIZER "Enable thread sanitizer testing in gcc/clang" FALSE) |
| 24 | + if(ENABLE_THREAD_SANITIZER) |
| 25 | + add_definitions(-fsanitize=thread -g) |
| 26 | + set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=thread") |
| 27 | + endif() |
| 28 | + |
| 29 | + option(ENABLE_ADDRESS_SANITIZER "Enable address sanitizer testing in gcc/clang" FALSE) |
| 30 | + if(ENABLE_ADDRESS_SANITIZER) |
| 31 | + add_definitions(-fsanitize=address -g) |
| 32 | + set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=address") |
| 33 | + endif() |
| 34 | + |
| 35 | + option(ENABLE_MEMORY_SANITIZER "Enable memory sanitizer testing in gcc/clang" FALSE) |
| 36 | + if(ENABLE_MEMORY_SANITIZER) |
| 37 | + add_definitions(-fsanitize=memory -g) |
| 38 | + set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=memory") |
| 39 | + endif() |
| 40 | + |
| 41 | + option(ENABLE_UNDEFINED_SANITIZER "Enable undefined behavior sanitizer testing in gcc/clang" FALSE) |
| 42 | + if(ENABLE_UNDEFINED_SANITIZER) |
| 43 | + add_definitions(-fsanitize=undefined -g) |
| 44 | + set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=undefined") |
| 45 | + endif() |
| 46 | + |
| 47 | + option(ENABLE_LTO "Enable Link Time Optimization" FALSE) |
| 48 | + |
| 49 | + if (ENABLE_LTO) |
| 50 | + add_definitions(-flto) |
| 51 | + set(LINKER_FLAGS "${LINKER_FLAGS} -flto") |
| 52 | + endif() |
| 53 | + |
| 54 | + option(PROFILE_GENERATE "Generate profile data" FALSE) |
| 55 | + if (PROFILE_GENERATE) |
| 56 | + add_definitions(-fprofile-generate) |
| 57 | + set(LINKER_FLAGS "${LINKER_FLAGS} -fprofile-generate") |
| 58 | + endif() |
| 59 | + |
| 60 | + option(PROFILE_USE "Use profile data" FALSE) |
| 61 | + if (PROFILE_USE) |
| 62 | + add_definitions(-fprofile-use) |
| 63 | + set(LINKER_FLAGS "${LINKER_FLAGS} -fprofile-use") |
| 64 | + endif() |
| 65 | + |
| 66 | + |
| 67 | +endif() |
| 68 | + |
| 69 | + |
| 70 | +include(CTest) |
| 71 | +enable_testing() |
| 72 | + |
| 73 | +if(CMAKE_COMPILER_IS_GNUCC) |
| 74 | + execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) |
| 75 | + |
| 76 | + if(GCC_VERSION VERSION_LESS 4.9) |
| 77 | + set(CPP14_FLAG "-std=c++1y") |
| 78 | + else() |
| 79 | + if (BUILD_IN_CPP17_MODE) |
| 80 | + set(CPP14_FLAG "-std=c++1z") |
| 81 | + else() |
| 82 | + set(CPP14_FLAG "-std=c++14") |
| 83 | + endif() |
| 84 | + endif() |
| 85 | +else() |
| 86 | + if (BUILD_IN_CPP17_MODE) |
| 87 | + set(CPP14_FLAG "-std=c++1z") |
| 88 | + else() |
| 89 | + set(CPP14_FLAG "-std=c++14") |
| 90 | + endif() |
| 91 | +endif() |
| 92 | + |
| 93 | +if(MSVC) |
| 94 | + add_definitions(/W4 /w44640) |
| 95 | + add_definitions(/bigobj) |
| 96 | + # Note on MSVC compiler flags. |
| 97 | + # The code base selective disables warnings as necessary when the compiler is complaining too much |
| 98 | + # about something that is perfectly valid, or there is simply no technical way around it |
| 99 | + # This particular warning, C4503 is in regards to the decorated names that MSVC generates internally. |
| 100 | + # The error did not come up until the move to C++11, but the compiler doesn't give enough information |
| 101 | + # to determine where the error is coming from, and the internet provides no real information for |
| 102 | + # how to workaround or fix the error. So I'm disabling it globally. |
| 103 | + add_definitions(/wd4503) |
| 104 | +else() |
| 105 | + add_definitions(-Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wcast-qual -Wunused -Woverloaded-virtual -pedantic ${CPP14_FLAG}) |
| 106 | + |
| 107 | + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 108 | + add_definitions(-Weverything -Wno-c++98-compat -Wno-documentation -Wno-switch-enum -Wno-weak-vtables -Wno-sign-conversion -Wno-missing-prototypes -Wno-padded -Wno-missing-noreturn) |
| 109 | + else() |
| 110 | + add_definitions(-Wnoexcept) |
| 111 | + endif() |
| 112 | + |
| 113 | + if(APPLE) |
| 114 | + add_definitions(-Wno-sign-compare) |
| 115 | + endif() |
| 116 | +endif() |
| 117 | + |
| 118 | +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 119 | + option(USE_LIBCXX "Use clang's libcxx" TRUE) |
| 120 | + |
| 121 | + if(USE_LIBCXX) |
| 122 | + add_definitions(-stdlib=libc++) |
| 123 | + set(LINKER_FLAGS "${LINKER_FLAGS} ${CPP14_FLAG} -stdlib=libc++") |
| 124 | + else() |
| 125 | + set(LINKER_FLAGS "${LINKER_FLAGS} ${CPP14_FLAG}") |
| 126 | + endif() |
| 127 | +elseif(CMAKE_COMPILER_IS_GNUCC) |
| 128 | + set(LINKER_FLAGS "${LINKER_FLAGS} ${CPP14_FLAG}") |
| 129 | +endif() |
| 130 | + |
| 131 | +# limitations in MinGW require us to make an optimized build |
| 132 | +# for the sake of object sizes or something |
| 133 | +if(MINGW OR CYGWIN) |
| 134 | + add_definitions(-O3) |
| 135 | +endif() |
| 136 | + |
| 137 | +if(NOT MULTITHREAD_SUPPORT_ENABLED) |
| 138 | + add_definitions(-DCHAISCRIPT_NO_THREADS) |
| 139 | +endif() |
| 140 | + |
| 141 | +if(CMAKE_HOST_UNIX) |
| 142 | + if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Haiku") |
| 143 | + list(APPEND LIBS "dl") |
| 144 | + endif() |
| 145 | + |
| 146 | + if(MULTITHREAD_SUPPORT_ENABLED) |
| 147 | + if(CMAKE_COMPILER_IS_GNUCC) |
| 148 | + execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE GCC_FULL_VERSION) |
| 149 | + if(GCC_FULL_VERSION MATCHES "4.8.1.*ubuntu") |
| 150 | + set(LINKER_FLAGS "${LINKER_FLAGS} -Wl,--no-as-needed -pthread") |
| 151 | + else() |
| 152 | + set(LINKER_FLAGS "${LINKER_FLAGS} -pthread") |
| 153 | + endif() |
| 154 | + else() |
| 155 | + set(LINKER_FLAGS "${LINKER_FLAGS} -pthread") |
| 156 | + endif() |
| 157 | + |
| 158 | + add_definitions(-pthread) |
| 159 | + endif() |
| 160 | +endif() |
| 161 | + |
| 162 | +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}") |
| 163 | +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}") |
| 164 | +set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}") |
| 165 | + |
| 166 | +add_subdirectory(cmake) |
| 167 | +add_subdirectory(tests) |
0 commit comments