Skip to content

Improve CMake module file#312

Merged
KjellKod merged 17 commits intoKjellKod:masterfrom
myd7349:win32-cmake-install
May 14, 2019
Merged

Improve CMake module file#312
KjellKod merged 17 commits intoKjellKod:masterfrom
myd7349:win32-cmake-install

Conversation

@myd7349
Copy link
Contributor

@myd7349 myd7349 commented Apr 6, 2019

I am trying to add g3log to vcpkg: microsoft/vcpkg#5961 these days, and encountered some issues:

  • Lack of install target on Win32
  • The g3loggerConfig.cmake doesn't work out on Win32
  • The g3loggerConfig.cmake only takes care of SHARED library

@myd7349 myd7349 marked this pull request as ready for review April 6, 2019 11:11
@myd7349
Copy link
Contributor Author

myd7349 commented Apr 8, 2019

Hi! @KjellKod Please don't merge yet. I just want to make sure that CPack works well after this PR.

@KjellKod
Copy link
Owner

KjellKod commented Apr 9, 2019

To further improve this change and to make it more robust please consider:

  1. Add a build section on the readme for this change
  2. Please consider extending the content of the AppVeyor script so the installation is tested also in the Cloud CI - ref: https://github.com/KjellKod/g3log/blob/master/appveyor.yml

@KjellKod
Copy link
Owner

@myd7349 : any progress on this one?

@myd7349
Copy link
Contributor Author

myd7349 commented Apr 18, 2019

Hi! @KjellKod Sorry for the delay! I will finish it as soon as possible.

@myd7349
Copy link
Contributor Author

myd7349 commented Apr 18, 2019

I have done some tests about CMAKE_INSTALL_PREFIX and CPACK_PACKAGING_INSTALL_PREFIX. And the result is here: https://github.com/myd7349/Ongoing-Study/blob/master/cpp/CMake/libfoo_v2/README.md

