Skip to content

Commit

Permalink
Auto-detect C++ extensions needed to build
Browse files Browse the repository at this point in the history
clang requires manually enabling C++ extensions via
`-std=c++<version>`, and ICU 75.1 needs C++17. Auto-detect the flags
that are needed to build.

Relates to #172

Closes #177
  • Loading branch information
stanhu committed Jul 9, 2024
1 parent 5f22c35 commit 1b5b275
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ext/charlock_holmes/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,30 @@
$CFLAGS << ' -Wall -funroll-loops'
$CFLAGS << ' -Wextra -O0 -ggdb3' if ENV['DEBUG']

minimal_program = <<~SRC
#include <unicode/translit.h>
int main() { return 0; }
SRC

# Pass -x c++ to force gcc to compile the test program
# as C++ (as it will end in .c by default).
compile_options = +"-x c++"

icu_requires_version_flag = checking_for("icu that requires explicit C++ version flag") do
!try_compile(minimal_program, compile_options)
end

if icu_requires_version_flag
abort "Cannot compile icu with your compiler: recent versions require C++17 support." unless %w[c++20 c++17 c++11 c++0x].any? do |std|
checking_for("icu that compiles with #{std} standard") do
if try_compile(minimal_program, compile_options + " -std=#{std}")
compile_options << " -std=#{std}"
$CPPFLAGS << " -std=#{std}"

true
end
end
end
end

create_makefile 'charlock_holmes/charlock_holmes'

0 comments on commit 1b5b275

Please sign in to comment.