When changing build configuration (compiler definitions, link libraries, compile/link flags), ensure it is applied only when the correct feature option is enabled and the selected target/toolchain actually requires it. Avoid unconditional/global flags that can break other platforms or remove the ability to disable features.
Practical rules:
Example pattern (OpenMP):
option(NCNN_OPENMP "build with OpenMP" ON)
if(NCNN_OPENMP)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
# Apply to the actual consuming target(s)
target_link_libraries(my_executable PRIVATE OpenMP::OpenMP_CXX)
endif()
endif()
Example pattern (target/toolchain gating):
# Don’t treat any ANDROID-defined toolchain as an Android NDK build.
if(ANDROID AND ANDROID_NDK)
# android-specific flags/libs
endif()
# Don’t force XP-only definitions for every WIN32 build.
if(WIN32 AND NCNN_TARGET_XP)
target_compile_definitions(ncnn PUBLIC _WIN32_WINNT=0x0501 WINVER=0x0501)
endif()
Enter the URL of a public GitHub repository