According to the tests:

   IF(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
      SET(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
   ELSEIF(NOT CPACK_PACKAGING_INSTALL_PREFIX)
      SET(CPACK_PACKAGING_INSTALL_PREFIX /usr/local)
   ENDIF()

will cause CPACK_PACKAGING_INSTALL_PREFIX always having the same value as CMAKE_INSTALL_PREFIX on Linux.
(If we don't specify CMAKE_INSTALL_PREFIX, it will has a default value /usr/local according to https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html.)
So, I think:

IF(NOT MINGW)
   INSTALL( TARGETS g3logger
               ARCHIVE DESTINATION ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
               LIBRARY DESTINATION ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
               COMPONENT libraries)

   INSTALL( FILES ${HEADER_FILES}
               DESTINATION ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_HEADERDIR}
               COMPONENT headers)

   INSTALL( FILES ${PROJECT_SOURCE_DIR}/cmake/g3loggerConfig.cmake
               DESTINATION ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/g3logger)
ELSE()
   INSTALL( TARGETS g3logger
               ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
               LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
               COMPONENT libraries)

   INSTALL( FILES ${HEADER_FILES}
               DESTINATION ${CMAKE_INSTALL_HEADERDIR}
               COMPONENT headers)

   INSTALL( FILES ${PROJECT_SOURCE_DIR}/cmake/g3loggerConfig.cmake
               DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/g3logger)
ENDIF()

can be simplified as:

   INSTALL( TARGETS g3logger
               ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
               LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
               COMPONENT libraries)

   INSTALL( FILES ${HEADER_FILES}
               DESTINATION ${CMAKE_INSTALL_HEADERDIR}
               COMPONENT headers)

   INSTALL( FILES ${PROJECT_SOURCE_DIR}/cmake/g3loggerConfig.cmake
               DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/g3logger)

The test result also shows that:

cmake .. -DCMAKE_INSTALL_PREFIX=<one value> -DCPACK_PACKAGING_INSTALL_PREFIX=<another value>

will not properly.

To fix this problem, we may change these lines to:

IF(NOT CPACK_PACKAGING_INSTALL_PREFIX)
   IF(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
      SET(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
   ELSE()
      SET(CPACK_PACKAGING_INSTALL_PREFIX /usr/local)
   ENDIF()
ENDIF()

@KjellKod
Copy link
Owner

Cool. That sounds like an amazing improvement. Please comment when you are ready for a re-review

@KjellKod
Copy link
Owner

@myd7349 : Please consider adding a section to the readme for the build/install options

@KjellKod
Copy link
Owner

@myd7349 your example [link] seem to be using CPACK_PACKAGING_PREFIX not CPACK_PACKAGING_INSTALL_PREFIX like your comment above suggests.

CPACK_PACKAGING_PREFIX seems to be lacking useable documentation AFAIK. It also doesn't seem to have an effect if it was supposed to work like: CPACK_PACKAGING_INSTALL_PREFIX

@myd7349
Copy link
Contributor Author

myd7349 commented Apr 19, 2019

Oh! Sorry. That's a shame. I have tested it again: https://github.com/myd7349/Ongoing-Study/blob/master/cpp/CMake/libfoo_v2/README.md
I also gave the lastest commit a test: https://github.com/myd7349/Ongoing-Study/blob/master/cpp/CMake/libfoo_v2/README.md#test-b30cd9360990fd439682e3543705aab7ea2d49fc

@myd7349 : Please consider adding a section to the readme for the build/install options

Sure.

@myd7349
Copy link
Contributor Author

myd7349 commented Apr 20, 2019

Hi! @KjellKod As of the last commit, I think I have finished this PR. Could you give it a review again?

Copy link
Owner

@KjellKod KjellKod left a comment

Choose a reason for hiding this comment

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

Amazing work @myd7349
Great attention to details and a huge community boon with the improved build system!
I haven’t redone the testing yet but overall it looks great.

I left some minor comments to address

README.markdown Outdated
You may also specify one or more of those options listed above from the command line.
For example, on Windows:
```
cmake .. -G "Visual Studio 15 2017" -DG3_SHARED_LIB=OFF -DCMAKE_INSTALL_PREFIX=C:/g3log -DADD_G3LOG_UNIT_TEST=ON -DADD_FATAL_EXAMPLE=OFF
Copy link
Owner

Choose a reason for hiding this comment

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

nit: please line break

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

README.markdown Outdated
```
This will install g3log to `/usr` instead of `/usr/local`.

Package maintainers may be interested in the `CPACK_PACKAGING_INSTALL_PREFIX`. For example:
Copy link
Owner

Choose a reason for hiding this comment

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

nit: Make it clear that this does not work on Windows.
Ref: your testing that shows that specifying CPACK_PACKAGING_INSTALL_PREFIX fails with cpack.

Suggestion:
Package maintainers
-> *nix* package maintainers or
-> Linux/OSX package maintainers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

README.markdown Outdated
## Configuring
g3log provides following CMake options (and default values):
```
$ cmake -LAH
Copy link
Owner

Choose a reason for hiding this comment

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

Super! Didn’t know you could trigger a listing of all the variables.

nit: explain above the command in a one liner what cmake -LAH is

Copy link
Owner

Choose a reason for hiding this comment

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

It doesn’t hurt to mention Options.cmake

Suggestion: something like


List all of g3log’s cmake options to see configuration choices. 

For additional option context and comments  please also see  [Options.cmake](https://github.com/KjellKod/g3log/blob/master/Options.cmake)

*Generate listing of all of g3log’s CMake variables:*
`cmake-LAH`

Copy link
Contributor Author

@myd7349 myd7349 Apr 21, 2019

Choose a reason for hiding this comment

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

One more commit is added. And the second sentence is added after those options.

@myd7349 myd7349 force-pushed the win32-cmake-install branch from 1f96aac to 89ae2f8 Compare April 21, 2019 06:41
KjellKod
KjellKod previously approved these changes Apr 21, 2019
Copy link
Owner

@KjellKod KjellKod left a comment

Choose a reason for hiding this comment

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

Detailed. To the point and overall a Great improvement.
Approved, pending testing before merging

@KjellKod
Copy link
Owner

KjellKod commented May 2, 2019

@myd7349
Can I re-review, test and hopefully merge this one or do you still have work in progress that I should wait on?

Thanks
Kjell

@myd7349
Copy link
Contributor Author

myd7349 commented May 2, 2019

Yes. I think this PR is more better after the last two commits. Please review it again. :)

@KjellKod
Copy link
Owner

Thanks. I have not forgotten about this but work-life balance has been off lately.
I will attend to this tonight!

Copy link
Owner

@KjellKod KjellKod left a comment

Choose a reason for hiding this comment

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

Can you verify if there is an : OSX issue on the generated target file.

@KjellKod KjellKod merged commit 376c417 into KjellKod:master May 14, 2019
@KjellKod
Copy link
Owner

Nice work @myd7349! thanks

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.

2 participants