Skip to content

CMake: Make BUILD_MODULE and BUILD_SHARED_LIBS non inclusive#459

Merged
squeek502 merged 3 commits intoluvit:masterfrom
doronbehar:cmake-fix
Feb 27, 2020
Merged

CMake: Make BUILD_MODULE and BUILD_SHARED_LIBS non inclusive#459
squeek502 merged 3 commits intoluvit:masterfrom
doronbehar:cmake-fix

Conversation

@doronbehar
Copy link
Copy Markdown
Contributor

@doronbehar doronbehar commented Feb 26, 2020

Running out of patience and in order to get my point better, here's a change I'm satisfied with it's results, here is the resulting tree for all 3 configurations of ON and OFF:

prefix-build-module-off-shared-on
└── var
    └── empty
        └── local
            ├── include
            │   └── luv
            │       ├── lhandle.h
            │       ├── lreq.h
            │       ├── luv.h
            │       └── util.h
            └── lib
                ├── libluv.so
                ├── libluv.so.1 -> libluv.so.1.34.1
                ├── libluv.so.1.34.1
                └── pkgconfig
                    └── libluv.pc
prefix-build-module-on-shared-off
└── var
    └── empty
        └── local
            └── lib
                └── lua
                    └── 5.1
                        └── libluv.so
prefix-build-module-on-shared-on
└── var
    └── empty
        └── local
            ├── include
            │   └── luv
            │       ├── lhandle.h
            │       ├── lreq.h
            │       ├── luv.h
            │       └── util.h
            └── lib
                ├── libluv.so
                ├── libluv.so.1 -> libluv.so.1.34.1
                ├── libluv.so.1.34.1
                ├── lua
                │   └── 5.1
                │       └── libluv.so
                └── pkgconfig
                    └── libluv.pc

22 directories, 18 files

Fixes #457 and fixes NixOS/nixpkgs#80528 .

NOTE: I've had to create an additional target - libluv which is distinguished from the luv target.

@doronbehar

This comment has been minimized.

@doronbehar

This comment has been minimized.

@doronbehar
Copy link
Copy Markdown
Contributor Author

cc @teto.

@squeek502
Copy link
Copy Markdown
Member

Looks good, this is the direction I was thinking of going in as well. Looks like it needs some fixes to get LuaRocks builds working again--I'll work on that.

@squeek502 squeek502 merged commit f3fe11f into luvit:master Feb 27, 2020
@zhaozg
Copy link
Copy Markdown
Member

zhaozg commented Feb 28, 2020

Not late, This will break luvi build, we need do more work. @squeek502

@squeek502
Copy link
Copy Markdown
Member

Not late, This will break luvi build, we need do more work. @squeek502

Sorry, you're right. I jumped the gun on this one. luvi expects to be able to build a static library by turning BUILD_MODULE off, but it's no longer possible to build a static library since BUILD_SHARED_LIBS affects the default library type of add_library. This definitely needs some more work.

squeek502 added a commit to squeek502/luv that referenced this pull request Feb 29, 2020
This adds on to the changes in luvit#459 to make it possible to build module, static, and shared libraries all at the same time if requested

- To build the module, `-DBUILD_MODULE=On`; the target name for the module is `luv`
- To build a static library, `-DBUILD_STATIC_LIBS=On`; the target name for the static lib is `libluv_a` (this matches how `libuv` names its targets; `uv` for shared and `uv_a` for static)
- To build a shared library, `-DBUILD_SHARED_LIBS=On`; the target name for the shared lib is `libluv`

These are able to be mixed/matched as needed.

