I am new to Premake. I am using Premake 4.4 beta 5 because Premake 5 has a few issues where it does not generate proper VS2010 solutions (generates VS2012 solutions with 2010 compiler), and it setting libdirs and links for all projects when written under one project.
Anyways, the issue I am having is that I wrote a Premake script. It all works fine, but there is an annoyance where it includes multiple parent folders in common between all the files included in the project. So you have to open multiple folders containing nothing but a single folder, before you get to the meat. Here's is an image so that you understand: premake_common_parent_folders
My folder structure on disc looks something like this:
build
premake4.lua
premake4.4-beta5.exe
src
StaticLib
include
Example.h
Example.cpp
Test
Example.cpp
Here is my Premake:
_targetdir = '../bin/' .. _ACTION
local function ProjectCommon()
targetdir( _targetdir .. '/' .. project().name )
files {
'../src/' .. project().name .. '/**.*',
}
includedirs {
'../src/' .. project().name .. '/include',
}
end
solution( 'Example' )
location( _ACTION )
configurations { "Release", "Debug" }
project( 'Test' )
ProjectCommon()
language( 'C++' )
kind( 'ConsoleApp' )
includedirs {
'../src/StaticLib/include',
}
libdirs {
_targetdir .. '/StaticLib',
}
links {
solution().name,
}
project( 'StaticLib' )
ProjectCommon()
targetname( solution().name )
language( 'C++' )
kind( 'StaticLib' )
I want to know if there is a way to have the implementation files directly under the project with the single include folder. Hiding the parent folders common between all project files (src and [Project Name]).
The hope is to have it look something like this: premake_no_common_parent_folders
In theory (untested, I haven't used Premake 4 in a long time) you can use virtual paths to rewrite the structure.
vpaths {
["*"] = "../src/"
}
Premake 5, on the other hand, automatically trims otherwise empty groups from the top of the path, so this isn't necessary if you upgrade.
Speaking of Premake 5, I'm not familiar with either of the bugs you mention; you should open an issue if you haven't already. I'd be willing to bet "setting libdirs and links for all projects when written under one project" is an issue with your project script rather than Premake itself, as that would be a pretty fundamental flaw.
Related
How would I add a single source set to multiple subprojects?
First of all ... yes I know how ridiculous this is. This is just something I have to do.
The setup
The project uses the Groovy DSL.
There are 3 subprojects (A,B,C), each with there own unique main source set.
There are 5 additional sourcesets (1, 2, 3, 4, 5) external to these projects.
Nonce of the external sourcesets can be compiled alone.
All of the source sets depend on an interface that is defined 3 different times in each subproject.
The subproject main source cannot depend on any of the external sources
1 and 2 need to be compiled with A, B, and C.
3 needs to be compiled with A and also B.
4 needs to be compiled with B and also C
5 needs to be compiled with C only.
4 and 5 need depend on a class defined in 2.
5 must be a standalone sourceset so that it can be included as a sourceset inside of any future subprojects that might be added.
None of the external sources are allowed to include sources from any other sourceset
None of the external sources are allowed to be compiled alone.
None of the external sources are allowed to be included as a jar or project dependency; they MUST be included as a source set and they MUST be compiled seperately for each subproject that includes them.
A
sourceSets {
main {
java {
srcDirs = ["src",
"$rootDir/source_sets/1/src",
"$rootDir/source_sets/2/src",
"$rootDir/source_sets/3/src"
]
}
}
}
B
sourceSets {
main {
java {
srcDirs = ["src",
"$rootDir/source_sets/1/src",
"$rootDir/source_sets/2/src",
"$rootDir/source_sets/3/src",
"$rootDir/source_sets/4/src"
]
}
}
}
C
sourceSets {
main {
java {
srcDirs = ["src",
"$rootDir/interfaces/source_sets/1/src",
"$rootDir/interfaces/source_sets/2/src",
"$rootDir/interfaces/source_sets/4/src",
"$rootDir/interfaces/source_sets/5/src"
]
}
}
}
settings.gradle
include(":interfaces/A")
project(":interfaces/A").name = "A"
include(":interfaces/A")
project(":interfaces/A").name = "A"
include(":interfaces/A")
project(":interfaces/A").name = "A"
The problem is that 4 and 5 are not able to find the class in 2, and my IDE (IntelliJ) cannot resolve the correct classpath.
Really what I need is for the external sourcesets to act as if there were 3 separate copies of them without there actually being 3 separate copies, and I need to do it without the use of symbolic/soft links.
The solution needs to only use gradle, but it can use JetBrains "idea" plugin for gradle so long as it doesn't involve committing any files under the ".idea" folder, but it can include inline xml or files in a resource folder outside of the .idea folder.
So yeah ... this is overly complicated and just .. ugh! But that's just how it is.
Ugh indeed.
I don't have an answer, but this is too long to put into a comment. So here goes.
I assume this is a problem with IntelliJ only, and not when compiling with Gradle, right? If that is the case, you should try and model your project in IntelliJ as you want it, and once you have found a way to do it, then figure out how to use customize the Idea plugin to do it for you.
However, I am pretty sure you can't have multiple modules in IntelliJ share the same "content root". So I only see the options left that you don't want - which is either to copy (synchronize) the sources with a new folder only used for IntelliJ (which won't allow for modifications), create symlinks (which aren't always portable) or to restructure your external sources so they can be compiled independently (which may not be easily possible)
:-(
I have a large-ish Qt project that has multiple subprojects.
One of the sub-projects is intentionally unbuildable, and I don't want QtCreator to try to build it. I still want all its source files visible in the project tree, however.
How can I prevent a project from getting built?
Is there a TEMPLATE = NONE or TARGET = PLZ_DONT_BUILD?
The hacky solution I've come up with is wrapping all my source files with:
DisableBuild {
SOURCES = DummyMain.cpp
} else {
SOURCES = main.cpp \
...many other files...
} #...at the bottom of the .pro file.
DummyMain.cpp just contains an empty int main() function, so the compiler doesn't complain about empty entry points.
If there is a better solution, I'd like to hear it!
I have a library project whose hierarchy looks something like this:
Root:
+ src/
+ apple.cpp
+ bananas/
+ bananas.cpp
...
+ include/
+ apple.h
+ bananas/
+ bananas.h
...
I've been using Visual Studio to compile it and it works fine but now I want to diversify it by allowing the library to be compiled using CMake. I've created the following CMakeLists.txt file (located in Root):
cmake_minimum_required(VERSION 2.8) # Version 2.8 required
file(GLOB_RECURSE HEADERS # Fetch all of the Lib's Headers
${CMAKE_CURRENT_SOURCE_DIR}/include/*.h
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp
)
file(GLOB_RECURSE SOURCES # Fetch all of the Lib's Srcs
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
)
add_library( # Create the Library from Srcs
HoneycombGameEngine ${SOURCES}
)
target_include_directories( # Add the Headers to the Lib
HoneycombGameEngine
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
It compiles with CMake and generates its files, however when I run make to actually compile the library, I get an error in the bananas.cpp file (first file it chooses to compile) that it cannot find the bananas.h header file. If it is relevant, the bananas.cpp include header statement looks like this:
#include "..\..\include\bananas\bananas.h"
I'm not exactly sure what I'm doing wrong, this my first time using CMake so I mostly wrote my CMakeLists file using bits and examples from the internet. Anything that could point me in the right direction and help me solve this issue is much appreciated.
You are only get all .h inside include directory.
Bananas.h is inside bananas directory. Then you have to use something like it:
file(GLOB_RECURSE HEADERS # Fetch all of the Lib's Headers
${CMAKE_CURRENT_SOURCE_DIR}/include/*.h
${CMAKE_CURRENT_SOURCE_DIR}/include/bananas/*.h
)
I'm working on a gradle multi project (java), where some of the sub-projects are applications (have a main class, and are executable) and some others are libraries (e.g, ends up being packaged as a jar, which some other sub-projects define a dependency on). It's working fine.
I'd like to be able to package (tar) the entire project for production, according to some structure that will make it easy for my users to deploy and use later on.
Currently, the distTar task creates a build/distribution/project-name.tar for each application project, and a build/libs/project-name.jar for each non application project, under each project build directory. That's a step in the right direction, but I'd like to consolidate the contents into one thing I can distribute.
As an example, right now after running distTar:
myapp/
README
docs/
services/
service1/
build/
libs/service1.jar
<other build dirs I don't want to distribute>
service2/
build/
distributions/service2.tar
<other build dirs I don't want to distribute>
service3/
build/
distributions/service3.tar
<other build dirs I don't want to distribute>
and the contents of service2.tar are:
service2/lib/service2.jar
service2/lib/some-service2-dependency.jar
service2/bin/service2 (start script)
service2/config.yml
(and similarly for service3.tar).
I'd like my final result to be a single myapp.tar(.gz) that includes a similar directory structure, but only with the production files:
README
docs/
services/
service1/
lib/service1.jar
service2/
lib/service2.jar
lib/some-service-dependency.jar
bin/service2 (start script)
config.yml
service3/
lib/service3.jar
lib/some-service-dependency.jar
bin/service3 (start script)
config.yml
Not sure what is the best way to achieve such a task. Do I create a parent level task that depends on distTar and copies files around, untar'ing stuff, etc? (tried that unsuccessfully).
Many thanks!
UPDATE:
I started doing something along these lines:
distributions {
main {
contents {
into('scripts') {
from {'scripts/sbin'}
}
into('service1') {
from {tarTree(tarFileForProject("service1"))}
}
into('service2') {
from {tarTree(tarFileForProject("service2"))}
}
into ...
}
}
}
distTar.dependsOn([subprojects.clean, subprojects.distTar])
(where tarFileForProject is a simple function that returns the path to the build/distributions/*.tar file of the given subproject name).
It seems to work, but also seems ugly. I wonder if there's a cleaner way to do this.
I have created a Sub project which just prints "Hello World". My goal is to create a C file inside the same subproject but within a folder named "src", also I want to create a H file within a folder named "include".
The H file contains only one function declaration "void printContent();" and the C file contains its definition which prints "Hello Buddy".
I added the C file inside the Source Files section of Sub project and added the H file inside the Header File Section, but when I compile the subproject and try to deploy it on to an emulator, I got an error.
BUILD: [01:0000000047:ERRORE] NMAKE : U1073: don't know how to make 'obj\ARMV4I\debug\content.obj'
I tried to configure the subproject by providing the below lines in the sources file of every Sub project.
INCLUDES= include/
But nothing changed and the problem still persists.
In wince subproject, sub folders are treated differently in the source file layout.
Rule No.1 You can't have both source and dirs files in the same folder.
So you either use one folder, or use several sub folders, then the root folder is clean and have one dirs file and several folders, no source file.
Rule No. 2 Each sub folder should have both source and makefile
You can copy and then edit the source file, the makefile will always be the same.
Ok, if you are going to use subfolder just to make the folder structure cleaner, my suggestion is that you create 2 subprojects, one is the main subproject; the other includes all your src files and its type is set to be static library. Then you can link to the static .lib file just as you are including them as in a subfolder. Of cource you need to set the additional include folder and input library.