Skip to content
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

Add cmake support #31

Closed
wants to merge 4 commits into from
Closed

Add cmake support #31

wants to merge 4 commits into from

Conversation

banshee
Copy link
Contributor

@banshee banshee commented Aug 19, 2018

I added cmake support for myself (I wanted to use CLion), and I'm happy to add it in to the project if it's interesting for other people. There's some cleanup work to be done here before merge (although it's working), I just wanted to see if it's worth doing.

@albertschulz
Copy link

Would love to see CMake support for this repository. @aclements could this request be accepted?

@banshee
Copy link
Contributor Author

banshee commented Jun 26, 2020

Just FYI, it's been a long time since I touched anything to do with CMake, so I'm unlikely to be able to do contribute anything additional here. I had totally forgotten about this until I saw the update from a week ago.

@banshee
Copy link
Contributor Author

banshee commented Jun 26, 2020

Looks like there's another PR that includes cmake - #37

@Smertig
Copy link

Smertig commented Sep 6, 2020

I wish this PR (or #37) would be accepted. CMake is the most popular tool for managing C++ build process.

@aclements, it would be great, if you take a look at this PR.

@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.6)

project (elfin)

set(CMAKE_CXX_STANDARD 17)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be 11, not 17


project (elfin)

set(CMAKE_CXX_STANDARD 17)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 11)

Comment on lines +7 to +9
add_subdirectory(elf elfdir)
add_subdirectory(dwarf dwarfdir)
add_subdirectory(examples examplesdir)
Copy link

@madebr madebr Oct 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an immediate subdirectory in the source tree as a different directory in the build directory is not necessary.
Also, optionally building the examples is nice as they are not needed when e.g. only wanting to build the library or adding libelfin as a subdirectory/subproject.

Suggested change
add_subdirectory(elf elfdir)
add_subdirectory(dwarf dwarfdir)
add_subdirectory(examples examplesdir)
option(BUILD_LIBELFIN_EXAMPLES "Build libelfin examples" ON)
add_subdirectory(elf)
add_subdirectory(dwarf)
if(BUILD_LIBELFIN_EXAMPLES)
add_subdirectory(examples)
endif()

Comment on lines +5 to +6
set(dwarfH ${CMAKE_CURRENT_LIST_DIR}/dwarf++.hh)
set(dataH ${CMAKE_CURRENT_LIST_DIR}/data.hh)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(dwarfH ${CMAKE_CURRENT_LIST_DIR}/dwarf++.hh)
set(dataH ${CMAKE_CURRENT_LIST_DIR}/data.hh)
set(dwarfH ${CMAKE_CURRENT_SOURCE_DIR}/dwarf++.hh)
set(dataH ${CMAKE_CURRENT_SOURCE_DIR}/data.hh)

add_library(dwarf dwarf.cc cursor.cc die.cc value.cc abbrev.cc
expr.cc rangelist.cc line.cc attrs.cc
die_str_map.cc elf.cc ${to_string_src})
target_include_directories(dwarf PUBLIC ${CMAKE_CURRENT_LIST_DIR})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_include_directories(dwarf PUBLIC ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(dwarf PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})


add_custom_command(
OUTPUT ${to_string_src}
COMMAND bash ${configured_to_string_script} ${dwarfH} ${dataH} ${to_string_src})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bash is not really cross platform (it is less often available on Windows then python).
I would just use a add_custom_command with all commands from the bash script.

See conan-io/conan-center-index#3283 for an example.


project(elf)

set(toStringInputHeader ${CMAKE_CURRENT_LIST_DIR}/data.hh)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(toStringInputHeader ${CMAKE_CURRENT_LIST_DIR}/data.hh)
set(toStringInputHeader ${CMAKE_CURRENT_SOURCE_DIR}/data.hh)

configure_file(create_to_string_code.sh ${configured_to_string_script})

add_custom_command(
OUTPUT ${to_string_src}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark as the dwarf library.
I would not use bash but add these commands directly here.
See conan-io/conan-center-index#3283 again

COMMAND bash ${configured_to_string_script} ${toStringInputHeader} ${to_string_src})
add_custom_target(elf_to_string_target DEPENDS ${to_string_src})
add_library(elf elf.cc mmap_loader.cc ${to_string_src})
add_dependencies(elf elf_to_string_target)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency (or add_custom_target) should not be necessary.
As the generated source is added to the sources of the add_library, cmake knows already that the generated source is a dependency of the library and that its source should be generated first.

@madebr
Copy link

madebr commented Oct 23, 2020

In addition to my remarks, cmake should also be tested on .travis.yml.

@banshee
Do you intend to update your pr?

@banshee
Copy link
Contributor Author

banshee commented Oct 24, 2020

No, it's been two years since I touched this and I haven't written anything in CMake for, hmm, can't actually remember. I'm totally happy to do anything to help (that doesn't involve relearning CMake...), but my suggestion would be to take the file you ended up with and make it a new PR. Abandoning this PR would be totally fine with me.

@banshee
Copy link
Contributor Author

banshee commented Oct 24, 2020

My next suggestion - if you want to put together a better PR that other people could also pull in, I'll happily close this one in favor of yours. Things like "err, bash isn't exactly portable" are 100% true, and I think my original CMake files were pretty much the fastest thing I could get working. Given that it's been here for two years, I suspect it's never going to make it into the main line, but it'd probably be good to only have one outstanding PR that people can grab.

@madebr
Copy link

madebr commented Oct 27, 2020

@banshee
Thanks for the reply!
I would love to propose a cmake pr myself,
but I will not invest any time in this until @aclements (or someone who has commit access) comments on this.

@banshee
Copy link
Contributor Author

banshee commented Jun 21, 2021

Closing this so it won't show up in my PR list any more.

@banshee banshee closed this Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants