eranif / codelite

A multi purpose IDE specialized in C/C++/Rust/Python/PHP and Node.js. Written in C++
https://codelite.org
GNU General Public License v2.0
2.08k stars 444 forks source link

[Bug]: Please avoid hardcoding brewisms, it is prone to failure and may create a mess with the installation #3373

Open barracuda156 opened 1 month ago

barracuda156 commented 1 month ago

What happened?

CMakeLists hardcode a random third-party package manager as the requirement for macOS. This is wrong:

https://github.com/eranif/codelite/blob/801b86f2ce58f4b669ad8e1b205a1851b077393e/CMakeLists.txt#L165-L173

There is no conceivable reason why Homebrew (or any package manager at all) should be required. All needed software can be compiled directly, if desired.

It is also a bad advice to give unconditionally: for a general user is it preferable to use a package manager which is already used. Nothing checks for that or allows to configure it manually. Someone using MacPorts or Fink may mess everything up by installing random packages from Homebrew (as well as the other way round). There is no reason to assume a potential user has brew (or port) at all: these are not components of the OS or Xcode tools.

Version

Self compiled

Operating system

macOS

Steps to reproduce

Try building without Homebrew, witness things going wrong.

Relevant log output

--->  Configuring codelite
Executing:  cd "/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/build" && /opt/local/bin/cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_BUILD_TYPE=MacPorts -DCMAKE_INSTALL_PREFIX="/opt/local" -DCMAKE_INSTALL_NAME_DIR="/opt/local/lib" -DCMAKE_SYSTEM_PREFIX_PATH="/opt/local;/usr" -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_OBJC_COMPILER="$CC" -DCMAKE_OBJCXX_COMPILER="$CXX" -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_POLICY_DEFAULT_CMP0060=NEW -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_COLOR_MAKEFILE=ON -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_MAKE_PROGRAM=/usr/bin/make -DCMAKE_MODULE_PATH="/opt/local/share/cmake/Modules" -DCMAKE_PREFIX_PATH="/opt/local/share/cmake/Modules" -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON -DCMAKE_INSTALL_RPATH="/opt/local/lib" -Wno-dev -DWITH_WX_CONFIG=/opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.1/bin/wx-config -DCMAKE_OSX_ARCHITECTURES="arm64" -DCMAKE_OSX_DEPLOYMENT_TARGET="14.0" -DCMAKE_OSX_SYSROOT="/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk" /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/codelite-853cb73b8bba99542e70c2133dca5305f9b5b807 
-- The C compiler identification is AppleClang 15.0.0.15000309
-- The CXX compiler identification is AppleClang 15.0.0.15000309
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SQLite3: /opt/local/include (found version "3.46.0")
-- CMAKE_SYSTEM_PREFIX_PATH is set to /opt/local;/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr;/opt/local;/usr;/usr;/;/usr/X11R6;/usr/pkg;/opt
-- BUILD_DIRECTORY is set to /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/build
-- OS name Darwin
-- wx-config used is: /opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.1/bin/wx-config
-- wxWidgets version is: 3.2.4
CMake Error at cmake/Modules/OSXInstall.cmake:140 (string):
  string sub-command FIND does not allow one to select REVERSE as the output
  variable.  Maybe you missed the actual output variable?
Call Stack (most recent call first):
  cmake/Modules/OSXInstall.cmake:149 (_FIND_WX_LIBRARIES)
  CMakeLists.txt:248 (include)

CMake Error at cmake/Modules/OSXInstall.cmake:142 (string):
  string sub-command SUBSTRING requires four arguments.
Call Stack (most recent call first):
  cmake/Modules/OSXInstall.cmake:149 (_FIND_WX_LIBRARIES)
  CMakeLists.txt:248 (include)

-- _WX_LIB_NAME is set to 
-- LIBSSH_INCLUDE_DIR is set to LIBSSH_INCLUDE_DIR-NOTFOUND
CMake Error at CMakeLists.txt:272 (message):
  Could not locate libssh.  Please run 'brew install libssh'

-- Configuring incomplete, errors occurred!
eranif commented 1 month ago

This should be fixed now. The following packages are now being built from sources by CodeLite:

CodeLite no longer expects you to have brew installed. Note that since some of the packages are not using cmake you will be required to install autoconf (if you had brew, then it could be done by using brew install autoconf automake libtool gettext)

Please re-open this if you are facing more brew related issues (I tried this on 2 computers)

barracuda156 commented 1 month ago

@eranif Thank you for responding!

Could you please provide an option to use pre-installed libraries? What I meant initially is that forcing a particular package manager onto a user is undesirable, but provided package manager is used already, using existing libs makes a build faster, consumes less disk space and, importantly, may be strictly required in cases where default build of some dependency fails.

