Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Rework setting of compiler flags #596

Merged
merged 4 commits into from
Jan 21, 2023

Conversation

NexAdn
Copy link
Contributor

@NexAdn NexAdn commented Jan 9, 2023

This PR reworks how compiler flags are set, removing code duplication and unnecessary if-else blocks. This should reduce the complexity of the CMakeLists.txt and allows for users and packagers to append to the compiler flags as needed or desired (e.g. reducing the optimization level on a system where DPP might behave differently with -O3) and use the default build types to obtain the desired results (i.e. use Release and MinSizeRel build types instead of specifying -DBUILD_O3=true/false).

I've did a short successful test for the build types Debug, Release and MinSizeRel on Linux to ensure the flags are still set to the desired values and that the library compiles.

Debug:

$ ninja -v
[0/1] /usr/bin/cmake --regenerate-during-build -S/home/nex/projects/dpp -B/home/nex/projects/dpp/Debug
-- INFO: Explicitly disabling VCPKG as running inside the CI action.
-- Checking for ability to update autogenerated files
-- Checking for update to autogenerated files
-- No change required.
-- Sodium 1.0.18
-- Detected libsodium and libopus. VOICE support will be enabled
-- Building git version. Be aware git versions may be unstable!
Library install directory at /usr/local/lib64
Include files install directory at /usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nex/projects/dpp/Debug
[1/125] /usr/bin/c++ -DDPP_BUILD -DDPP_OS=Linux -DHAVE_PRCTL -DHAVE_PTHREAD_SETNAME_NP -DHAVE_VOICE -Ddpp_EXPORTS -I/home/nex/projects/dpp/library/../include -I/home/nex/projects/dpp/library/../include/dpp -Wall -Wno-psabi -Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough -Wmissing-field-initializers -Wsign-compare -Wtype-limits -Wuninitialized -Wshift-negative-value -pthread -g -Og -fPIC -Winvalid-pch -x c++-header -include /home/nex/projects/dpp/Debug/library/CMakeFiles/dpp.dir/cmake_pch.hxx -MD -MT library/CMakeFiles/dpp.dir/cmake_pch.hxx.gch -MF library/CMakeFiles/dpp.dir/cmake_pch.hxx.gch.d -o library/CMakeFiles/dpp.dir/cmake_pch.hxx.gch -c /home/nex/projects/dpp/Debug/library/CMakeFiles/dpp.dir/cmake_pch.hxx.cxx
<snip>

Release:

$ ninja -v
[0/1] /usr/bin/cmake --regenerate-during-build -S/home/nex/projects/dpp -B/home/nex/projects/dpp/Release
-- INFO: Explicitly disabling VCPKG as running inside the CI action.
-- Checking for ability to update autogenerated files
-- Checking for update to autogenerated files
-- No change required.
-- Sodium 1.0.18
-- Detected libsodium and libopus. VOICE support will be enabled
-- Building git version. Be aware git versions may be unstable!
Library install directory at /usr/local/lib64
Include files install directory at /usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nex/projects/dpp/Release
[1/125] /usr/bin/c++ -DDPP_BUILD -DDPP_OS=Linux -DHAVE_PRCTL -DHAVE_PTHREAD_SETNAME_NP -DHAVE_VOICE -Ddpp_EXPORTS -I/home/nex/projects/dpp/library/../include -I/home/nex/projects/dpp/library/../include/dpp -Wall -Wno-psabi -Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough -Wmissing-field-initializers -Wsign-compare -Wtype-limits -Wuninitialized -Wshift-negative-value -pthread -O3 -DNDEBUG -fPIC -Winvalid-pch -x c++-header -include /home/nex/projects/dpp/Release/library/CMakeFiles/dpp.dir/cmake_pch.hxx -MD -MT library/CMakeFiles/dpp.dir/cmake_pch.hxx.gch -MF library/CMakeFiles/dpp.dir/cmake_pch.hxx.gch.d -o library/CMakeFiles/dpp.dir/cmake_pch.hxx.gch -c /home/nex/projects/dpp/Release/library/CMakeFiles/dpp.dir/cmake_pch.hxx.cxx
<snip>

MinSizeRel:

ninja -v
[0/1] /usr/bin/cmake --regenerate-during-build -S/home/nex/projects/dpp -B/home/nex/projects/dpp/MinSizeRel
-- INFO: Explicitly disabling VCPKG as running inside the CI action.
-- Checking for ability to update autogenerated files
-- Checking for update to autogenerated files
-- No change required.
-- Sodium 1.0.18
-- Detected libsodium and libopus. VOICE support will be enabled
-- Building git version. Be aware git versions may be unstable!
Library install directory at /usr/local/lib64
Include files install directory at /usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nex/projects/dpp/MinSizeRel
[1/125] /usr/bin/c++ -DDPP_BUILD -DDPP_OS=Linux -DHAVE_PRCTL -DHAVE_PTHREAD_SETNAME_NP -DHAVE_VOICE -Ddpp_EXPORTS -I/home/nex/projects/dpp/library/../include -I/home/nex/projects/dpp/library/../include/dpp -Wall -Wno-psabi -Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough -Wmissing-field-initializers -Wsign-compare -Wtype-limits -Wuninitialized -Wshift-negative-value -pthread -Os -DNDEBUG -fPIC -Winvalid-pch -x c++-header -include /home/nex/projects/dpp/MinSizeRel/library/CMakeFiles/dpp.dir/cmake_pch.hxx -MD -MT library/CMakeFiles/dpp.dir/cmake_pch.hxx.gch -MF library/CMakeFiles/dpp.dir/cmake_pch.hxx.gch.d -o library/CMakeFiles/dpp.dir/cmake_pch.hxx.gch -c /home/nex/projects/dpp/MinSizeRel/library/CMakeFiles/dpp.dir/cmake_pch.hxx.cxx
<snip>

Note that parts of the Windows toolchain have been adjusted as well. However, I am unable to test this, since I don't have a Windows machine. We could still drop this if desired, but maybe we can find someone to test the Windows part as well. I've dropped the Windows stuff since the CI pipeline broke for some Windows builds.

Closes #595

@netlify
Copy link

netlify bot commented Jan 9, 2023

Deploy Preview for dpp-dev ready!

Name Link
🔨 Latest commit 373d694
🔍 Latest deploy log https://app.netlify.com/sites/dpp-dev/deploys/63bc5b47f629850007aeb9c5
😎 Deploy Preview https://deploy-preview-596--dpp-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

NexAdn and others added 4 commits January 9, 2023 19:21
This commit uses the CMake variables CMAKE_CXX_FLAGS_DEBUG and
CMAKE_CXX_FLAGS_RELEASE to handle setting varying compiler flags
depending on the build target. This gets rid of a bunch of if-else
blocks, allowing easier to read code.

Furthermore, common flags are put in CMAKE_CXX_FLAGS only once to reduce
code duplication.

Issue: brainboxdotcc#595
-std=c++17 is automatically set on demand by target_compile_features.
-fPIC is set by default for SHARED and MODULE targets and can be enabled
by target properties for STATIC targets.

Issue: brainboxdotcc#595
CMake provides various build types which already set the correct -O
levels and -g depending on the user's choice. This commit gets rid of
the previous explicit setting of these flags where possible.

Issue: brainboxdotcc#595
C++17 is required when building against DPP. As such, it should be a
PUBLIC compile feature.
@braindigitalis braindigitalis merged commit 2d46cca into brainboxdotcc:dev Jan 21, 2023
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.

2 participants