Giter Club home page Giter Club logo

cmake-git-version-tracking's People

Contributors

andrew-hardin avatar brunexgeek avatar drouin-simon avatar egelja avatar ekilmer avatar phantom9999 avatar pwm1234-sri avatar sebastian-0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmake-git-version-tracking's Issues

sudo make install doesn't work with this script

We use your code in a downstream project at https://gitlab.com/YottaDB/DBMS/YDBOcto. It has served us well.

We had some problems, so I am looking at the upstream version in order to see if they are resolved there.

There is a problem with sudo make install.

I made a simple example for you: Add this line to the CMakeLists.txt in the better-example folder.

install(TARGETS demo DESTINATION /usr/local/bin)

Run cmake .. && make && sudo make install, and you will see this:

CMake Error at /home/sam/work/gitlab/cmake-git-version-tracking/git_watcher.cmake:139 (message):
  fatal: unsafe repository
  ('/home/sam/work/gitlab/cmake-git-version-tracking' is owned by someone
  else)

  To add an exception for this directory, call:

  

        git config --global --add safe.directory
  /home/sam/work/gitlab/cmake-git-version-tracking

   (/usr/bin/git status --porcelain -unormal)
Call Stack (most recent call first):
  /home/sam/work/gitlab/cmake-git-version-tracking/git_watcher.cmake:162 (RunGitCommand)
  /home/sam/work/gitlab/cmake-git-version-tracking/git_watcher.cmake:289 (GetGitState)
  /home/sam/work/gitlab/cmake-git-version-tracking/git_watcher.cmake:356 (CheckGit)
  /home/sam/work/gitlab/cmake-git-version-tracking/git_watcher.cmake:367 (Main)

This seems to be due to this change: https://github.blog/2022-04-12-git-security-vulnerability-announced/

I am trying to come up with a general purpose solution, but don't have any ideas right now.

Modified pre-configure file doesn't trigger a reconfigure

  • Expected behavior: after making a change to the pre-configure file, the post-configure file is regenerated.
  • Actual behavior: the post-configure file isn't regenerated because the git-hash hasn't changed.

The script name is also hard coded and can be replaced with ${CMAKE_CURRENT_LIST_FILE}.

Documentation improvement

Add

include(FetchContent)

to section Quickstart via FetchContent of README.md for completeness. Otherwise user gets error:

CMake Error at CMakeLists.txt:12 (FetchContent_Declare):
  Unknown CMake command "FetchContent_Declare".

Graceful failover for when directory is not a git repository?

When building using cmake, if the cmake script fails I've run into into a situation where the failure of the cmake build makes the build significantly longer because the compiler errors accumulating from the failed build takes longer to process.

My suggestion would be to have a variation where the script always succeeds, but writes into an additional auxiliary function whether the related git functionality is truly available?

IE:

inline static bool is_git_repository();

won't work with llvm-ar

-DCMAKE_AR=llvm-ar -DCMAKE_C_FLAGS="-flto=thin" -DCMAKE_...=... ...

[  2%] Linking C static library libcmake_git_version_tracking.a                                                                         
/usr/bin/ar: invalid option -- 'e'                                                                                                      
Usage: /usr/bin/ar [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV] [--plugin <name>] [member-name] [count] archive-file file...   
       /usr/bin/ar -M [<mri-script]                                                                                                     
.
.

Need manually `GitStateChangedAction()` right after including git_watcher if your lib are compiled by globbing sources

I'm configuring my c++ project just like https://github.com/andrew-hardin/cmake-git-version-tracking/blob/master/better-example/CMakeLists.txt, but I need to run cmake .. && make twice to get the linking works.

I found that the first time I run cmake .. && make, my lib compiled without git.cc.

At the time I wrote this issue, I found my mistake:

file(GLOB_RECURSE SOURCES src/**/*.cpp "${PROJECT_BINARY_DIR}/git.cc")
# globbing in cmake will ignore non-existing source, so the first time of `cmake` (before `make` generating git.cc) will not include git.cc
set(PRE_CONFIGURE_FILE cmake/git.cc.in)
set(POST_CONFIGURE_FILE "${PROJECT_BINARY_DIR}/git.cc")
include(cmake/git_watcher.cmake)
GitStateChangedAction() # I need this extra line

It's not a mistake of your cmake script. Just firing an issue hopping it to be helpful for others.

Git info not properly set

Generated git.cc has something like:

bool GitMetadata::Populated() {
    return ;
}
bool GitMetadata::AnyUncommittedChanges() {
    return ;
}
std::string GitMetadata::CommitBody() {
    return ;
}

Seems env variables not properly set. (Not quite sure how did I get there. I'll provide a mimimum process to reproduce it later.)

I would suggest

bool GitMetadata::Populated() {
    return "@GIT_RETRIEVED_STATE@" == std::string("false");
}
bool GitMetadata::AnyUncommittedChanges() {
    return "@GIT_IS_DIRTY@" == std::string("false");
}
std::string GitMetadata::CommitBody() {
    return "@GIT_COMMIT_BODY@";
}

and not surround these variables with " quotation mark in cmake. This would be more robust.

Header is not generated if it is missing but git-state-hash is present

If the generated header file goes missing but the git-state-hash is not also deleted (for example if make clean is run), the header file will not be generated again, causing compilation to fail.

Example steps to reproduce using hello-world demo:

cd hello-world/
cmake .
make
# The project will build successfully
make clean
# git.h is deleted, but git-state-hash remains
make
# git-state-hash is present and up to date, but git.h does not regenerate
# Build fails with missing header

Can the build be configured such that if generated header is missing, it will be generated in all cases?
Less sure if this makes sense or not, but it might also be a good idea for make clean to remove git-state-hash.

hello-world: Expected a command name, got unquoted argument with text

I can't build the hello-world example:

cmake -G "MSYS Makefiles" ..
CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at git_watcher.cmake:1:
  Parse error.  Expected a command name, got unquoted argument with text
  "../git_watcher.cmake".
Call Stack (most recent call first):
  CMakeLists.txt:7 (include)


-- Configuring incomplete, errors occurred!
See also "cmake-git-version-tracking/hello-world/build/CMakeFiles/CMakeOutput.log".

The CMakeOutput.log does not contain anything useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.