Skip to content

Commit

Permalink
build: consolidate preferred compiler options (namely return-type)
Browse files Browse the repository at this point in the history
  • Loading branch information
malachib committed Dec 9, 2024
1 parent f284b05 commit c33b1fd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Added Features

* https://github.com/malachi-iot/estdlib/issues/70 CMake compiler option macro helper
* https://github.com/malachi-iot/estdlib/issues/69 `get<T>(tuple)` now available
* https://github.com/malachi-iot/estdlib/issues/58 ESP-IDF logging emulation

## Quality Updates & Bug Fixes

Expand Down
13 changes: 2 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,8 @@ else()
add_library(estd_lib ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} PUBLIC ${ESTD_INCLUDE_DIRECTORY})
# DEBT: Make a macro/function so we can compare "GNU-like" and include Clang, LLVM, etc.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Werror=return-type)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Kind of a blunt tool, but we're exporting so little anyway it's not too bad
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

# As per https://developercommunity.visualstudio.com/t/msvc-incorrectly-defines-cplusplus/139261
# DEBT: We'll likely want this PUBLIC or INTERFACE
target_compile_options(${PROJECT_NAME} PRIVATE /Zc:__cplusplus)
endif()

estd_compile_options()
endif()

add_library(malachi-iot::estd ALIAS ${PROJECT_NAME})
Expand Down
18 changes: 1 addition & 17 deletions test/catch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,7 @@ endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE UNIT_TESTING)

# TODO: Instead, filter by presence of GCC
if (MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /Zc:__cplusplus)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Werror=return-type)

# As per
# https://stackoverflow.com/questions/31890021/mingw-too-many-sections-bug-while-compiling-huge-header-file-in-qt
if(MSYS OR MINGW)
message(STATUS "MSYS mode")
target_compile_options(${PROJECT_NAME} PRIVATE -Wa,-mbig-obj)
endif()
endif()

# -Wno-unused-variable want this too, remember .H files aren't compiled independently
# so we have to report unused variables in unit tests fused with headers
# -Wextra) not ready for this just yet, but want it
estd_compile_options()

target_link_libraries(${PROJECT_NAME} estd Catch2::Catch2)

Expand Down
40 changes: 40 additions & 0 deletions tools/cmake/compiler.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
include_guard()

# DEBT: Add a parameter or option to change 'PRIVATE' default
# DEBT: Strongly consider making this "target_estd_compile_options" and friends


# -Wno-unused-variable want this too, remember .H files aren't compiled independently
# so we have to report unused variables in unit tests fused with headers
# -Wextra) not ready for this just yet, but want it


macro(estd_gcc_compile_options)
# Run, don't walk, do your nearest absent return type
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Werror=return-type)

# As per
# https://stackoverflow.com/questions/31890021/mingw-too-many-sections-bug-while-compiling-huge-header-file-in-qt
if(MSYS OR MINGW)
message(STATUS "MSYS mode")
target_compile_options(${PROJECT_NAME} PRIVATE -Wa,-mbig-obj)
endif()
endmacro()

macro(estd_msvc_compile_options)
# Kind of a blunt tool, but we're exporting so little anyway it's not too bad
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

# As per https://developercommunity.visualstudio.com/t/msvc-incorrectly-defines-cplusplus/139261
# DEBT: We'll likely want this PUBLIC or INTERFACE
target_compile_options(${PROJECT_NAME} PRIVATE /Zc:__cplusplus)
endmacro()

macro(estd_compile_options)
# DEBT: Make a macro/function so we can compare "GNU-like" and include Clang, LLVM, etc.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
estd_gcc_compile_options()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
estd_msvc_compile_options()
endif()
endmacro()
3 changes: 3 additions & 0 deletions tools/cmake/setvars.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
include_guard()

# This guy gets picked up by Catch2 tests as well as core estd itself

get_filename_component(TOOLS_DIR ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE)
get_filename_component(ROOT_DIR ${TOOLS_DIR}/../.. ABSOLUTE)
set(ESTD_DIR ${ROOT_DIR}/src)

include(${TOOLS_DIR}/CPM.cmake)
include(${TOOLS_DIR}/fetchcontent.cmake)
include(${TOOLS_DIR}/options.cmake)
include(${TOOLS_DIR}/compiler.cmake)

0 comments on commit c33b1fd

Please sign in to comment.