diff --git a/CHANGES.md b/CHANGES.md index efa2b13..aa0f878 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,8 @@ -## 5.1.0 (2021-09-22) +### Pending + +- Don't use `-lpthread` and non-MSVC flags with MSVC compiler + +### 5.1.0 (2021-09-22) - Added let&-operator for implicit closing of an opened database. diff --git a/src/config/discover.ml b/src/config/discover.ml index 99db6a9..ceb7ffb 100644 --- a/src/config/discover.ml +++ b/src/config/discover.ml @@ -68,6 +68,16 @@ let split_ws str = done; List.rev !lst +let add_compiler_args ~is_msvc ~cflags ~libs = + let module C = Configurator.V1 in + match is_msvc with + | true -> { C.Pkg_config.cflags = cflags @ [ "/O2" ]; libs } + | false -> + { + C.Pkg_config.cflags = cflags @ [ "-O2"; "-fPIC"; "-DPIC" ]; + libs = libs @ [ "-lpthread" ]; + } + let () = let module C = Configurator.V1 in C.main ~name:"sqlite3" (fun c -> @@ -76,6 +86,11 @@ let () = | "macosx" -> true | _ -> false) in + let is_msvc = + opt_map (C.ocaml_config_var c "ccomp_type") ~default:false ~f:(function + | "msvc" -> true + | _ -> false) + in let is_mingw = opt_map (C.ocaml_config_var c "system") ~default:false ~f:(function | "mingw" | "mingw64" -> true @@ -111,6 +126,6 @@ let () = | [ libs ] -> split_ws libs | _ -> failwith "pkg-config failed to return libs" in - let conf = { C.Pkg_config.cflags; libs } in + let conf = add_compiler_args ~is_msvc ~cflags ~libs in C.Flags.write_sexp "c_flags.sexp" conf.cflags; C.Flags.write_sexp "c_library_flags.sexp" conf.libs) diff --git a/src/dune b/src/dune index dac3b8f..e3d72a9 100644 --- a/src/dune +++ b/src/dune @@ -5,10 +5,7 @@ (names sqlite3_stubs) (flags (:standard) - (:include c_flags.sexp) - -O2 - -fPIC - -DPIC)) + (:include c_flags.sexp))) (c_library_flags (:include c_library_flags.sexp)))