I tried now to run the build as-is, with bundled libs, and it failed on OpenSSL (and that is on Sonoma, not an exotic legacy system):

[  6%] Building C object crypto/CMakeFiles/crypto.dir/asn1/a_type.c.o
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/codelite-c3ce2bca0f70325fe08cac2ff61c8e4a77a0161c/submodules/openssl-cmake/crypto/cpt_err.c:57:34: error: use of undeclared identifier 'CRYPTO_R_FIPS_MODE_NOT_SUPPORTED'
    {ERR_PACK(ERR_LIB_CRYPTO, 0, CRYPTO_R_FIPS_MODE_NOT_SUPPORTED),
                                 ^
[  6%] Building C object crypto/CMakeFiles/crypto.dir/asn1/a_strex.c.o
1 error generated.
gmake[2]: *** [crypto/CMakeFiles/crypto.dir/build.make:76: crypto/CMakeFiles/crypto.dir/cpt_err.c.o] Error 1
gmake[2]: *** Waiting for unfinished jobs....
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/codelite-c3ce2bca0f70325fe08cac2ff61c8e4a77a0161c/submodules/openssl-cmake/crypto/uid.c:31:11: error: expected "FILENAME" or <FILENAME>
# include OPENSSL_UNISTD
          ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/codelite-c3ce2bca0f70325fe08cac2ff61c8e4a77a0161c/submodules/openssl-cmake/crypto/asn1/a_i2d_fp.c:18:5: error: conflicting types for 'ASN1_i2d_fp'
int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
    ^
/opt/local/include/openssl/asn1.h:943:5: note: previous declaration is here
int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, const void *x);
    ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/codelite-c3ce2bca0f70325fe08cac2ff61c8e4a77a0161c/submodules/openssl-cmake/crypto/asn1/a_i2d_fp.c:34:5: error: conflicting types for 'ASN1_i2d_bio'
int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
    ^
/opt/local/include/openssl/asn1.h:967:5: note: previous declaration is here
int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, const void *x);
    ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/codelite-c3ce2bca0f70325fe08cac2ff61c8e4a77a0161c/submodules/openssl-cmake/crypto/asn1/a_i2d_fp.c:71:5: error: conflicting types for 'ASN1_item_i2d_fp'
int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
    ^
/opt/local/include/openssl/asn1.h:950:5: note: previous declaration is here
int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, const void *x);
    ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/codelite-c3ce2bca0f70325fe08cac2ff61c8e4a77a0161c/submodules/openssl-cmake/crypto/asn1/a_i2d_fp.c:87:5: error: conflicting types for 'ASN1_item_i2d_bio'
int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
    ^
/opt/local/include/openssl/asn1.h:974:5: note: previous declaration is here
int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, const void *x);
    ^
4 errors generated.
. . . 

At the same time OpenSSL installs via MacPorts with no errors. I do not need anything in the upstream code to specifically call MacPorts, that will be wrong, but there are canonical ways to prefer pre-installed dependencies if those are found, and if not, then build and install bundled ones. CMake has everything needed for this.

I am sure if I try building with all dependencies bundled on a less mainstream platforms, things will be broken further. I have a PowerMac here :)

UPD. Ah, here it conflicts with pre-installed OpenSSL. This is solvable, but the point about an option is still relevant.

barracuda156 commented 1 month ago

Please re-open this if you are facing more brew related issues (I tried this on 2 computers)

@eranif I am afraid this option is restricted to members (?). I do not see an option to re-open the issue.

eranif commented 1 month ago

I wonder why it "sees" the installed OpenSSL, it shouldn't have.

The good news is that with the latest change, it should be easy to allow the user to specify the path to an existing libraries.

FYI: I too am using Sonoma (14) on ARM M2

eranif commented 1 month ago

This error looks like that the file #include <openssl/cryptoerr.h> is being used from system directories and not from the build directory

barracuda156 commented 1 month ago

I wonder why it "sees" the installed OpenSSL, it shouldn't have.

No idea, tbh, I did not specify openssl portgroup, so presumably it should not have found its headers. But anyway, we really want this to be flexible: even if everything builds neatly, not having to build unnecessary stuff saves time.

The good news is that with the latest change, it should be easy to allow the user to specify the path to an existing libraries.

This is awesome! Thank you, I will try it.

eranif commented 1 month ago

Could you please and try building it without CodeLite? (mainly, to understand the root cause of this) It should be easy:

cd codelite-src/submodules/openssl-cmake/
mkdir build-release
cd $_
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(sysctl -n hw.physicalcpu)
eranif commented 1 month ago

QQ: I see that libssh provides libssh-config.cmake and libssh-config-release.cmake do you have these files as part of your local builds, and where are these files are placed? (CodeLite does not use OpenSSL directly, it is needed with SSH support)

I was planning on adding:

cmake .. -DWITH_LIBSSH=/opt/homebrew

(Replace /opt/homebrew with the root location of your install)

barracuda156 commented 1 month ago

QQ: I see that libssh provides libssh-config.cmake and libssh-config-release.cmake do you have these files as part of your local builds, and where are these files are placed? (CodeLite does not use OpenSSL directly, it is needed with SSH support)

Is it libssh or libssh2? The first installs CMake config: https://ports.macports.org/port/libssh/details (if you click on Files on the right, it will show list of installed files). libssh2 is built without CMake, so it only installs libssh2.pc, but CMake can use those too. https://ports.macports.org/port/libssh2/details

As long as there is some reasonable way to point the build system to the needed libraries, all is good.

P. S. Since some libraries may be installed in a custom way (to allow co-existing versions, for example), it is helpful to be able to specify includes and libs separately. But normally CMake can handle that via canonical arguments.

eranif commented 1 month ago

No, I am using libssh (without the 2). On my mac using brew, there is no FindLibSSH.cmake file, only the one I mentioned above

barracuda156 commented 1 month ago

Could you please and try building it without CodeLite? (mainly, to understand the root cause of this)

Manually it works, at least on Sonoma:

svacchanda@43-226 ~ % cd /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/codelite-c3ce2bca0f70325fe08cac2ff61c8e4a77a0161c/submodules/openssl-cmake
svacchanda@43-226 openssl-cmake % sudo mkdir build-release
Password:
svacchanda@43-226 openssl-cmake % cd  build-release
svacchanda@43-226 build-release % sudo /opt/local/bin/cmake .. -DCMAKE_BUILD_TYPE=Release
CMake Deprecation Warning at CMakeLists.txt:26 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- The C compiler identification is AppleClang 15.0.0.15000309
-- The CXX compiler identification is AppleClang 15.0.0.15000309
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- OpenSSL version 1.1.1w
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of long
-- Check size of long - done
-- Check size of long long
-- Check size of long long - done
-- Check size of int
-- Check size of int - done
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done (4.8s)
-- Generating done (0.2s)
-- Build files have been written to: /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_editors_codelite/codelite/work/codelite-c3ce2bca0f70325fe08cac2ff61c8e4a77a0161c/submodules/openssl-cmake/build-release
svacchanda@43-226 build-release % sudo make -j$(sysctl -n hw.physicalcpu)
[  0%] Building C object crypto/CMakeFiles/crypto.dir/ebcdic.c.o
[  0%] Building C object crypto/CMakeFiles/crypto.dir/cpt_err.c.o
[  0%] Building C object crypto/CMakeFiles/crypto.dir/cversion.c.o
[  0%] Building C object crypto/CMakeFiles/crypto.dir/ctype.c.o
[  0%] Building C object crypto/CMakeFiles/crypto.dir/ex_data.c.o
[  0%] Building C object crypto/CMakeFiles/crypto.dir/cryptlib.c.o
[  0%] Building C object crypto/CMakeFiles/crypto.dir/init.c.o
[  1%] Building C object crypto/CMakeFiles/crypto.dir/mem.c.o
[  1%] Building C object crypto/CMakeFiles/crypto.dir/mem_clr.c.o
[  1%] Building C object crypto/CMakeFiles/crypto.dir/mem_sec.c.o
[  1%] Building C object crypto/CMakeFiles/crypto.dir/mem_dbg.c.o
[  1%] Building C object crypto/CMakeFiles/crypto.dir/o_dir.c.o
[  1%] Building C object crypto/CMakeFiles/crypto.dir/o_fips.c.o
[  1%] Building C object crypto/CMakeFiles/crypto.dir/o_fopen.c.o
[  2%] Building C object crypto/CMakeFiles/crypto.dir/o_init.c.o
[  2%] Building C object crypto/CMakeFiles/crypto.dir/o_str.c.o
[  2%] Building C object crypto/CMakeFiles/crypto.dir/o_time.c.o
. . .
[ 92%] Building C object ssl/CMakeFiles/ssl.dir/statem/statem_srvr.c.o
[ 92%] Building C object ssl/CMakeFiles/ssl.dir/statem/statem_lib.c.o
[ 93%] Linking C static library libssl.a
[ 93%] Built target ssl
[ 93%] Building C object apps/CMakeFiles/openssl.dir/apps.c.o
[ 93%] Building C object apps/CMakeFiles/openssl.dir/cms.c.o
[ 93%] Building C object apps/CMakeFiles/openssl.dir/crl.c.o
[ 93%] Building C object apps/CMakeFiles/openssl.dir/app_rand.c.o
[ 93%] Building C object apps/CMakeFiles/openssl.dir/asn1pars.c.o
[ 93%] Building C object apps/CMakeFiles/openssl.dir/ciphers.c.o
[ 94%] Building C object apps/CMakeFiles/openssl.dir/bf_prefix.c.o
[ 94%] Building C object apps/CMakeFiles/openssl.dir/ca.c.o
[ 94%] Building C object apps/CMakeFiles/openssl.dir/crl2p7.c.o
[ 94%] Building C object apps/CMakeFiles/openssl.dir/dgst.c.o
[ 95%] Building C object apps/CMakeFiles/openssl.dir/dhparam.c.o
[ 95%] Building C object apps/CMakeFiles/openssl.dir/dsa.c.o
[ 95%] Building C object apps/CMakeFiles/openssl.dir/dsaparam.c.o
[ 95%] Building C object apps/CMakeFiles/openssl.dir/ec.c.o
[ 95%] Building C object apps/CMakeFiles/openssl.dir/ecparam.c.o
[ 95%] Building C object apps/CMakeFiles/openssl.dir/enc.c.o
[ 95%] Building C object apps/CMakeFiles/openssl.dir/engine.c.o
[ 95%] Building C object apps/CMakeFiles/openssl.dir/errstr.c.o
[ 96%] Building C object apps/CMakeFiles/openssl.dir/gendsa.c.o
[ 96%] Building C object apps/CMakeFiles/openssl.dir/genpkey.c.o
[ 96%] Building C object apps/CMakeFiles/openssl.dir/genrsa.c.o
[ 96%] Building C object apps/CMakeFiles/openssl.dir/nseq.c.o
[ 96%] Building C object apps/CMakeFiles/openssl.dir/ocsp.c.o
[ 96%] Building C object apps/CMakeFiles/openssl.dir/opt.c.o
[ 96%] Building C object apps/CMakeFiles/openssl.dir/openssl.c.o
[ 97%] Building C object apps/CMakeFiles/openssl.dir/passwd.c.o
[ 97%] Building C object apps/CMakeFiles/openssl.dir/pkcs7.c.o
[ 97%] Building C object apps/CMakeFiles/openssl.dir/pkcs12.c.o
[ 97%] Building C object apps/CMakeFiles/openssl.dir/pkcs8.c.o
[ 97%] Building C object apps/CMakeFiles/openssl.dir/pkey.c.o
[ 97%] Building C object apps/CMakeFiles/openssl.dir/pkeyutl.c.o
[ 97%] Building C object apps/CMakeFiles/openssl.dir/pkeyparam.c.o
[ 98%] Building C object apps/CMakeFiles/openssl.dir/prime.c.o
[ 98%] Building C object apps/CMakeFiles/openssl.dir/rand.c.o
[ 98%] Building C object apps/CMakeFiles/openssl.dir/req.c.o
[ 98%] Building C object apps/CMakeFiles/openssl.dir/rehash.c.o
[ 98%] Building C object apps/CMakeFiles/openssl.dir/rsa.c.o
[ 98%] Building C object apps/CMakeFiles/openssl.dir/rsautl.c.o
[ 98%] Building C object apps/CMakeFiles/openssl.dir/s_cb.c.o
[ 99%] Building C object apps/CMakeFiles/openssl.dir/s_server.c.o
[ 99%] Building C object apps/CMakeFiles/openssl.dir/s_client.c.o
[ 99%] Building C object apps/CMakeFiles/openssl.dir/s_socket.c.o
[ 99%] Building C object apps/CMakeFiles/openssl.dir/s_time.c.o
[ 99%] Building C object apps/CMakeFiles/openssl.dir/sess_id.c.o
[ 99%] Building C object apps/CMakeFiles/openssl.dir/smime.c.o
[ 99%] Building C object apps/CMakeFiles/openssl.dir/speed.c.o
[ 99%] Building C object apps/CMakeFiles/openssl.dir/spkac.c.o
[100%] Building C object apps/CMakeFiles/openssl.dir/storeutl.c.o
[100%] Building C object apps/CMakeFiles/openssl.dir/srp.c.o
[100%] Building C object apps/CMakeFiles/openssl.dir/verify.c.o
[100%] Building C object apps/CMakeFiles/openssl.dir/ts.c.o
[100%] Building C object apps/CMakeFiles/openssl.dir/version.c.o
[100%] Building C object apps/CMakeFiles/openssl.dir/x509.c.o
[100%] Linking C executable openssl
ld: warning: ignoring duplicate libraries: '../crypto/libcrypto.a'
[100%] Built target openssl

(PowerPC is busy compiling other stuff.)

barracuda156 commented 1 month ago

No, I am using libssh (without the 2). On my mac using brew, there is no FindLibSSH.cmake file, only the one I mentioned above

@eranif So it is the same with MacPorts here.