Skip to content

Commit

Permalink
[cmake] Require and enforce C++11 project wide.
Browse files Browse the repository at this point in the history
  - Instead of allowing C++11 on a target by target basis when needed,
    enable it globally. We would not be able to have a working omc or
    simulation as it is now without a compiler with C++11 support. So
    require it globally.

  - Unfortunately, we can not enforce c89/90 standards on our code at the
    moment as we rely heavily on C99 features and GNU extensions.
  • Loading branch information
mahge committed Aug 23, 2021
1 parent 5e72526 commit e1ed430
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
15 changes: 14 additions & 1 deletion OMCompiler/CMakeLists.txt
Expand Up @@ -18,7 +18,6 @@ string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}
string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")

# set(CMAKE_VERBOSE_MAKEFILE ON)

# include utility macros.
include(.cmake/omc_utils.cmake)
Expand All @@ -30,6 +29,20 @@ omc_add_to_report(CMAKE_CXX_COMPILER_ID)
omc_add_to_report(CMAKE_C_COMPILER_ID)
omc_add_to_report(CMAKE_LIBRARY_ARCHITECTURE)

#########################################################################################################
## Set the C standard to use. Unfortunately, we can not enforce c90.
## Our sources contain a lot of c99 and gnu extension code.
# set(CMAKE_C_STANDARD 90)

## Set the C++ standard to use.
set(CMAKE_CXX_STANDARD 11)
set(CXX_STANDARD_REQUIRED ON)
## Make sure we do not start relying on extensions down the road.
set(CMAKE_CXX_EXTENSIONS OFF)

#########################################################################################################
## Enable verbose Makefiles if you want to debug. (you can also instead use 'make VERBOSE=1')
# set(CMAKE_VERBOSE_MAKEFILE ON)

# Export compile commands (compile_commands.json) for each source file. This helps editors (e.g. vscode, emacs) have
# a more accurate code navigation and intellisense. E.g. includes can be pinpointed instead of
Expand Down
1 change: 0 additions & 1 deletion OMCompiler/Compiler/CMakeLists.txt
Expand Up @@ -150,7 +150,6 @@ add_custom_target(INTERFACE_CHECK
# Add a small dependency scanner program. This reads a list of list of dependencies and generates
# a list of dependents for each entry.
add_executable(dep_scanner ${CMAKE_CURRENT_SOURCE_DIR}/.cmake/dep_scanner.cpp)
target_compile_features(dep_scanner PRIVATE cxx_std_11)

# Write out a new line separated list of all MM source files to a list so that it can be easily
# parsed by the small MetaModelica dependency scanner we have now. (c++ code)
Expand Down
1 change: 0 additions & 1 deletion OMCompiler/Compiler/runtime/CMakeLists.txt
Expand Up @@ -69,7 +69,6 @@ add_library(omcruntime STATIC)
add_library(omc::compiler::runtime ALIAS omcruntime)

target_sources(omcruntime PRIVATE ${OMC_RUNTIIME_SOURCES})
target_compile_features(omcruntime PRIVATE cxx_std_11)

target_link_libraries(omcruntime PUBLIC omc::config)
target_link_libraries(omcruntime PUBLIC CURL::libcurl)
Expand Down

0 comments on commit e1ed430

Please sign in to comment.