Skip to content

Adding CMakeLists.txt for cpp version#206

Open
micaah42 wants to merge 4 commits intonayuki:masterfrom
micaah42:master
Open

Adding CMakeLists.txt for cpp version#206
micaah42 wants to merge 4 commits intonayuki:masterfrom
micaah42:master

Conversation

@micaah42
Copy link
Copy Markdown

@micaah42 micaah42 commented Sep 24, 2024

Hello there,

I added a minimal CMakeLists.txt to make it easier to include this repository in cmake driven projects.

You can build a static library using:

cd cpp
mkdir build && cd build
cmake ..
make

Or include in other projects like this:

include(FetchContent)

FetchContent_Declare(qrcodegen
    SOURCE_SUBDIR cpp
    GIT_REPOSITORY git@github.com:micaah42/QR-Code-generator.git
    GIT_TAG master
)
FetchContent_MakeAvailable(qrcodegen)

If you have any notes or want something fixed let me know :)

@lexuanquynh
Copy link
Copy Markdown

Support for MACOS and iOS:
https://github.com/leetal/ios-cmake

Comment thread cpp/CMakeLists.txt

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

@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

Copy link
Copy Markdown

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 …

@Neustradamus
Copy link
Copy Markdown

@nayuki: Have you seen this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants