diff --git a/apps/hellotriangle/CMakeLists.txt b/apps/hellotriangle/CMakeLists.txt index 362d69ac1..ffd382c5f 100644 --- a/apps/hellotriangle/CMakeLists.txt +++ b/apps/hellotriangle/CMakeLists.txt @@ -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}) diff --git a/apps/osc/CMakeLists.txt b/apps/osc/CMakeLists.txt index 51c3d1740..25861e7e6 100644 --- a/apps/osc/CMakeLists.txt +++ b/apps/osc/CMakeLists.txt @@ -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 @@ -106,11 +106,6 @@ target_link_options(osc PRIVATE > ) -set_target_properties(osc PROPERTIES - CXX_EXTENSIONS OFF - CXX_STANDARD_REQUIRED ON -) - # -------------- installation/packaging ------------- # diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5b5d9f555..0e2ab485d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,3 @@ -add_subdirectory(oscar_compiler_configuration) add_subdirectory(oscar) add_subdirectory(oscar_demos) if (${OSC_BUILD_OPENSIMCREATOR}) diff --git a/src/OpenSimCreator/CMakeLists.txt b/src/OpenSimCreator/CMakeLists.txt index 7f9bc22a5..bc240634b 100644 --- a/src/OpenSimCreator/CMakeLists.txt +++ b/src/OpenSimCreator/CMakeLists.txt @@ -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 ` - ${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 $<$,$>: @@ -475,8 +466,13 @@ target_compile_definitions(OpenSimCreator PRIVATE # OpenSim's `spdlog` transitively uses a deprecated `stdext::checked_array_iterator` $<$:_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 ` + ${CMAKE_CURRENT_SOURCE_DIR}/.. +) +target_link_libraries(OpenSimCreator PUBLIC + oscar + oscar_demos + osim ) diff --git a/src/README.md b/src/README.md index da7eb290d..1f9bd836e 100644 --- a/src/README.md +++ b/src/README.md @@ -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` | diff --git a/src/oscar/CMakeLists.txt b/src/oscar/CMakeLists.txt index bec7f4a3f..1e705d4af 100644 --- a/src/oscar/CMakeLists.txt +++ b/src/oscar/CMakeLists.txt @@ -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) @@ -470,20 +480,180 @@ 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 + $<$: + + # 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 + $<$,$>: + + # 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 + $<$: + # 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 + $<$: + # produces false positives? + -Wno-uninitialized + + # false-positive in googletest https://github.com/google/googletest/issues/4232 + -Wno-restrict + > +) +target_compile_definitions(oscar +PUBLIC + $<$:OSC_FORCE_ASSERTS_ENABLED> + $<$:OSC_RUNTIME_PERF_MEASUREMENTS_ENABLED> +) target_include_directories(oscar PUBLIC # so that `#include ` works ${CMAKE_CURRENT_SOURCE_DIR}/.. ) -target_link_libraries(oscar -PUBLIC - oscar_compiler_configuration -PRIVATE - $<$>:OpenGL::GL> - $<$>:GLEW::glew_s> - $<$>:SDL2::SDL2> - $<$>: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) + $<$>: + OpenGL::GL + GLEW::glew_s + SDL2::SDL2 + nativefiledialog + > + imgui implot stb @@ -491,8 +661,3 @@ PRIVATE tomlplusplus::tomlplusplus lunasvg::lunasvg ) - -set_target_properties(oscar PROPERTIES - CXX_EXTENSIONS OFF - CXX_STANDARD_REQUIRED ON -) diff --git a/src/oscar_compiler_configuration/CMakeLists.txt b/src/oscar_compiler_configuration/CMakeLists.txt deleted file mode 100644 index 660047482..000000000 --- a/src/oscar_compiler_configuration/CMakeLists.txt +++ /dev/null @@ -1,172 +0,0 @@ -# -------------- gather user-facing build cache vars ---------------- # - -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" -) - -# -------------- set globally-applicable policies ---------------- # - -# oscar_compiler_configuration: -# -# a cmake target that downstream projects can link to in order to inherit the -# configured compiler parameters (e.g. warning flags, language level, etc.) for -# oscar -add_library(oscar_compiler_configuration INTERFACE) -target_compile_options(oscar_compiler_configuration INTERFACE - - # msvc (Windows) flags - $<$: - - # 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 - $<$,$>: - - # 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 - $<$: - # 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 - $<$: - # produces false positives? - -Wno-uninitialized - - # false-positive in googletest https://github.com/google/googletest/issues/4232 - -Wno-restrict - > -) -target_compile_features(oscar_compiler_configuration INTERFACE cxx_std_20) - -target_compile_definitions(oscar_compiler_configuration INTERFACE - $<$:OSC_FORCE_ASSERTS_ENABLED> - $<$:OSC_RUNTIME_PERF_MEASUREMENTS_ENABLED> -) diff --git a/src/oscar_compiler_configuration/README.md b/src/oscar_compiler_configuration/README.md deleted file mode 100644 index b4bed9c13..000000000 --- a/src/oscar_compiler_configuration/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# `src/oscar_compiler_configuration`: Compiler configuration target - -This provides an `INTERFACE` cmake target that allows other projects to use -the same compiler flags as `oscar` (target name: `oscar_compiler_configuration`). diff --git a/src/oscar_demos/CMakeLists.txt b/src/oscar_demos/CMakeLists.txt index 243be3bd7..b5c2f44b8 100644 --- a/src/oscar_demos/CMakeLists.txt +++ b/src/oscar_demos/CMakeLists.txt @@ -84,18 +84,18 @@ add_library(oscar_demos STATIC SubMeshTab.cpp SubMeshTab.h ) - +set_target_properties(oscar_demos PROPERTIES + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON +) +target_compile_features(oscar_demos PUBLIC + cxx_std_20 +) target_include_directories(oscar_demos PUBLIC # so that `#include "oscar_demos/HEADER.h"` works ${CMAKE_CURRENT_SOURCE_DIR}/.. ) - target_link_libraries(oscar_demos PUBLIC oscar ) - -set_target_properties(oscar_demos PROPERTIES - CXX_EXTENSIONS OFF - CXX_STANDARD_REQUIRED ON -) diff --git a/tests/TestOpenSimCreator/CMakeLists.txt b/tests/TestOpenSimCreator/CMakeLists.txt index 85a05ef6f..eca716fdc 100644 --- a/tests/TestOpenSimCreator/CMakeLists.txt +++ b/tests/TestOpenSimCreator/CMakeLists.txt @@ -1,6 +1,10 @@ include(GoogleTest) find_package(GTest REQUIRED CONFIG) +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/TestOpenSimCreatorConfig.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/generated/TestOpenSimCreator/TestOpenSimCreatorConfig.h" +) add_executable(TestOpenSimCreator ComponentRegistry/TestStaticComponentRegistries.cpp @@ -33,50 +37,23 @@ add_executable(TestOpenSimCreator TestOpenSimCreator.cpp # entrypoint (main) ) - -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/TestOpenSimCreatorConfig.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/generated/TestOpenSimCreator/TestOpenSimCreatorConfig.h" +set_target_properties(TestOpenSimCreator PROPERTIES + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON +) +target_compile_features(TestOpenSimCreator PUBLIC + cxx_std_20 ) target_include_directories(TestOpenSimCreator PRIVATE # so that source code can `#include ` "${CMAKE_CURRENT_BINARY_DIR}/generated/" ) - target_link_libraries(TestOpenSimCreator PRIVATE - - # set compile options - oscar_compiler_configuration - - # link to the to-be-tested library OpenSimCreator - - # link to testing library GTest::gtest GTest::gtest_main ) -# additional compile options (on top of `oscar_compiler_configuration`) -target_compile_options(TestOpenSimCreator PRIVATE - - # gcc/clang - $<$,$>: - # disable extra-semicolon detection: broken by OpenSim_DECLARE_ macros (see: opensim-core/3496) - -Wno-extra-semi - > - - # gcc - $<$: - # gcc-12 finds (possibly legit) bounds issues in simbody - requires investigation - -Wno-array-bounds - > -) - -set_target_properties(TestOpenSimCreator PROPERTIES - CXX_EXTENSIONS OFF - CXX_STANDARD_REQUIRED ON -) - # tell CMake (+IDEs) how to find all tests if(${OSC_DISCOVER_TESTS}) gtest_discover_tests(TestOpenSimCreator) diff --git a/tests/testoscar/CMakeLists.txt b/tests/testoscar/CMakeLists.txt index a1316e054..3a7e03aa6 100644 --- a/tests/testoscar/CMakeLists.txt +++ b/tests/testoscar/CMakeLists.txt @@ -1,6 +1,10 @@ include(GoogleTest) find_package(GTest REQUIRED CONFIG) +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/testoscarconfig.h.in" + "${CMAKE_CURRENT_BINARY_DIR}/generated/testoscar/testoscarconfig.h" +) add_executable(testoscar DOM/TestClass.cpp DOM/TestNode.cpp @@ -123,12 +127,13 @@ add_executable(testoscar TestingHelpers.h testoscar.cpp # entry point ) - -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/testoscarconfig.h.in" - "${CMAKE_CURRENT_BINARY_DIR}/generated/testoscar/testoscarconfig.h" +set_target_properties(testoscar PROPERTIES + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON +) +target_compile_features(testoscar PUBLIC + cxx_std_20 ) - target_include_directories(testoscar PRIVATE # so that the source code can `#include ` @@ -139,23 +144,11 @@ target_include_directories(testoscar PRIVATE ) target_link_libraries(testoscar PRIVATE - - # set compiler options - oscar_compiler_configuration - - # link to the to-be-tested library oscar - - # link to testing library GTest::gtest GTest::gtest_main ) -set_target_properties(testoscar PROPERTIES - CXX_EXTENSIONS OFF - CXX_STANDARD_REQUIRED ON -) - # tell CMake (+IDEs) how to find all tests if(${OSC_DISCOVER_TESTS}) gtest_discover_tests(testoscar) diff --git a/tests/testoscar_demos/CMakeLists.txt b/tests/testoscar_demos/CMakeLists.txt index 19c87b396..9b1265f5f 100644 --- a/tests/testoscar_demos/CMakeLists.txt +++ b/tests/testoscar_demos/CMakeLists.txt @@ -5,28 +5,25 @@ add_executable(testoscar_demos TestAllRegisteredDemoTabs.cpp testoscar_demos.cpp # entry point ) - +set_target_properties(testoscar_demos PROPERTIES + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON +) +target_compile_features(testoscar_demos PUBLIC + cxx_std_20 +) target_include_directories(testoscar_demos PRIVATE # so that the source code can `#include ` ${CMAKE_CURRENT_SOURCE_DIR}/.. ) - target_link_libraries(testoscar_demos PRIVATE - - oscar_compiler_configuration oscar oscar_demos - GTest::gtest GTest::gtest_main ) -set_target_properties(testoscar_demos PROPERTIES - CXX_EXTENSIONS OFF - CXX_STANDARD_REQUIRED ON -) - if(${OSC_DISCOVER_TESTS}) gtest_discover_tests(testoscar_demos) endif() diff --git a/third_party/README.md b/third_party/README.md index 0e22b1b96..a703ba4c0 100644 --- a/third_party/README.md +++ b/third_party/README.md @@ -1,10 +1,10 @@ # `third_party/`: Source Code for OpenSim Creator's Third-Party Dependencies This directory contains the source code for all (recursive) of OpenSim Creator's -third-party runtime dependencies. We use `git submodule` to fetch/version the +third-party runtime dependencies. We use `git submodule` to fetch/version all dependencies. -This directory also operates as a `cmake` build. It contains a `CMakeLists.txt` +This directory also operates as a `cmake` "superbuild". It contains a `CMakeLists.txt` file that uses the `ExternalProject` API to build+install these third-party dependencies into a standalone directory, so that OpenSim Creator's main build (`../CMakeLists.txt`) can find all necessary dependencies via a combination