Repository: ledger/ledger (language: cpp)

Issue:
ledger failed to build on clang 8.0.1 (__PIC__ level differs in PCH file)
This is my command line
```
$ env CXX=c++ python3 ./acprep update
```

It failed with
```
[ 83%] Building CXX object src/CMakeFiles/ledger.dir/main.cc.o
error: __PIC__ level differs in PCH file vs. current file
```

By observing the compiling command lines via `acprep update -v`, I found 
 - `cmake_pch.hxx.pch` was built with `-fPIC` flag
 - `libledger.so` was built with `-fPIC` flag 
 - but `main.cc.o` is not compiled with `-fPIC` flag

I found `main.cc.o` could be compiled if I made one of following changes:
 - add `-fPIC` flag to the compile flags of `main.cc.o` , or
 - remove `-include-pch cmake_pch.hxx.pch` from the compile flags of `main.cc.o`

I guess the right way to fix it is either:
 - build everything with `-fPIC`, or
 - build two versions of PCH file, one with `-fPIC` for library and one without `-fPIC` for executable

-----
More information:
 - ledger version is v.3.2.1 (56c42e11fe58828af39d43a972033741a5f5e27e)
 - my OS is FreeBSD 12.1-RELEASE-p2
 - clang version is 8.0.1
 - cmake version 3.17.2



Discussion / hints:
For anyone coming to this problem, I found that switching the compiler from Clang to GCC fixed this issue.
I am also attempting to compile ledger under FreeBSD (13.0) and am seeing the same error.  Could you please clarify where one should specify -fPIC for main.cc?

Thank you.

> This is my command line
> 
> ```
> $ env CXX=c++ python3 ./acprep update
> ```
> 
> It failed with
> 
> ```
> [ 83%] Building CXX object src/CMakeFiles/ledger.dir/main.cc.o
> error: __PIC__ level differs in PCH file vs. current file
> ```
> 
> ...
> More information:
> 
>     * ledger version is v.3.2.1 ([56c42e1](https://github.com/ledger/ledger/commit/56c42e11fe58828af39d43a972033741a5f5e27e))
> 
>     * my OS is FreeBSD 12.1-RELEASE-p2
> 
>     * clang version is 8.0.1
> 
>     * cmake version 3.17.2


Closing as wontfix as clang 8 is about 4 years old and Ledger only tries to support dependencies ~ younger than 4 years.
If you have a compelling reason for this to be worked on, please speak up and re-open this issue.
Hi, I have the same issue on OpenBSD and clang 13.0.0.

For the record: A really easy fix is to set the environment variable `CXXFLAGS+=-fPIC`. I do:
```
CXXFLAGS=-fPIC ./acprep update
```

Fix patch:
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f229d70cd..f64ab8397 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -287,6 +287,8 @@ if (BUILD_LIBRARY)
     INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
     VERSION ${Ledger_VERSION_MAJOR}
     SOVERSION ${Ledger_VERSION_MAJOR})
+  set_source_files_properties(
+    ${LEDGER_CLI_SOURCES} PROPERTIES COMPILE_FLAGS "-fPIC")
 
   add_executable(ledger main.cc global.cc)
   target_link_libraries(ledger libledger)


Test patch: