-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake support #19
base: master
Are you sure you want to change the base?
CMake support #19
Conversation
tested on MinGW with GCC 7.3 & DWARF2 EH
I tested this on Linux and it seems to work ok. It would be nice to have more complete support (e.g. check target, shared version of library) but those can be added later I suppose. One thing that I think would be worth fixing is that the generated files are emitted into the source directory instead of the build directory -- I don't think this is a good idea. It is a minor "POLA violation" (so to speak) and makes it difficult to use same source dir for multiple parallel builds. Better to emit into CMAKE_CURRENT_BINARY_DIR and then add a -I... to the build flags. |
That should do it. I've also added minor comment regarding C/CXX flags. I'm quite amazed that this works on linux since I haven't even tried to make it so. ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be willing to sign the Google CLA at https://cla.developers.google.com/about/google-individual ?
Or have you signed an FSF copyright assignment?
If we add this change, how will people use it with cmake? Sorry if that is an obvious question--I don't know how cmake works.
.gitignore
Outdated
@@ -3,3 +3,8 @@ | |||
*.lo | |||
*.a | |||
*.la | |||
|
|||
backtrace-supported\.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does cmake support building in a separate directory, so that the sources can be read-only? If so, let's not modify .gitignore here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really that familiar with autotools but I've built this library using ./configure
and make
and it generated headers in source directory, as well as .a files. So I thought having .a and not .h in gitignore was a bug, not a feature. If I'm wrong I'll remove this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expectation is that people will run the equivalent of
mkdir x
cd x
../libbacktrace/configure
rather than running .configure
. It's OK to run ./configure
, but it shouldn't be necessary, and we need to make sure that running configure
from a different directory works without modifying the source directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reverted my changes in 28d7445
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does cmake support building in a separate directory, so that the sources can be read-only? If so, let's not modify .gitignore here.
Yes, via this command:
cmake -S <source-dir> -B <build-dir> [optional_arguments] # configure step
cmake --build <build-dir> # build step
The old CMake also allows separate build via:
mkdir build
cd build
cmake <path-to-source>
CMakeLists.txt
Outdated
# Assume multi-threaded environment | ||
set(BACKTRACE_SUPPORTS_THREADS 1) | ||
|
||
# Assume ELF/DWARF, meaning that BACKTRACE_SUPPORTS_DATA is hard-coded on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an unfortunate assumption, since we have PE and XCOFF support, and we really need Mach-O support. Do people not use cmake on those systems? Though I suppose we could also fix this up later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote for adding things later, since I've never worked with XCOFF or Mach-O files and platforms supporting them. Therefore I can't add support to them, so I guess there's little more options than putting notice in README that CMake support is in it's infancy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 9f5df7e
backtrace-supported.h.cmake
Outdated
@@ -0,0 +1,51 @@ | |||
/* backtrace-supported.h.cmake -- Whether stack backtrace is supported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some way we could generate this file from backtrace-supported.h.in, so that we don't have the unnecessary duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked right now and it's entirely possible. I'll do proper changes right away. config.h.in uses autotools-specific syntax, so unfortunately we need CMake variant.
@@ -0,0 +1,58 @@ | |||
/* config.h.cmake */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, can we generate this from config.h.in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config.h.in is useless from the perspective of cmake, as all of the entries in it are of the form #undef ....
.
A separate pre-processing step would be needed to transform the file into something cmake can use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
file(READ "config.h.in" original_config_h_in)
string(REGEX REPLACE "#undef" "#cmakedefine" new_config_h_cmake "${original_config_h_in}")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/config.h.cmake" "${new_config_h_cmake}")
configure_file("${CMAKE_CURRENT_BINARY_DIR}/config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/config.h")
Regarding CMake usage. Typically, one creates On Windows there's no standard way how I'm new to this CLA business and I don't mind transferring all the rights for contributions to this repo, but currently I'm not aware of any drawbacks related to signing. Which one is preferred: FSF (I see them listed in |
The Google CLA is easier to sign. The FSF approach involves a transfer of copyright and takes longer. Some people trust the FSF more than they trust Google (although the CLA is not a copyright transfer and requires very little trust). It's up to you which path to follow. I just want to make sure there is no copyright question on these changes. Thanks. |
I don't really feel like creating Google account just to sign into their CLA, especially since I see no direct connection between Google and this repo (Okay, you're Google employee, but repo's LICENSE states that it's FSF property). FSF is truly a pain because of postage thingy, so that's a no-go too. From what I've seen many repos use CLAHub which integrates nicely with GH. If this legal business is truly needed, could you please set it up using CLAHub for mine and future contributors' convenience? You can also integrate with pull requests so that there will be auto checks for CLA signage, so that's another benefit. |
At present the master sources for this library live in the GCC sources, which are covered by the FSF license. Google has an agreement with the FSF such that anything written by Google may be used by the FSF, so I feel moderately comfortable accepting code under the Google CLA. But I'm not comfortable using something else. Sorry. I can understand the desire to not create a Google account. I really only suggested that because the Google CLA is simpler. For the FSF agreement, start by filling out the form below and mailing it to [email protected]. Yes, this legal stuff is unfortunately truly needed. There have been significant legal problems in the past due to the lack of careful use of licensing agreements. These have had real world consequences. See, for example, https://en.wikipedia.org/wiki/SCO%E2%80%93Linux_disputes , in particular the so-called SCOsource program for users of GNU/Linux. Please email the following information to [email protected]. Please also CC the package maintainer(s). If you are uncomfortable We will send you the assignment form for your past and future changes. PLEASE USE YOUR FULL NAME AS THE SUBJECT LINE OF THE MESSAGE.* [What is the name of the program or package you're contributing to?] [Did you copy any files or text written by someone else in these changes? [Do you have an employer who might have a basis to claim to own [For the copyright registration, what country are you a citizen of?] [What year were you born?] [Please write your email address here.] [Please write your snail address here.] [Which files have you changed so far, and which new files have you written |
Done. Now we wait, I guess. Do I need to correct anything else in sources, or are we just waiting for legal thingy? |
.gitignore
Outdated
@@ -2,4 +2,4 @@ | |||
*.o | |||
*.lo | |||
*.a | |||
*.la |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what is changing here--no reason for .gitignore to change at all.
CMakeLists.txt
Outdated
@@ -0,0 +1,109 @@ | |||
cmake_minimum_required(VERSION 3.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we should add copyright header like the one in configure.ac.
CMakeLists.txt
Outdated
@@ -0,0 +1,109 @@ | |||
cmake_minimum_required(VERSION 3.5) | |||
|
|||
project(backtrace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backtrace or libbacktrace? People usually say libbacktrace, and that is what autoconf uses. Should probably libbacktrace unless there is some reason not to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use libbacktrace
, that way it will be different from the FindBacktrace CMake module associated with backtrace(3)
@@ -0,0 +1,14 @@ | |||
# Usage: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a copyright header.
@@ -0,0 +1,21 @@ | |||
set(PACKAGE_VERSION "1.0.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a copyright header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the idea of generating config.h.cmake from config.h.in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this @tehKaiN , I posted few comments and would also be happy to help move this forward.
CMakeLists.txt
Outdated
@@ -0,0 +1,109 @@ | |||
cmake_minimum_required(VERSION 3.5) | |||
|
|||
project(backtrace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use libbacktrace
, that way it will be different from the FindBacktrace CMake module associated with backtrace(3)
CMakeLists.txt
Outdated
@@ -0,0 +1,109 @@ | |||
cmake_minimum_required(VERSION 3.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this project is just being converted to CMake, I suggest to use the latest 3.12.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change CMake version, good point.
Regarding project name, I thought so too, but then it occurred to me that most CMake-packaged libs omit "lib" in their name - you type find_library(curl)
instead of find_library(libcurl)
. Also, IIRC if you tell cmake to find_library(blah)
it will look for libblah.a
automatically, so find_library(libbacktrace)
would result inf looking for liblibbacktrace.a
. I also wonder, for which package is FindBacktrace designed? What do you think about my points?
CMakeLists.txt
Outdated
) | ||
|
||
add_library(${PROJECT_NAME} ${sources} ${export_headers}) | ||
include_directories(${PROJECT_NAME} ${CMAKE_CURRENT_BINARY_DIR}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, prefer setting the variable set(CMAKE_INCLUDE_CURRENT_DIR ON)
at the top of the project
CMakeLists.txt
Outdated
if(ZLIB_FOUND) | ||
SET(HAVE_LIBZ 1) | ||
SET(HAVE_ZLIB 1) | ||
target_link_libraries(${PROJECT_NAME} z) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB)
CMakeLists.txt
Outdated
# Automake uses -frandom-seed initialized with file name of given file | ||
# but AFAIK it can't be done on CMake, so here's always same seed | ||
set(CMAKE_CXX_FLAGS "-DHAVE_CONFIG_H -funwind-tables -frandom-seed=mySeed -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -g -O2") | ||
set(CMAKE_C_FLAGS "-DHAVE_CONFIG_H -funwind-tables -frandom-seed=mySeed -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual -g -O2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public, private and interface flags should be differentiated and directly associated with the library target. For example:
target_compile_options(${PROJECT_NAME} PRIVATE -funwind-tables -frandom-seed=mySeed -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wmissing-format-attribute -Wcast-qual)
-
If there are compile option that must be used by project using the library, they should be declared as
INTERFACE.
INTERFACE
means that project linking against thelibbacktrace
imported target will transitively use the flag. -
HAVE_CONFIG_H
is not used in the project and should probably be removed. -
-g -O2
flags are automatically listed when building the project withRELWITHDEBINFO
build type. Is this a strong requirement ?
The default flags for each build type are available here:
CMakeLists.txt
Outdated
project(backtrace) | ||
|
||
# Automake uses -frandom-seed initialized with file name of given file | ||
# but AFAIK it can't be done on CMake, so here's always same seed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be possible, which file is expected to use as seed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to automake each file was using it's own file for seed. I don't think there's strong reason for that, so I guess we can just use same seed for every file.
Just in case you guys hadn't come across it, there's a version of this project cloned out of the GCC sources in 2014 at https://github.com/ErwanLegrand/libbacktrace that includes cmake support. |
I don't mind if someone merges that code and not mine, as long as linux/rpi/windows platforms are supported by it. |
Not suggesting that. It's not forked from this repo. so is inherently out of date, spent an hour trying to get his cmake script to work with this code without any success, then gave up as more trouble than it's worth. Was just drawing attention to it in case it was a useful reference. |
I am able to support something on Windows 10 (32bit; 64bit) with MSVC. |
@googlebot rescan |
What's blocking this from being merged? Is it just the unresolved feedback from the code review (e.g. adding copyright headers to a few files) or is it something else? I'd be willing to make the requested changes and get it moving along again. |
There are various unresolved comments as you can see. I'm also somewhat concerned about keeping this up to date, as I don't know or use cmake. But I guess we can try it and see. |
CMakeLists.txt
Outdated
else() | ||
set(ALLOC_FILE "alloc.c") | ||
endif() | ||
if(${ALLOC_FILE} STREQUAL "alloc.c") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to use ${} here, cmake will automatically unwrap the variable.
But you'd be better off moving the two SET() calls into the if(use_mmap_for_alloc) check anyway.
@@ -0,0 +1,21 @@ | |||
set(PACKAGE_VERSION "1.0.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use CMakePackageConfigHelpers
to automatically generate libbacktraceConfig.cmake
(from libbacktraceConfig.cmake.in
) and libbacktraceConfigVersion.cmake
.
Incomplete since I can only support Windows. Tested on MinGW with GCC 7.3 & DWARF2 EH
Fixes #12, at least for me ;)