Skip to content

Commit

Permalink
everything: Massive (overdue) cleanup
Browse files Browse the repository at this point in the history
- Update 3rd party libraries to the newest version (Closes #6)
- Removed Mangadex code since I will need to redo all of it anyways
- Move Windows NOMINMAX define out of MSVC compiler to an if(Windows)
  conditional (Closes #7)
- Move MSVC /permissive- flag outside of the if(ENABLE_WARNINGS)
  conditional
  (Closes #7)
- Merge Clang and AppleClang flags (again)
- Clean-up top level CMakeLists.txt by moving the changes to appropriate
  .cmake files
- Drop generator from CMakePresets.json now that its not required by
  default.
- Update .gitignore
- Restructure how I handle handle source files. The time to do this sort
  of thing is now, figuring out what works best for me and the project is
  when its infancy and I am the sole contributor.

We do include the beginning skeleton of the new window.[cpp/h] files
since it was easier then more mucking about in the cmake files. ;)
  • Loading branch information
HackingPheasant committed Nov 15, 2021
1 parent 2d7def5 commit 6493881
Show file tree
Hide file tree
Showing 28 changed files with 303 additions and 688 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ CMakeCache.txt
CMakeFiles/
build/*
CMakeUserPresets.json
*session.vim
57 changes: 9 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,26 @@ project(manga-manager
# Add cmake helpers and 3rd party library helpers to cmake module path
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake;${PROJECT_SOURCE_DIR}/cmake/3rd-party" ${CMAKE_MODULE_PATH})

# Set some default project settins and throw project
# specific options if they have nowhere else to go
include(StandardProjectSettings)
include(PreventInSourceBuilds)

# Link this 'library' to set the c++ standard / compile-time options requested
add_library(project_options INTERFACE)
add_library(project::options ALIAS project_options)
target_compile_features(project_options INTERFACE cxx_std_20)

if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
option(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
if(ENABLE_BUILD_WITH_TIME_TRACE)
target_compile_options(project_options INTERFACE -ftime-trace)
endif()
endif()
# Prevent in source builds
include(PreventInSourceBuilds)

# enable cache system
# Enable cache system
include(Cache)

# standard compiler warnings
include(CompilerWarnings)
# Standard compiler options and warnings
include(CompilerOptions)

# sanitizer options if supported by compiler
# Sanitizer options if supported by compiler
include(Sanitizers)
enable_sanitizers(project_options)

# allow for static analysis options
# Allow for static analysis options
include(StaticAnalyzers)

# allow for cmake options to depend on other options
include(CMakeDependentOption)

# Options
option(ENABLE_WARNINGS "Enable compiler warnings" FALSE)
# Off by default, feel free to switch to on by default if you current builds have zero errors
cmake_dependent_option(ENABLE_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" FALSE "ENABLE_WARNINGS" ON)
# We should at least ENABLE_TESTING when we have some tests
option(ENABLE_TESTING "Enable Test Builds" OFF)
option(ENABLE_FUZZING "Enable Fuzzing Builds" OFF)
option(BUILD_DOCUMENTATION "Build documentation" OFF)
option(BUILD_EXAMPLES "Build all examples" OFF)

# Enable testing at top level project
if(ENABLE_TESTING)
include(CTest)
enable_testing()

include(catch2)
Fetch_GetProperties(catch2)
set(CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/extras" ${CMAKE_MODULE_PATH})
endif()

# Enable fuzzing
if(ENABLE_FUZZING)
endif()

# Build documentation
if(BUILD_DOCUMENTATION)
endif()

# Put the libaries and binaries that get built into directories at the
# top of the build tree rather than in hard-to-find leaf directories.
#
Expand Down
5 changes: 2 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": 2,
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"minor": 21,
"patch": 0
},
"configurePresets": [
Expand All @@ -11,7 +11,6 @@
"displayName": "Base",
"description": "Base configuration",
"hidden": true,
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS" : "ON"
Expand Down
2 changes: 1 addition & 1 deletion cmake/3rd-party/catch2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG 2dc5a5f
GIT_TAG v2.13.7
)

FetchContent_MakeAvailable(Catch2)
2 changes: 1 addition & 1 deletion cmake/3rd-party/cpr.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include(FetchContent)
FetchContent_Declare(
cpr
GIT_REPOSITORY https://github.com/whoshuu/cpr.git
GIT_TAG 1.6.0
GIT_TAG 1.6.2
)

FetchContent_MakeAvailable(cpr)
46 changes: 22 additions & 24 deletions cmake/3rd-party/dear-imgui.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: Clean this up
if(TARGET imgui::imgui)
return()
endif()
Expand All @@ -8,7 +9,7 @@ include(FetchContent)
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.81
GIT_TAG v1.85
)

FetchContent_MakeAvailable(imgui)
Expand Down Expand Up @@ -78,33 +79,14 @@ endif()

if(IMGUI_BUILD_METAL_BINDING)
target_sources(imgui PRIVATE ${imgui_SOURCE_DIR}/backends/imgui_impl_metal.mm)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/backends/imgui_impl_metal.mm PROPERTIES COMPILE_FLAGS -fobjc-weak)
endif()

if(IMGUI_BUILD_OPENGL2_BINDING)
target_sources(imgui PRIVATE ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl2.cpp)
endif()

if(IMGUI_BUILD_OPENGL3_GLEW_BINDING)
find_package(GLEW REQUIRED)
target_link_libraries(imgui PUBLIC GLEW::GLEW)
target_sources(imgui PRIVATE ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp)
endif()

if(IMGUI_BUILD_OPENGL3_GLAD_BINDING)
find_package(glad CONFIG REQUIRED)
target_link_libraries(imgui PUBLIC glad::glad)
target_sources(imgui PRIVATE ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp)
endif()

if(IMGUI_BUILD_OPENGL3_GL3W_BINDING)
find_package(gl3w CONFIG REQUIRED)
target_link_libraries(imgui PUBLIC unofficial::gl3w::gl3w)
target_sources(imgui PRIVATE ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp)
endif()

if(IMGUI_BUILD_OPENGL3_GLBINDING_BINDING)
find_package(glbinding CONFIG REQUIRED)
target_link_libraries(imgui PUBLIC glbinding::glbinding)
if(IMGUI_BUILD_OPENGL3_BINDING)
target_sources(imgui PRIVATE ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp)
endif()

Expand All @@ -118,6 +100,12 @@ if(IMGUI_BUILD_SDL2_BINDING)
target_sources(imgui PRIVATE ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl.cpp)
endif()

if(IMGUI_BUILD_SDL2_RENDERER_BINDING)
find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(imgui PUBLIC SDL2::SDL2)
target_sources(imgui PRIVATE ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer.cpp)
endif()

if(IMGUI_BUILD_VULKAN_BINDING)
#find_package(Vulkan REQUIRED)
target_link_libraries(imgui PUBLIC Vulkan::Vulkan)
Expand Down Expand Up @@ -215,8 +203,14 @@ if(NOT IMGUI_SKIP_HEADERS)
install(FILES ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl2.h DESTINATION include)
endif()

if(IMGUI_BUILD_OPENGL3_GLEW_BINDING OR IMGUI_BUILD_OPENGL3_GLAD_BINDING OR IMGUI_BUILD_OPENGL3_GL3W_BINDING OR IMGUI_BUILD_OPENGL3_GLBINDING_BINDING)
install(FILES ${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.h DESTINATION include)
if(IMGUI_BUILD_OPENGL3_BINDING)
install(
FILES
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.h
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3_loader.h
DESTINATION
include
)
endif()

if(IMGUI_BUILD_OSX_BINDING)
Expand All @@ -227,6 +221,10 @@ if(NOT IMGUI_SKIP_HEADERS)
install(FILES ${imgui_SOURCE_DIR}/backends/imgui_impl_sdl.h DESTINATION include)
endif()

if(IMGUI_BUILD_SDL2_RENDERER_BINDING)
install(FILES ${imgui_SOURCE_DIR}/backends/imgui_impl_sdlrenderer.h DESTINATION include)
endif()

if(IMGUI_BUILD_VULKAN_BINDING)
install(FILES ${imgui_SOURCE_DIR}/backends/imgui_impl_vulkan.h DESTINATION include)
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/3rd-party/fmt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include(FetchContent)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 7.1.3
GIT_TAG 8.0.1
)

FetchContent_MakeAvailable(fmt)
10 changes: 7 additions & 3 deletions cmake/3rd-party/nlohmann_json.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ FetchContent_Declare(
nlohmann_json
# GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent.git
GIT_TAG v3.9.1
GIT_TAG v3.10.4
)

FetchContent_MakeAvailable(nlohmann_json)

if (NOT DEFINED JSON_BuildTests)
set(JSON_BuildTests OFF)
if (NOT DEFINED JSON_SystemInclude)
set(JSON_SystemInclude ON)
endif()

if (NOT DEFINED JSON_Diagnostics)
set(JSON_Diagnostics ON)
endif()
103 changes: 50 additions & 53 deletions cmake/CompilerWarnings.cmake → cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
# Warning flags based from:
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md

# TODO
# - https://github.com/HackingPheasant/manga-manager/issues/7
# - change to something like -Weverything and explictily disable as needed, like I do in clang tidy
# TODO for CMakeUserPresets.json
# - have a everything preset that will build vsrious versions, such as address sanitizer version,
# undefined behaviour type version etc and run them
# - setup valgrind
# - setup Unit tests presets and related.
# - setup to compile under mutliple compilers at once.

# interface target for our warnings
add_library(project_warnings INTERFACE)
add_library(project::warnings ALIAS project_warnings)
add_library(project_options INTERFACE)
add_library(project::options ALIAS project_options)

# Set C++ Standard
target_compile_features(project_options INTERFACE cxx_std_20)

# installation
set_target_properties(project_warnings PROPERTIES EXPORT_NAME warnings)
install(TARGETS project_warnings EXPORT project_targets)
set_target_properties(project_options PROPERTIES EXPORT_NAME compiler_options)
install(TARGETS project_options EXPORT project_targets)

# compiler options
# Compiler specific options
#
# More compiler targets can be found at:
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
if(ENABLE_WARNINGS)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options(project_warnings INTERFACE
if("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang")
# Clang options that cover both Clang and Apple Clang
if(ENABLE_WARNINGS)
target_compile_options(project_options INTERFACE
"-Wall"
"-Wextra" # reasonable and standard
"-Wshadow" # warn the user if a variable declaration shadows one from a parent context
Expand All @@ -40,38 +32,32 @@ if(ENABLE_WARNINGS)
"-Wnull-dereference" # warn if a null dereference is detected
"-Wdouble-promotion" # warn if float is implicit promoted to double
"-Wformat=2" # warn on security issues around functions that format output (ie printf)
"-Wimplicit-fallthrough"# warn on statements that fallthrough without an explicit annotation
)

if(ENABLE_WARNINGS_AS_ERRORS)
target_compile_options(project_warnings INTERFACE "-Werror")
target_compile_options(project_options INTERFACE "-Werror")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(project_warnings INTERFACE
"-Wall"
"-Wextra" # reasonable and standard
"-Wshadow" # warn the user if a variable declaration shadows one from a parent context
"-Wnon-virtual-dtor" # warn the user if a class with virtual functions has a non-virtual destructor.
# This helps catch hard to track down memory errors
"-Wold-style-cast" # warn for c-style casts
"-Wcast-align" # warn for potential performance problem casts
"-Wunused" # warn on anything being unused
"-Woverloaded-virtual" # warn if you overload (not override) a virtual function
"-Wpedantic" # warn if non-standard C++ is used
"-Wconversion" # warn on type conversions that may lose data
"-Wsign-conversion" # warn on sign conversions
"-Wnull-dereference" # warn if a null dereference is detected
"-Wdouble-promotion" # warn if float is implicit promoted to double
"-Wformat=2" # warn on security issues around functions that format output (ie printf)
)
endif()

if(ENABLE_WARNINGS_AS_ERRORS)
target_compile_options(project_warnings INTERFACE "-Werror")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(project_warnings INTERFACE
option(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
if(ENABLE_BUILD_WITH_TIME_TRACE)
target_compile_options(project_options INTERFACE -ftime-trace)
endif()


if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
# Apple Clang specific flags
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Clang options that Apple Clang can't handle
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(ENABLE_WARNINGS)
target_compile_options(project_options INTERFACE
"-Wall"
"-Wextra" # reasonable and standard
"-Wshadow" # warn the user if a variable declaration shadows one from a parent context
"-Wpedantic"
"-Wnon-virtual-dtor" # warn the user if a class with virtual functions has a non-virtual destructor.
# This helps catch hard to track down memory errors
"-Wold-style-cast" # warn for c-style casts
Expand All @@ -92,10 +78,15 @@ if(ENABLE_WARNINGS)
)

if(ENABLE_WARNINGS_AS_ERRORS)
target_compile_options(project_warnings INTERFACE "-Werror")
target_compile_options(project_options INTERFACE "-Werror")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(project_warnings INTERFACE
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(project_options INTERFACE
"/permissive-" # standards conformance mode for MSVC compiler.
)
if(ENABLE_WARNINGS)
target_compile_options(project_options INTERFACE
"/W4" # Baseline reasonable warnings
"/w14242" # 'identifier': conversion from 'type1' to 'type1', possible loss of data
"/w14254" # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
Expand All @@ -118,14 +109,20 @@ if(ENABLE_WARNINGS)
"/w14905" # wide string literal cast to 'LPSTR'
"/w14906" # string literal cast to 'LPWSTR'
"/w14928" # illegal copy-initialization; more than one user-defined conversion has been implicitly applied
"/permissive-" # standards conformance mode for MSVC compiler.
"NOMINMAX" # Stop windows.h min/max macros conflicting with C++ Standard Library
)

if(ENABLE_WARNINGS_AS_ERRORS)
target_compile_options(project_warnings INTERFACE "/WX")
target_compile_options(project_options INTERFACE "/WX")
endif()
else()
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
endif()
else()
message(AUTHOR_WARNING "No compiler options/warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
endif()


# Operating Specific options
if(WIN32)
target_compile_definitions(project_options INTERFACE
"NOMINMAX" # Stop windows.h min/max macros conflicting with C++ Standard Library
)
endif()
Loading

0 comments on commit 6493881

Please sign in to comment.