This is a breaking change (as was luvit#459) for users of CMake (e.g. luvi) who will now need to specify linking against `libluv`/`libluv_a` and turn on `BUILD_STATIC_LIBS`/`BUILD_SHARED_LIBS` before calling `add_subdirectory`
squeek502 added a commit to squeek502/luvi that referenced this pull request Feb 29, 2020
Updates CMake to be compatible with the changes in luvit/luv#459 and luvit/luv#461
squeek502 added a commit to squeek502/luvi that referenced this pull request Feb 29, 2020
Updates CMake to be compatible with the changes in luvit/luv#459 and luvit/luv#461
@teto
Copy link
Copy Markdown

teto commented Feb 29, 2020

another issue we see in NixOS/nixpkgs#80528 (comment)
(the install FILES given no DESTINATION! part) is that SHAREDLIBS_INSTALL_INC_DIR definition is kinda hard to follow and lacks a good default. Once CMAKE_INSTALL_PREFIX is set can't we set SHAREDLIBS_INSTALL_INC_DIR from that or remove it altogether ?

@squeek502
Copy link
Copy Markdown
Member

@teto totally open to suggestions here. I'm not sure I fully understand what the issue is/what the possible fixes are.

@doronbehar
Copy link
Copy Markdown
Contributor Author

@squeek502 Our build system calls luarocks make which in turn calls cmake with the following flags:

-G"Unix Makefiles"
-DCMAKE_MODULE_LINKER_FLAGS="-shared"
-DLIBDIR="/nix/store/5wf8zrgpp199pmbbgyvkp7hc484pzrbs-luajit-2.1.0-beta3-luv-1.34.2-0/luv-1.34.2-0-rocks/luv/1.34.2-0/lib"
-DLUA_INCDIR="/nix/store/1m8vh1byjnjmjkpdidcqc37cykgsqjap-luajit-2.1.0-beta3/include/luajit-2.1"
-DLUA_LIBDIR=""
-DLUA="/nix/store/1m8vh1byjnjmjkpdidcqc37cykgsqjap-luajit-2.1.0-beta3/bin/luajit"
-DCMAKE_LIBRARY_PATH="/nix/store/1m8vh1byjnjmjkpdidcqc37cykgsqjap-luajit-2.1.0-beta3/lib:/nix/store/w89ndqsb7ig22mw5hk7k7zfvxmhx44xb-libuv-1.34.2/lib:/nix/store/1m8vh1byjnjmjkpdidcqc37cykgsqjap-luajit-2.1.0-beta3/lib:/nix/store/w89ndqsb7ig22mw5hk7k7zfvxmhx44xb-libuv-1.34.2/lib"
-DCMAKE_INCLUDE_PATH="/nix/store/1m8vh1byjnjmjkpdidcqc37cykgsqjap-luajit-2.1.0-beta3/include:/nix/store/w89ndqsb7ig22mw5hk7k7zfvxmhx44xb-libuv-1.34.2/include:/nix/store/1m8vh1byjnjmjkpdidcqc37cykgsqjap-luajit-2.1.0-beta3/include:/nix/store/w89ndqsb7ig22mw5hk7k7zfvxmhx44xb-libuv-1.34.2/include"
-DLUADIR="/nix/store/5wf8zrgpp199pmbbgyvkp7hc484pzrbs-luajit-2.1.0-beta3-luv-1.34.2-0/luv-1.34"

Where /nix/store/5wf8zrgpp199pmbbgyvkp7hc484pzrbs-luajit-2.1.0-beta3-luv-1.34.2-0/ is our $prefix.

There are a couple of issues here which can be detected and handled somehow in CMakeLists.txt by detecting that LUA is set.

  1. LIBDIR is set to $prefix/luv-1.34.2-0-rocks/luv/1.34.2-0/lib which is not where libluv.so should end up, this is where the file loaded by lua -e "require('lua')" should end up.
  2. The cmake configure phase fails with the following error:
CMake Error at CMakeLists.txt:229 (install):
  install FILES given no DESTINATION!

I'm not sure my self how to address it yet, but this is my best summarise so I think it's a good start.

@doronbehar
Copy link
Copy Markdown
Contributor Author

Oh actually, there's even 1 more thing I was thinking of, but consider this one as a nice-to-have:

Since luarocks/luarocks#1160, luarocks/luarocks#509 and luarocks/luarocks#339 are unresolved, perhaps would it be possible to set cmake options via environmental variables? This would help us make the build even cleaner.

@teto
Copy link
Copy Markdown

teto commented Mar 1, 2020

basically we should avoid the scenario

CMake Error at CMakeLists.txt:229 (install):
  install FILES given no DESTINATION!

if we follow the definitions, it goes up to SET(INSTALL_LIB_DIR ${LIBDIR}) but LIBDIR is never defined ?

@doronbehar
Copy link
Copy Markdown
Contributor Author

if we follow the definitions, it goes up to SET(INSTALL_LIB_DIR ${LIBDIR}) but LIBDIR is never defined ?

LIBDIR is defined, but not to the value we would want it to have.

@teto
Copy link
Copy Markdown

teto commented Mar 1, 2020

where is it defined ? is that some kind of default ? I only can find LUA_LIBDIR.

@doronbehar
Copy link
Copy Markdown
Contributor Author

Timothy- pushed a commit to luvitred/luv that referenced this pull request Apr 17, 2020
This adds on to the changes in luvit#459 to make it possible to build module, static, and shared libraries all at the same time if requested

- To build the module, `-DBUILD_MODULE=On`; the target name for the module is `luv`
- To build a static library, `-DBUILD_STATIC_LIBS=On`; the target name for the static lib is `libluv_a` (this matches how `libuv` names its targets; `uv` for shared and `uv_a` for static)
- To build a shared library, `-DBUILD_SHARED_LIBS=On`; the target name for the shared lib is `libluv`

These are able to be mixed/matched as needed.

This is a breaking change (as was luvit#459) for users of CMake (e.g. luvi) who will now need to specify linking against `libluv`/`libluv_a` and turn on `BUILD_STATIC_LIBS`/`BUILD_SHARED_LIBS` before calling `add_subdirectory`
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.

make it possible to install both headers and library

4 participants