Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to set SRC dir S for eclass cmake with /src subdirectory
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
nagmat84
Guru
Guru


Joined: 27 Mar 2007
Posts: 308

PostPosted: Wed Apr 23, 2025 6:39 am    Post subject: How to set SRC dir S for eclass cmake with /src subdirectory Reply with quote

Assume you have a project whose main CMakeLists.txt does not reside in the project's main directory but in a subdirectory /src. I want to use the eclass cmake and I am wondering wether
  1. it is better to set the ebuild variable S to the sub-directory, or
  2. change the working dir to /src in src_compile?
Option 1 essentially looks like:
Code:
EAPI=8

inherit cmake

S="${WORKDIR}/release-${PV}-stable/src"
Option 2 looks like:
Code:
EAPI=8

inherit cmake

S="${WORKDIR}/release-${PV}-stable"

src_compile() {
   cd src || die
   cmake_src_compile
}

The basic structure of the project is:
Code:
release-x.y.z-stable
  |-- doc
  |-- lib
  |     `-- CMakeLists.txt
  |-- src
  |     `-- CMakeLists.txt
  |-- test
  |-- tools
  |-- BUILDING.md
  |-- CHANGELOG.md
  `-- README.md


Things worth noting:
  • Option 1 is more succint, less boiler plate code.
  • There are files above the /src subdirectory level inside /lib and /doc which needs to be installed, too. I don't know wether confining ${S} to /src might prevent this in a later emerge stage. I haven't come so far yet.
  • With option 1, emerge creates the build directory "${WORKDIR}/release-${PV}-stable/src_build", i.e. the build directory resides within the extracted project next to ./src. With option 2, emerge creates the build directory "${WORKDIR}/release-${PV}-stable_build" outside the extracted project. The latter option feels as if this would be the correct way.
  • With option 2, I change the working dir at the beginning of the compilation phase, before I call the default implementation of the eclass. I don't know where I also have to change the working dir in order to not accidentally break thing. Or stated differently: I don't know how many things inside the eclass rely on ${S} pointing to the directory with the main CMakeLists.txt.
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 2141

PostPosted: Wed Apr 23, 2025 12:27 pm    Post subject: Reply with quote

If you don't care about any other CMakeLists.txt except in src directory as the base, then use Option 3:
Code:
EAPI=8

CMAKE_USE_DIR="${S}/src"

inherit cmake
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum