### Description
Using `cmake` to compile on MacOS (Darwin) 15.1.1 (Sequoia) fails.
### Troubleshooting
#### Reproduction
<!-- If the issue can be reproduced, describe how it can be done. -->
#### Debugging Data
``` mkdir buildmac cd buildmac/ cmake .. make VERBOSE=1 /opt/local/bin/cmake -S/tmp/kamailio -B/tmp/kamailio/buildmac --check-build-system CMakeFiles/Makefile.cmake 0 /opt/local/bin/cmake -E cmake_progress_start /tmp/kamailio/buildmac/CMakeFiles /tmp/kamailio/buildmac//CMakeFiles/progress.marks /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all /Applications/Xcode.app/Contents/Developer/usr/bin/make -f src/core/CMakeFiles/GenerateParser.dir/build.make src/core/CMakeFiles/GenerateParser.dir/depend cd /tmp/kamailio/buildmac && /opt/local/bin/cmake -E cmake_depends "Unix Makefiles" /tmp/kamailio /tmp/kamailio/src/core /tmp/kamailio/buildmac /tmp/kamailio/buildmac/src/core /tmp/kamailio/buildmac/src/core/CMakeFiles/GenerateParser.dir/DependInfo.cmake "--color=" Dependencies file "src/core/CMakeFiles/GenerateParser.dir/lex.yy.c.o.d" is newer than depends file "/tmp/kamailio/buildmac/src/core/CMakeFiles/GenerateParser.dir/compiler_depend.internal". Consolidate compiler generated dependencies of target GenerateParser /Applications/Xcode.app/Contents/Developer/usr/bin/make -f src/core/CMakeFiles/GenerateParser.dir/build.make src/core/CMakeFiles/GenerateParser.dir/build [ 0%] Building C object src/core/CMakeFiles/GenerateParser.dir/lex.yy.c.o cd /tmp/kamailio/buildmac/src/core && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 -DARCH="arm64" -DCFG_DIR="/usr/local/etc/kamailio/" -DCOMPILER="16.0.0.16000026" -DDBG_SR_MEMORY -DDISABLE_NAGLE -DDNS_IP_HACK -DFAST_LOCK -DFMSTATS -DF_MALLOC -DHAVE_RESOLV_RES -DKMSTATS -DKSR_PTHREAD_MUTEX_SHARED -DMALLOC_STATS -DNAME="kamailio" -DOS=Darwin -DOS_QUOTED="Darwin" -DPIC -DPKG_MALLOC -DQ_MALLOC -DRAW_SOCKS -DRUN_DIR="/var/run/kamailio" -DSHARE_DIR="/usr/local/share/kamailio/" -DSHM_MMAP -DSTATISTICS -DTLSF_MALLOC -DTLS_HOOKS -DUSE_DNS_CACHE -DUSE_DNS_FAILOVER -DUSE_DST_BLOCKLIST -DUSE_FUTEX -DUSE_MCAST -DUSE_NAPTR -DUSE_SCTP -DUSE_TCP -DUSE_TLS -DVERSION="6.0.0-dev2" -DVERSIONVAL=6000000 -D__CPU_arm64 -D__OS_darwin -std=gnu11 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk -MD -MT src/core/CMakeFiles/GenerateParser.dir/lex.yy.c.o -MF CMakeFiles/GenerateParser.dir/lex.yy.c.o.d -o CMakeFiles/GenerateParser.dir/lex.yy.c.o -c /tmp/kamailio/src/core/lex.yy.c In file included from /tmp/kamailio/src/core/cfg.lex:33: In file included from /tmp/kamailio/src/core/globals.h:34: In file included from /tmp/kamailio/src/core/ip_addr.h:39: In file included from /tmp/kamailio/src/core/ut.h:46: In file included from /tmp/kamailio/src/core/mem/shm_mem.h:32: In file included from /tmp/kamailio/src/core/mem/shm.h:44: In file included from /tmp/kamailio/src/core/mem/../lock_ops.h:92: /tmp/kamailio/src/core/mem/../fastlock.h:130:2: error: "unknown architecture" 130 | #error "unknown architecture" | ^ /tmp/kamailio/src/core/mem/../fastlock.h:294:2: error: "unknown architecture" 294 | #error "unknown architecture" | ^ /tmp/kamailio/src/core/mem/../fastlock.h:317:2: error: call to undeclared function 'membar_getlock'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 317 | membar_getlock(); | ^ /tmp/kamailio/src/core/mem/../fastlock.h:328:2: error: call to undeclared function 'membar_getlock'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 328 | membar_getlock(); | ^ /tmp/kamailio/src/core/mem/../fastlock.h:436:2: error: "unknown architecture" 436 | #error "unknown architecture" | ^ 5 errors generated. make[2]: *** [src/core/CMakeFiles/GenerateParser.dir/lex.yy.c.o] Error 1 make[1]: *** [src/core/CMakeFiles/GenerateParser.dir/all] Error 2 make: *** [all] Error 2 ```
Compiling with the old Makefiles (just git clone and then `make Q=0`), the compile command looks like:
``` gcc -g -pthread -DKSR_PTHREAD_MUTEX_SHARED -Wunused-variable -Wuninitialized -DNAME='"kamailio"' -DVERSION='"6.0.0-dev3"' -DARCH='"arm64"' -DOS='darwin_' -DOS_QUOTED='"darwin"' -DCOMPILER='"gcc Apple clang version 16.0.0 (clang-1600.0.26.4)"' -D__CPU_arm64 -D__OS_darwin -DVERSIONVAL=6000000 -DCFG_DIR='"/opt/local/etc/kamailio/"' -DSHARE_DIR='"/opt/local/share/kamailio/"' -DRUN_DIR='"/var/run/kamailio/"' -DPKG_MALLOC -DSHM_MMAP -DDNS_IP_HACK -DUSE_MCAST -DUSE_TCP -DDISABLE_NAGLE -DHAVE_RESOLV_RES -DUSE_DNS_CACHE -DUSE_DNS_FAILOVER -DUSE_DST_BLOCKLIST -DUSE_NAPTR -DMEM_JOIN_FREE -DF_MALLOC -DQ_MALLOC -DTLSF_MALLOC -DDBG_SR_MEMORY -DUSE_TLS -DTLS_HOOKS -DUSE_CORE_STATS -DSTATISTICS -DMALLOC_STATS -DUSE_SCTP -DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL -DUSE_ANON_MMAP -DNDEBUG -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM -DUSE_SIGWAIT -DHAVE_IP_MREQN -DUSE_PTHREAD_MUTEX -DUSE_SYSV_SEM -DHAVE_KQUEUE -DHAVE_SELECT -c core/lex.yy.c -o core/lex.yy.o ```
### Possible Solutions
<!-- If you found a solution or workaround for the issue, describe it. Ideally, provide a pull request with a fix. -->
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` Kamailio master branch ```
* **Operating System**:
``` ❯ uname -a Darwin Mac 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:11 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6020 arm64
❯ uname -m arm64
❯ uname -p arm
❯ cmake --version cmake version 3.29.5
CMake suite maintained and supported by Kitware (kitware.com/cmake). ```
The compile flags are different, among them for example, with old Makefiles is set `-DUSE_SYSV_SEM`.
Hey @miconda,
Regarding the unknown architecture, it seems that CMake defines the arch as `arm64` for your machine instead of `aarch64` and therefore `__CPU_arm64` is defined (and not an option in `fastlock.h`). As far as I can understand they are one and the same. [see this SO](https://stackoverflow.com/questions/31851611/differences-between-arm64-and-a...).
Two options I see for this, either 1. I can have CMake alter this arch to `aarch64` and it will pick up the correct path. 2. Add `__CPU_arm64` as a possible value in fastlock.h right next to the `__CPU_aarch64`.
I would go for the second option, as I find it more clean and descriptive but of course we can discuss it.
The compile flags are different, among them for example, with old Makefiles is set `-DUSE_SYSV_SEM`.
Actually, I didn't populate any Apple specific flags. You can these that in `cmake/os_specific.cmake`. I will introduce an `apple` specific branch one and let you know.
I think internally in the Kamailio we are using the "arm64" definition for the Mac, e.g. used below (commit ab1831efc2081).
src/core/atomic/atomic_unknown.h: #if defined __CPU_arm64 && defined __OS_darwin /* fallback to locking-variant of atomic ops for OSes used for development * - MacOS with Apple silicon */ #else #warning no native memory barrier implementations, falling back to slow lock \ based workaround #endif
The aarch64 used elsewhere is for actual ARM processors, like embedded systems. We probably need to detect or anticipate this special architecture in the cmake as well.
After some review of the https://github.com/kamailio/kamailio/blob/093d0cca8c4a529b5330a0b85fa150d85a...
i can see that `FAST_LOCK` is not enabled for the `arm64`. is that intentional? if yes, I will revise the respective `CMakefile`, to not allow `FAST_LOCK` on arm64 and darwin machines
Indeed, the FAST_LOCK is not defined on MacOS when compiling using the old Makefiles. I guess it has to be as an option and decide based on cpu/arch to use it or not.
Ultimately MacOS is not a primary target for server side, but afaik it is similar with many *BSDs, and some people were using K on *BSD along the time. That's why I tried again on MacOS to see how it goes.
Do you want me to push directly to master?
or Shall I create PR after some basic testing because I currently cant do it as I do not own a MacOS machine?
Right now I pushed the new commit related to `macos` to cmake branch.
I have some more commits related to clean up/structuring/add support for new features (that were present in makefiles). What would be the best approach?
I think bugfixes or smaller extensions to the cmake can be pushed directly to the master, as you are the main developer working on that topic right now. It also makes it easier to test for other people.
Pushing to master branch is ok, simplifies things.
I noticed in the previous commit that it has `include(${OS_SPECIFIC_DIR}/darwin.cmake)` but the new file name is `macos.cmake`.
ahhh good catch... fixing it now.
Just pushed two small commits (d416f7207a39db5ec15c0133904bfd76980a9d4b 2d59d44dd620c597e69f7f1b3d6a9d1b3d410ae3) that made it compile on macos.
When I get some time, I can investigate to see if the option 2. (`Add __CPU_arm64 as a possible value in fastlock.h right next to the __CPU_aarch64`) proposed in a comment above is a good alternative.
Great, thanks for the commits!
We can use `STREQUAL` for exact matching but I think it will be more Verbose to write and regex seems good enough.
Closed #4049 as completed.
For now should be good enough, thanks for helping! Closing it.