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

Windows cmake build fails #311

Closed
Katharsas opened this issue Apr 1, 2019 · 10 comments
Closed

Windows cmake build fails #311

Katharsas opened this issue Apr 1, 2019 · 10 comments

Comments

@Katharsas
Copy link

Katharsas commented Apr 1, 2019

When i go into g3log dir and try:

mkdir build
cd build
cmake ../ -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 15"

cmake (latest version 3.14.1 win64) fails with

CMake Error at CMakeLists.txt:95 (math):
  math cannot parse the expression: "/255": syntax error, unexpected
  exp_DIVIDE, expecting exp_PLUS or exp_MINUS or exp_OPENPARENT or exp_NUMBER
  (1).

CMake Error at CMakeLists.txt:96 (math):
  math cannot parse the expression: "%255": syntax error, unexpected exp_MOD,
  expecting exp_PLUS or exp_MINUS or exp_OPENPARENT or exp_NUMBER (1).

for g3log commits at tag 1.3.1, 1.3.2 and current master (9c5e7f3). When i go back to 1.3, it seems to work. This seems to be the case for both cmd and powershell.

@KjellKod KjellKod added question build build issue labels Apr 1, 2019
@KjellKod
Copy link
Owner

KjellKod commented Apr 1, 2019

Hi,

Your environment does not seem to find git. It's the only way I've found to easily extract the software version without hardcoding into a file a version. (Ugh!)

SET(MAJOR_VERSION 1)
IF ( NOT VERSION )
   IF ( "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows" )
      message("windows: Extracting git software version")
      execute_process(COMMAND cmd /c "git rev-list --branches HEAD | find /v " " /c" OUTPUT_VARIABLE GIT_VERSION WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
   ELSE()
      IF(UNIX OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
         message( STATUS "nix: Extracting git software version" )
      ELSE()
         message( STATUS "unknown platform: extracting git software version" )
      ENDIF()
      execute_process(COMMAND bash "-c" "git rev-list --branches HEAD | wc -l | tr -d ' ' | tr -d '\n'" OUTPUT_VARIABLE GIT_VERSION WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
   ENDIF()

   SET(MINOR_VERSION 3)
   math(EXPR VERSION-BASE ${GIT_VERSION}/255)
   math(EXPR VERSION-REMAINDER ${GIT_VERSION}%255)

Suggestions:

  1. Make sure your environment is setup so the path works for accessing git.
  2. You can also, I believe, pass in, GIT_VERSION with the GIT_VERSION configuration. You can either set the GIT_VERSION to whatever.

@KjellKod
Copy link
Owner

KjellKod commented Apr 1, 2019

A third option could be to change the CMakeLists.txt to check if the value GIT_VERSION isn't set and then just set it to a default value 1 or similar. If you take this route then I think that could be a nice adjustment to the CMakeLists.txt file -- if so, please do a pull request

@Katharsas
Copy link
Author

Katharsas commented Apr 1, 2019

I'm new to cpp and cmake so i kind of have a hard time understanding what is going on in these cmake statements. I assume GIT_VERSION is version of git that is called (but how is it used) ? I don't really understand options 2 & 3.

I don't have git on my path because it is not installed, so i should probably do that first. It is not installed because i am using SourceTree as my git client, which comes with its own bundled git binaries. I guess bundling Git is quite popular for windows git clients, so it would probably a good idea to
A) mention the need for Git on path somewhere in the readme (i could do that) and
B) checking during cmake on windows if Git is available on path and emitting a descriptive error if not (that would be very very hard for me, if this is even possible)

(Personally i just change hardcoded version on release with a separate commit in my projects, it helps documenting versions without being mutable like tags^^)

Edit:
Any way, installing Git to path fixed the problem, thanks. Tell me if you'd like to have pull request on documentation.

@KjellKod
Copy link
Owner

KjellKod commented Apr 1, 2019

GIT_VERSION is not the version of git is the version of the g3log software

@KjellKod
Copy link
Owner

KjellKod commented Apr 1, 2019

I.e. git retrieved version

@Katharsas
Copy link
Author

Oh ok, now option 2 and 3 make much more sense. I'll see what i can do.

@KjellKod
Copy link
Owner

KjellKod commented May 2, 2019

@Katharsas can this be closed?

@macdew
Copy link

macdew commented May 2, 2019

I faced a similar issue today whilst rebuilding the source from the github release tar.gz file. I solved it by just passing -DVERSION=1.3.2 to the CMake command. This bypasses the git version check and I did not see any negative outcomes.

@KjellKod
Copy link
Owner

KjellKod commented May 2, 2019

perfect. I just updated the doc and I consider this issue closed now: #316

@KjellKod KjellKod closed this as completed May 2, 2019
@KjellKod
Copy link
Owner

KjellKod commented May 2, 2019

@macdew thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants