Forceflow / libmorton

C++ header-only library with methods to efficiently encode/decode Morton codes in/from 2D/3D coordinates
MIT License
593 stars 71 forks source link

Rework CMake scripts for install rules #55

Closed mablanchard closed 3 years ago

mablanchard commented 3 years ago

Introduce CMake install rules, respecting GNUInstallDirs. Also prefer the standard BUILD_TESTING build option over LIBMORTON_BUILD_TESTS.

Testing on Fedora 33, with CMake + Ninja :

cmake -B build/ -S . -G Ninja -DCMAKE_INSTALL_PREFIX:PATH=$PWD/install && ninja -C build/ install
[...]
-- Installing: .../libmorton/install/include/libmorton/morton_common.h
-- Installing: .../libmorton/install/include/libmorton/morton_AVX512BITALG.h
-- Installing: .../libmorton/install/include/libmorton/morton_BMI.h
-- Installing: .../libmorton/install/include/libmorton/morton2D_LUTs.h
-- Installing: .../libmorton/install/include/libmorton/morton2D.h
-- Installing: .../libmorton/install/include/libmorton/morton3D_LUTs.h
-- Installing: .../libmorton/install/include/libmorton/morton3D.h
-- Installing: .../libmorton/install/include/libmorton/morton.h
-- Installing: .../libmorton/install/share/cmake/libmorton/libmortonTargets.cmake
-- Installing: .../libmorton/install/share/cmake/libmorton/libmortonConfigVersion.cmake
-- Installing: .../libmorton/install/share/cmake/libmorton/libmortonConfig.cmake
-- Installing: .../libmorton/install/share/pkgconfig/libmorton.pc

ninja -C build/ test
[...]
[0/1] Running tests...
Test project .../libmorton/build
    Start 1: libmorton-test
1/1 Test #1: libmorton-test ...................   Passed   66.82 sec

100% tests passed, 0 tests failed out of 1

Closes #53.

Forceflow commented 3 years ago

What's the status of this PR - still WiP?

Forceflow commented 3 years ago

Can you move the cmake files out of /include ? That's a folder that people who are not building the test suite should just be able to download and include. I'd like it to be header files only.

mablanchard commented 3 years ago

What's the status of this PR - still WiP?

Yep, I still need to test this on Windows.

mablanchard commented 3 years ago

Can you move the cmake files out of /include ? That's a folder that people who are not building the test suite should just be able to download and include. I'd like it to be header files only.

Sure! What about removing the the include sub-folder too (and simply have libmorton/morton.h, libmorton/morton2D.h...)? Doing so, the test suite could include headers with #include <libmorton/morton.h> (like downstream users do with installed libmorton headers).

Forceflow commented 3 years ago

Fine by me

mablanchard commented 3 years ago

Seems to be working on Windows (with MSVC 2019):

C:\Users\mblanchard\Work\src\libmorton>cmake -S . -B build/ -G "NMake Makefiles" -D CMAKE_BUILD_TYPE:STRING=Release -D CMAKE_INSTALL_PREFIX:PATH=C:\Users\mblanchard\Work\src\libmorton\install
-- The C compiler identification is MSVC 19.28.29333.0
-- The CXX compiler identification is MSVC 19.28.29333.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/mblanchard/Work/src/libmorton/build

C:\Users\mblanchard\Work\src\libmorton>cd build

C:\Users\mblanchard\Work\src\libmorton\build>nmake

Microsoft (R) Program Maintenance Utility Version 14.28.29333.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Scanning dependencies of target libmorton-test-avx512
[ 12%] Building CXX object test/CMakeFiles/libmorton-test-avx512.dir/libmorton_test.cpp.obj
libmorton_test.cpp
[ 25%] Linking CXX executable libmorton-test-avx512.exe
[ 25%] Built target libmorton-test-avx512
Scanning dependencies of target libmorton-test
[ 37%] Building CXX object test/CMakeFiles/libmorton-test.dir/libmorton_test.cpp.obj
libmorton_test.cpp
[ 50%] Linking CXX executable libmorton-test.exe
[ 50%] Built target libmorton-test
Scanning dependencies of target libmorton-test-bmi2
[ 62%] Building CXX object test/CMakeFiles/libmorton-test-bmi2.dir/libmorton_test.cpp.obj
libmorton_test.cpp
[ 75%] Linking CXX executable libmorton-test-bmi2.exe
[ 75%] Built target libmorton-test-bmi2
Scanning dependencies of target libmorton-test-zen2
[ 87%] Building CXX object test/CMakeFiles/libmorton-test-zen2.dir/libmorton_test.cpp.obj
libmorton_test.cpp
[100%] Linking CXX executable libmorton-test-zen2.exe
[100%] Built target libmorton-test-zen2

C:\Users\mblanchard\Work\src\libmorton\build>ctest
Test project C:/Users/mblanchard/Work/src/libmorton/build
    Start 1: libmorton-test
1/2 Test #1: libmorton-test ...................   Passed   28.20 sec
    Start 2: libmorton-test-bmi2
2/2 Test #2: libmorton-test-bmi2 ..............   Passed   27.98 sec

100% tests passed, 0 tests failed out of 2

Total Test time (real) =  56.20 sec

C:\Users\mblanchard\Work\src\libmorton\build>nmake install

Microsoft (R) Program Maintenance Utility Version 14.28.29333.0
Copyright (C) Microsoft Corporation.  All rights reserved.

[ 25%] Built target libmorton-test-avx512
[ 50%] Built target libmorton-test
[ 75%] Built target libmorton-test-bmi2
[100%] Built target libmorton-test-zen2
Install the project...
-- Install configuration: "Release"
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/include/libmorton/morton_common.h
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/include/libmorton/morton_AVX512BITALG.h
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/include/libmorton/morton_BMI.h
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/include/libmorton/morton2D_LUTs.h
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/include/libmorton/morton2D.h
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/include/libmorton/morton3D_LUTs.h
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/include/libmorton/morton3D.h
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/include/libmorton/morton.h
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/share/cmake/libmorton/libmortonTargets.cmake
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/share/cmake/libmorton/libmortonConfigVersion.cmake
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/share/cmake/libmorton/libmortonConfig.cmake
-- Installing: C:/Users/mblanchard/Work/src/libmorton/install/share/pkgconfig/libmorton.pc

C:\Users\mblanchard\Work\src\libmorton\build>
mablanchard commented 3 years ago

Same logic on Linux (with GCC 10):

[mblanchard:~/Work/src/libmorton] mblanchard/cmake* ± cmake -B build/ -S . -G Ninja -D CMAKE_BUILD_TYPE:STRING=Release -D CMAKE_INSTALL_PREFIX:PATH=$PWD/install
-- The C compiler identification is GNU 10.2.1
-- The CXX compiler identification is GNU 10.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/lib64/ccache/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib64/ccache/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mblanchard/Work/src/libmorton/build
[mblanchard:~/Work/src/libmorton] mblanchard/cmake* ± ninja -C build/
ninja: Entering directory `build/'
[8/8] Linking CXX executable test/libmorton-test-bmi2
[mblanchard:~/Work/src/libmorton] mblanchard/cmake* ± ninja -C build/ test
ninja: Entering directory `build/'
[0/1] Running tests...
Test project /home/mblanchard/Work/src/libmorton/build
    Start 1: libmorton-test
1/2 Test #1: libmorton-test ...................   Passed   36.53 sec
    Start 2: libmorton-test-bmi2
2/2 Test #2: libmorton-test-bmi2 ..............   Passed   30.24 sec

100% tests passed, 0 tests failed out of 2

Total Test time (real) =  66.78 sec
[mblanchard:~/Work/src/libmorton] mblanchard/cmake* 1m7s ± ninja -C build/ install
ninja: Entering directory `build/'
[0/1] Install the project...
-- Install configuration: "Release"
-- Installing: /home/mblanchard/Work/src/libmorton/install/include/libmorton/morton_common.h
-- Installing: /home/mblanchard/Work/src/libmorton/install/include/libmorton/morton_AVX512BITALG.h
-- Installing: /home/mblanchard/Work/src/libmorton/install/include/libmorton/morton_BMI.h
-- Installing: /home/mblanchard/Work/src/libmorton/install/include/libmorton/morton2D_LUTs.h
-- Installing: /home/mblanchard/Work/src/libmorton/install/include/libmorton/morton2D.h
-- Installing: /home/mblanchard/Work/src/libmorton/install/include/libmorton/morton3D_LUTs.h
-- Installing: /home/mblanchard/Work/src/libmorton/install/include/libmorton/morton3D.h
-- Installing: /home/mblanchard/Work/src/libmorton/install/include/libmorton/morton.h
-- Installing: /home/mblanchard/Work/src/libmorton/install/share/cmake/libmorton/libmortonTargets.cmake
-- Installing: /home/mblanchard/Work/src/libmorton/install/share/cmake/libmorton/libmortonConfigVersion.cmake
-- Installing: /home/mblanchard/Work/src/libmorton/install/share/cmake/libmorton/libmortonConfig.cmake
-- Installing: /home/mblanchard/Work/src/libmorton/install/share/pkgconfig/libmorton.pc
θ62° [mblanchard:~/Work/src/libmorton] mblanchard/cmake* ±
mablanchard commented 3 years ago

Shall we update Travis CI to use CMake rather than the makefile?

Forceflow commented 3 years ago

Probably a good idea! Thanks for all work you put in this!

Make sure it builds the test suite for all instruction sets (BMI2, AVX, ...). We can only test the basic version, but at least try building them all to see if nothing derps out ;)

mablanchard commented 3 years ago

Should be ok now, what do you think?

Forceflow commented 3 years ago

Looks great, sorry for delay :) Merging!

mablanchard commented 3 years ago

@Forceflow: Any idea when you'll cut a new libmorton version? I'd love to see that in a stable release :)

Forceflow commented 3 years ago

Doing it right now :)

mablanchard commented 3 years ago

Awesome, thanks!