Skip to content

Commit

Permalink
Refactor oscar_compiler_configuration into oscar
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Nov 1, 2024
1 parent 176f38d commit ebe41ad
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 297 deletions.
14 changes: 8 additions & 6 deletions apps/hellotriangle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
add_executable(hellotriangle hellotriangle.cpp)

target_link_libraries(hellotriangle PRIVATE
oscar_compiler_configuration # so that it uses standard compiler flags etc.
oscar
add_executable(hellotriangle
hellotriangle.cpp
)

set_target_properties(hellotriangle PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
target_compile_features(hellotriangle PUBLIC
cxx_std_20
)
target_link_libraries(hellotriangle PRIVATE
oscar
)

# -------------- installation/packaging ------------- #
if(${OSC_EMSCRIPTEN})
Expand Down
19 changes: 7 additions & 12 deletions apps/osc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ add_executable(osc
${CMAKE_CURRENT_SOURCE_DIR}/Windows/resources.rc
>
)

set_target_properties(osc PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
target_compile_features(osc PUBLIC
cxx_std_20
)
target_link_libraries(osc PRIVATE

# so that it uses standard compiler flags etc.
oscar_compiler_configuration

# so that it can boot into the main osc codebase
OpenSimCreator
)

target_include_directories(osc PRIVATE

# Windows: `resources.rc` uses the include path to find resources
Expand All @@ -106,11 +106,6 @@ target_link_options(osc PRIVATE
>
)

set_target_properties(osc PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)


# -------------- installation/packaging ------------- #

Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
add_subdirectory(oscar_compiler_configuration)
add_subdirectory(oscar)
add_subdirectory(oscar_demos)
if (${OSC_BUILD_OPENSIMCREATOR})
Expand Down
32 changes: 14 additions & 18 deletions src/OpenSimCreator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -440,23 +440,14 @@ add_library(OpenSimCreator STATIC
Utils/TPS3D.cpp
Utils/TPS3D.h
)

target_include_directories(OpenSimCreator PUBLIC

# so that the source code can `#include <OpenSimCreator/SomeModule.h>`
${CMAKE_CURRENT_SOURCE_DIR}/..
set_target_properties(OpenSimCreator PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)

target_link_libraries(OpenSimCreator PUBLIC
oscar_compiler_configuration
oscar
oscar_demos

osim
target_compile_features(OpenSimCreator PUBLIC
cxx_std_20
)

# additional compile options (on top of `oscar_compiler_configuration`)
target_compile_options(OpenSimCreator PRIVATE
target_compile_options(OpenSimCreator INTERFACE

# gcc/clang
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:
Expand All @@ -475,8 +466,13 @@ target_compile_definitions(OpenSimCreator PRIVATE
# OpenSim's `spdlog` transitively uses a deprecated `stdext::checked_array_iterator`
$<$<CXX_COMPILER_ID:MSVC>:_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING>
)
target_include_directories(OpenSimCreator PUBLIC

set_target_properties(OpenSimCreator PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
# so that the source code can `#include <OpenSimCreator/SomeModule.h>`
${CMAKE_CURRENT_SOURCE_DIR}/..
)
target_link_libraries(OpenSimCreator PUBLIC
oscar
oscar_demos
osim
)
3 changes: 1 addition & 2 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ The libraries are split into several targets. The intent of each is:
| - | - | - |
| `OpenSimCreator/` | Implements the OpenSim Creator UI by integrating [osim](https://github.com/ComputationalBiomechanicsLab/osim) against `oscar`. Also includes the demo tabs for testing/verification. | `oscar`, `oscar_demos`, `osim` |
| `oscar/` | Core engine for creating scientific tooling UIs | `OpenGL`, `glew`, `SDL2`, `nativefiledialog`, `imgui`, `implot`, `stb`, `lunasvg`, `tomlplusplus`, `unordered_dense` |
| `oscar_compiler_configuration/` | Cmake `INTERFACE` target that configures the compiler options for `oscar` and `OpenSimCreator` | (nothing) |
| `oscar_demos/` | Demos that uses the `oscar` API to provide something interesting/useful, such as implement https://learnopengl.com/ in terms of the `oscar` API | `oscar`, `oscar_compiler_configuration` |
| `oscar_demos/` | Demos that uses the `oscar` API to provide something interesting/useful, such as implement https://learnopengl.com/ in terms of the `oscar` API | `oscar` |
191 changes: 178 additions & 13 deletions src/oscar/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
set(
OSC_FORCE_ASSERTS_ENABLED ON
CACHE BOOL
"force-enable/-disable OSC's runtime assertions - even if building a release build"
)
set(OSC_RUNTIME_PERF_MEASUREMENTS_ENABLED ON
CACHE BOOL
"enable/disable whether performance counters are collected at runtime wherever the `OSC_PERF` macro is used in the source code"
)

# find dependencies (usually built+installed from `third_party/`)
if (NOT ${OSC_EMSCRIPTEN})
find_package(OpenGL REQUIRED)
Expand Down Expand Up @@ -470,29 +480,184 @@ add_library(oscar STATIC
Variant.h
)

set_target_properties(oscar PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
target_compile_features(oscar PUBLIC
cxx_std_20
)
target_compile_options(oscar PUBLIC

# msvc (Windows) flags
$<$<CXX_COMPILER_ID:MSVC>:

# set the warning level very high
/W4

# treat all warnings as errors
/WX

# keep frame pointers around, so that runtime stack traces can be dumped to error logs
/Oy-

# disable MSVC's permissive mode to ensure better ISO C++ conformance
/permissive-

# ensure `volatile` variables follow (less-strict) ISO standards
/volatile:iso

# ensure preprocessor is standards conformant
/Zc:preprocessor

# assume `new` throws when memory cannot be allocated (ISO conformance)
/Zc:throwingNew

# only handle standard, synchronous, C++ exceptions (ISO) and treat asynchronous
# Windows/system structured exceptions as fatal, non-catchable, errors
/EHsc
>

# gcc AND clang flags
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:

# treat all warnings as errors
-Werror

# enable all basic warnings
-Wall

# enable extra warnings
-Wextra

# enable pedantically extra warnings
-pedantic

# warn if an uninitialized variable is initialized by itself
-Winit-self

# warn if data is casted to a higher alignment (e.g. char -> long)
#
# (set to =strict if the code quality is high enough and Clang in CI is high enough)
-Wcast-align

# warn if casting C string constants from `char const*` to `char*`
-Wwrite-strings

# warn if a dangling else is detected
-Wdangling-else

# warn if a date-time macro expansion is not reproducible
-Wdate-time

# warn if a variable-length array (VLA) is detected (disallowed)
-Wvla

# warn if the compiler detected that the code is way too complex to optimize
-Wdisabled-optimization

# warn if a structure is given the 'packed' attribute (disallowed: alignment)
-Wpacked

# warn if a case in a switch statement implicitly falls through after a statement
-Wimplicit-fallthrough

# disabled: requires newer gcc
# warn if calls to `strcmp` and `strncmp` are determined to be invalid at compile-time
# -Wstring-compare

# warn if insecure string formatting (e.g. for printf) is detected
-Wformat-security

# disabled: requires newer gcc
# warn if trying to allocate 0 bytes of memory using an allocation function (could be undef behavior)
# -Walloc-zero

# disabled: requires newer gcc
# warn if using trampoline functions (requires executable stack)
# -Wtrampolines

# warn if a pointer is cast in a C-style cast in such a way that it removes qualifiers (e.g. char const* -> char*)
-Wcast-qual

# warn if implicit conversion may alter a value
-Wconversion

# disabled: very very hard to avoid all warnings from this :(
#
# warn if an implicit conversion involving signed-to-unsigned etc. may alter a value
-Wno-sign-conversion

# disabled: the codebase contains MSVC-specific `pragma warning` etc. that should hopefully
# be dropped once the codebase is upgraded to C++23
-Wno-unknown-pragmas

# disabled: requires newer gcc
# warn if a suspicous use of a logical operator is detected (e.g. i < 0 && i < 0)
# -Wlogical-op

# disabled: doesn't work in some contexts where forward declarations are necessary
# -Wredundant-decls

# regardless of debug/release, pin the frame pointer register
# so that stack traces are sane when debugging (even in Release).
#
# This adds some overhead (pins one register and requires callers
# to setup their base pointers etc.) but makes debugging + profiling
# the application much easier, even in release mode
-fno-omit-frame-pointer
>

# clang flags
$<$<CXX_COMPILER_ID:Clang>:
# required in earlier clangs. Just setting
# -fno-omit-frame-pointer (above) is not enough
#
# see:
# - https://stackoverflow.com/questions/43864881/fno-omit-frame-pointer-equivalent-compiler-option-for-clang
# - fixed here: https://reviews.llvm.org/D64294
-mno-omit-leaf-frame-pointer

# warn if using an uninitialized variable
#
# not done on gcc because it produces false-positives
-Wuninitialized
>

# gcc flags
$<$<CXX_COMPILER_ID:GNU>:
# produces false positives?
-Wno-uninitialized

# false-positive in googletest https://github.com/google/googletest/issues/4232
-Wno-restrict
>
)
target_compile_definitions(oscar
PUBLIC
$<$<BOOL:${OSC_FORCE_ASSERTS_ENABLED}>:OSC_FORCE_ASSERTS_ENABLED>
$<$<BOOL:${OSC_RUNTIME_PERF_MEASUREMENTS_ENABLED}>:OSC_RUNTIME_PERF_MEASUREMENTS_ENABLED>
)
target_include_directories(oscar PUBLIC

# so that `#include <oscar/HEADER.h>` works
${CMAKE_CURRENT_SOURCE_DIR}/..
)

target_link_libraries(oscar
PUBLIC
oscar_compiler_configuration
PRIVATE
$<$<NOT:$<BOOL:${OSC_EMSCRIPTEN}>>:OpenGL::GL>
$<$<NOT:$<BOOL:${OSC_EMSCRIPTEN}>>:GLEW::glew_s>
$<$<NOT:$<BOOL:${OSC_EMSCRIPTEN}>>:SDL2::SDL2>
$<$<NOT:$<BOOL:${OSC_EMSCRIPTEN}>>:nativefiledialog>
target_link_libraries(oscar PRIVATE
# these libraries are either provided by emscripten later on, or aren't
# supported by the emscripten build (they're #ifdef'd out)
$<$<NOT:$<BOOL:${OSC_EMSCRIPTEN}>>:
OpenGL::GL
GLEW::glew_s
SDL2::SDL2
nativefiledialog
>

imgui
implot
stb
unordered_dense::unordered_dense
tomlplusplus::tomlplusplus
lunasvg::lunasvg
)

set_target_properties(oscar PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
Loading

0 comments on commit ebe41ad

Please sign in to comment.