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 build code #60

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft

Conversation

SchaichAlonso
Copy link
Contributor

@SchaichAlonso SchaichAlonso commented Oct 28, 2024

Preliminary PR to add a cmake project file.

Fixes: #59

Force serial execution of everything within check-hashdbm-util,
and rename `casket*` to `check-hashdbm-util*` in order to preempt
the delete statement from racing with the other tests.
tkrzw doesn't explicitly set any symbol exports, therefore
relying on gcc's default policy to export everything.

On msvc, the default behaviour is to not export unless
explicitly asked for.

Have cmake instruct msvc to export everything, to match
the gcc behaviour
Comment on lines +1 to +4
cmake_minimum_required(VERSION 3.28)

cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0091 NEW)

Choose a reason for hiding this comment

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

These two lines doesn't appear to be needed if cmake_minimum_required is 3.28?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi.

In cmake, most policies default to the OLD behaviour, in order to remain compatible to previous behaviour when people bump up cmake_mininum_required_version.

CMP0048's last paragraph states that unless explicitly set, the old behaviour will be used.
The same goes for CMP0091.

Choose a reason for hiding this comment

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

No?

CMP0091 page

Use the cmake_policy() command to set it to OLD or NEW explicitly.

The cmake_minimum_required page from v3.28 says

All policies known to the running version of CMake and introduced in the (or , if specified) version or earlier will be set to use NEW behavior.

I think this means cmake_minimum_required(VERSION 3.28) will set NEW for all the policies introduced in VERSION <= 3.28.

)
set_target_properties(tkrzw
PROPERTIES
MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>$<IF:$<STREQUAL:$<TARGET_PROPERTY:tkrzw,TYPE>,SHARED_LIBRARY>,DLL,>
Copy link

@shenlebantongying shenlebantongying Nov 6, 2024

Choose a reason for hiding this comment

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

I don't have access to Windows machine now, but last time I checked, for relative newer CMake, this is useless. However, I am not sure at all.

Copy link
Contributor Author

@SchaichAlonso SchaichAlonso Nov 6, 2024

Choose a reason for hiding this comment

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

It was not required for older versions of cmake, i.e. before 3.15.
Starting with 3.15, CMP0091 deprecated the automatic setup of the correct runtime library.

If CMP0091 isn't set at the prelude section, the explicit setting of MSVC_RUNTIME_LIBRARY is not required. In my opinion, the old behaviour was "friendlier", as this line is more or less a triviality, but now needs to be written all over the place. The OLD behaviour, however, is deprecated.

_TKRZW_LIB_VERSION="${LIB_VERSION}"
)

target_compile_features(tkrzw PUBLIC cxx_std_17)

Choose a reason for hiding this comment

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

No opinion about this line, this means if the compiler by default uses 20 or 23 then the code will be compiled in 20 or 23 mode.

Alternatively, set the version to fixed 17

set_property(TARGET tkrzw PROPERTY CXX_STANDARD 17)

Copy link
Contributor Author

@SchaichAlonso SchaichAlonso Nov 6, 2024

Choose a reason for hiding this comment

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

I agree with CXX_STANDARD being more readable.

However, it is ancient. and was/is meant as a relieve from the days people were writing hundreds of lines of cmake code to add the compiler specific option for -std=c++11 (which might require to be denoted as -std=c++0x). Because all those self-written cxx_standard code had tweaks and fallbacks and odd hacks, CXX_STANDARD doesn't actually enforce anything unless CXX_STANDARD_REQUIRED is also set. And then, CXX_EXTENSIONS has to be disabled, as the default to CXX_STANDARD would enable vendor specific extentions, which isn't what the autoconf code was doing.

All three options, unlike cxx_std_XX, can be set globaly, with something like

set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_EXTENSIONS OFF)
set (CXX_STANDARD_REQUIRED ON)

so the fact it's 3 options to set would be a minor issue for large projects with many targets.

However, CXX_STANDARD does not trancend, which is a showstopper: Inside of the tkrzw build, setting up c++17 mode, either globaly or by a lot of set_property calls, might be good enough to build tkrzw.

When the built targets gets installed, however, this configure_package_config_file call generates a file that is then installed, containing everything other projects require in order to use the tkrzw targets, similar to the pkg-config file that is generated by autotools.
The other project doesn't know anything about global variable setups in tkrzw, and as CXX_STANDARD doesn't transcend, "using" tkrzw will not imply the requirement for a c++17 mode to the consuming project. cxx_std_XX does transcends to all consumers, up- but not down-grading the c++ standard in use, i.e. if a consumer uses c++11 itself but links against tkrzw, it will be upgraded to use c++17, while a project using c++23 will keep using 23 despite linking against tkrzw.

I'm currently working on this integration.

CMakeLists.txt Outdated Show resolved Hide resolved
@shenlebantongying
Copy link

shenlebantongying commented Nov 6, 2024

Overall, looks good and I tested briefly locally. Just a few nitpicking. I am not associated with this project in any way as of now.

@SchaichAlonso
Copy link
Contributor Author

VCPKG overlay repository: https://github.com/SchaichAlonso/tkrzw-vcpkg-overlay

@SchaichAlonso
Copy link
Contributor Author

SchaichAlonso commented Nov 6, 2024

VCPKG consumer example repository that builds the demos in example of the main repository against a vcpkg provisioned tkrzw package: https://github.com/SchaichAlonso/tkrzw-vcpkg-consumer-example

Seems there's some assertion blowing up in treedbm_ex1

tkrzw has quite a bit of code that is implemented in header files
that are supposed to be included by consuming projects.

This causes some technical issues with [weak symbols](https://en.wikipedia.org/wiki/Weak_symbol) inside
the consumer's translation units (or `.obj` files), that might fail
to be deduplicated if the consuming project uses compiler settings
different from those used by the tkrzw build system.

More importantly, however, parts of the code, especially imlementations
of non-virtual functions, might end up being embedded into consumer
applications when an optimization phase eliminates the procedure
calls, raising many concerns considering licensing.

This commit moves all implementations from header files documented
for inclusion into third-party projects on https://dbmx.net/tkrzw/,
as well as any header that implicitly gets included by including a
tkrzw interface header into source files.
Further, `inline` declarations are removed as within tkrzw, the
inlining happens on the discredition of the linker independed of
the `inline` keyword, while cross-module inlining is what this
commit is supposed to interdict.

Nothing can be done about template code in tkrzw_lib_common.h ,
however, template code is whitelisted on GPLv3.
While ia32 and amd64 use 4096 byte pages in popular setups,
however all i686 processors have the ability to use 8k pages,
while Xeon E5/E7/Scalable have up to 1GB "Huge Page" support.

ia64 systems never had 4k page support to begin with and use
64k pages instead.

Autodetect the page size on win32 systems.
It might be better to have a custom type with a real operator==
though
Build and execute unit tests, with the exception of tkrzw_langc_test which has just too many global variable accesses to get them all.
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.

Add cmake build code
2 participants