Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.22)

project(qrcodegen LANGUAGES CXX VERSION 2.0)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAXE_CXX_FLAGS} -Wall -Werror")
Copy link

@AlexisCompain AlexisCompain Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only work for compiler that accepts this options (gcc/clang) but won't work for MSVC for example

I use this variant that is compatible with msvc too

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
    add_compile_options(/W4 /EHsc)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    add_compile_options(-Wall -Wextra)
endif()

Note: additionally use add_compile_options instead of set for beter portability

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And please don't add -Werror. When I build this next year and my gcc18 suddenly comes with new warnings this will need patching. Instead do:

set(CMAKE_COMPILE_WARNING_AS_ERROR On)

This was introduced in 3.24 and will just do nothing in older versions. This can then easily be disabled from the command line:

cmake --compile-no-warning-as-error …


add_library(${PROJECT_NAME} STATIC
qrcodegen.hpp
qrcodegen.cpp
)

target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR})