|
1 | 1 | cmake_minimum_required(VERSION 3.2) |
2 | 2 |
|
| 3 | +option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" FALSE) |
| 4 | + |
3 | 5 | # Link this 'library' to use the following warnings |
4 | 6 | add_library(project_warnings INTERFACE) |
5 | 7 |
|
6 | | -if (CMAKE_COMPILER_IS_GNUCC) |
| 8 | +if(CMAKE_COMPILER_IS_GNUCC) |
7 | 9 | option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" FALSE) |
8 | 10 |
|
9 | | - if (ENABLE_COVERAGE) |
| 11 | + if(ENABLE_COVERAGE) |
10 | 12 | add_compile_options(--coverage -O0) |
11 | 13 | endif() |
12 | 14 | endif() |
13 | 15 |
|
14 | | -if (MSVC) |
| 16 | +if(MSVC) |
15 | 17 | target_compile_options(project_warnings INTERFACE /W4) |
16 | 18 | else() |
17 | | - target_compile_options(project_warnings INTERFACE -Wall -Wextra -Wpedantic) |
| 19 | + target_compile_options(project_warnings |
| 20 | + INTERFACE |
| 21 | + -Wall |
| 22 | + -Wextra # reasonable and standard |
| 23 | + -Wshadow # warn the user if a variable declaration shadows one from a |
| 24 | + # parent context |
| 25 | + -Wnon-virtual-dtor # warn the user if a class with virtual functions has a |
| 26 | + # non-virtual destructor. This helps catch hard to |
| 27 | + # track down memory errors |
| 28 | + -Wold-style-cast # warn for c-style casts |
| 29 | + -Wcast-align # warn for potential performance problem casts |
| 30 | + -Wunused # warn on anything being unused |
| 31 | + -Woverloaded-virtual # warn if you overload (not override) a virtual |
| 32 | + # function |
| 33 | + -Wpedantic # warn if non-standard C++ is used |
| 34 | + -Wconversion # warn on type conversions that may lose data |
| 35 | + -Wsign-conversion # warn on sign conversions |
| 36 | + -Wmisleading-indentation # warn if identation implies blocks where blocks |
| 37 | + # do not exist |
| 38 | + -Wduplicated-cond # warn if if / else chain has duplicated conditions |
| 39 | + -Wduplicated-branches # warn if if / else branches have duplicated code |
| 40 | + -Wlogical-op # warn about logical operations being used where bitwise were |
| 41 | + # probably wanted |
| 42 | + -Wnull-dereference # warn if a null dereference is detected |
| 43 | + -Wuseless-cast # warn if you perform a cast to the same type |
| 44 | + -Wdouble-promotion # warn if float is implicit promoted to double |
| 45 | + -Wformat=2 # warn on security issues around functions that format output |
| 46 | + # (ie printf) |
| 47 | + ) |
18 | 48 | endif() |
19 | 49 |
|
20 | 50 | add_executable(intro main.cpp) |
21 | | -target_compile_features(intro PRIVATE cxx_lambda_init_captures) |
22 | | -target_link_libraries(intro PRIVATE project_warnings) |
23 | | - |
24 | | -target_link_libraries(intro --coverage) |
| 51 | +target_compile_features(intro PRIVATE cxx_std_17) |
| 52 | +target_link_libraries(intro PRIVATE project_warnings --coverage) |
25 | 53 |
|
26 | 54 | enable_testing() |
27 | 55 |
|
28 | 56 | add_executable(tester tester.cpp) |
29 | | -target_link_libraries(tester PRIVATE project_warnings) |
| 57 | +target_link_libraries(tester PRIVATE project_warnings --coverage) |
30 | 58 |
|
31 | | -target_link_libraries(tester --coverage) |
32 | 59 | add_test(Tester tester) |
33 | 60 |
|
| 61 | +#fltk test |
| 62 | +find_package(FLTK REQUIRED) |
| 63 | +add_executable(test_fltk fltk/test_fltk.cpp) |
| 64 | +target_link_libraries(test_fltk PRIVATE project_warnings ${FLTK_LIBRARIES}) |
| 65 | +target_include_directories(test_fltk PRIVATE ${FLTK_INCLUDE_DIR}) |
| 66 | + |
| 67 | +# gtkmm test |
| 68 | +find_package(PkgConfig REQUIRED) |
| 69 | +pkg_check_modules(GTKMM REQUIRED gtkmm-3.0) |
| 70 | +add_executable(test_gtkmm gtkmm/main.cpp gtkmm/hello_world.cpp) |
| 71 | +target_link_libraries(test_gtkmm PRIVATE project_warnings ${GTKMM_LIBRARIES}) |
| 72 | +target_include_directories(test_gtkmm PRIVATE ${GTKMM_INCLUDE_DIRS}) |
| 73 | + |
| 74 | +# imgui example |
| 75 | +find_package(SFML COMPONENTS graphics window system) |
| 76 | +find_package(OpenGL) |
| 77 | + |
| 78 | +# imgui + sfml built as a lib, intentionally not using full warning flags |
| 79 | +add_library(imgui imgui/lib/imgui.cpp imgui/lib/imgui_draw.cpp imgui/lib/imgui-SFML.cpp) |
| 80 | +target_link_libraries(imgui INTERFACE ${SFML_LIBRARIES} ${OPENGL_gl_LIBRARY}) |
| 81 | + |
| 82 | +# imgui test executable, with full warnings enabled |
| 83 | +add_executable(test_imgui imgui/test.cpp) |
| 84 | +target_link_libraries(test_imgui PRIVATE project_warnings imgui) |
| 85 | +target_include_directories(test_imgui PRIVATE ${SFML_INCLUDE_DIR}) |
| 86 | + |
| 87 | +# Nana |
| 88 | +include(ExternalProject) |
| 89 | +ExternalProject_add( |
| 90 | + Nana |
| 91 | + GIT_REPOSITORY https://github.com/cnjinhao/nana.git |
| 92 | + GIT_TAG v1.5.6 |
| 93 | + CMAKE_CACHE_ARGS "-DNANA_CMAKE_SHARED_LIB" |
| 94 | + INSTALL_COMMAND "" |
| 95 | +) |
| 96 | + |
| 97 | +#ExternalProject_Get_Property(Nana NANA_INCLUDE_DIR) |
| 98 | +ExternalProject_Get_Property(Nana SOURCE_DIR BINARY_DIR) |
| 99 | +add_executable(test_nana nana/main.cpp) |
| 100 | +target_include_directories(test_nana PRIVATE ${SOURCE_DIR}/include) |
| 101 | +target_link_libraries(test_nana PRIVATE ${BINARY_DIR}/libnana.so ${NANA_LINKS}) |
| 102 | + |
34 | 103 |
|
0 commit comments