tl; dr questions are below.
I am a developer trying something new - my last poison is C ++. Since I spend half my time on my Linux laptop and the other half on a Windows XP PC, I tried to find a way to create a basic, barebone project using good C ++ practices (well, I donβt know them from experience, I just read about them). Right now my project almost works when using cmake . && make cmake . && make on Linux (it works when the header and source files are in the same folder, it fails when I separate them to include / src folders). I use muw nuwen distribution on windows (and I know that the toolchain works, it compiles projects from Eclipse without any problems).
My project directory is as follows:
engine | |- main | |- include | |- App.h |- CMakeLists.txt (2) |- src | |- main.cc |- App.cc |- CMakeLists.txt (3) |- CMakLists.txt (1)
The contents of the files are very simple (I can remove include security elements, etc.).
App.h:
class App { public: App(); int onExecute(); };
App.cc:
#include <iostream> #include "App.h" App::App() { } int App::onExecute() { std::cout << "inside app.." << '\n'; return 0; }
main.cc:
#include <iostream>
CMakeLists.txt (1) - main:
cmake_minimum_required (VERSION 2.6) set (CMAKE_CXX_COMPILER "g++") project (gameengine) add_definitions ( "-Wall -ansi -pedantic") add_subdirectory (${CMAKE_SOURCE_DIR}/main/include) add_subdirectory (${CMAKE_SOURCE_DIR}/main/src) add_executable (engine ${CMAKE_SOURCE_DIR}/main/src/main.cc) target_link_libraries (engine Application)
CMakeLists.txt (2) - inside the include directory
add_library (Application App) set_target_properties (Application PROPERTIES LINKER_LANGUAGE CXX)
CMakeLists.txt (3) - inside the src directory
include_directories (../include)
And this is until I got it - with some changes (for example, moving App.cc to the include directory) the whole thing compiles and works fine on Linux, but I can not get the mingw generator to work in Win XP, I manually set CMAKE_MAKE_PROGRAM to CMakeCache.txt file to point to the correct make.exe (I know that this should be defined as a system variable, but since I work on many different computers, I do not want to leave garbage after me).
My questions:
1) what are the guidelines for writing a multi-platform CMakeLists.txt file (which will work regardless of os and the location of the project files), which will preferably allow me to easily reconfigure my project from one another
2) how can I fix the error without finding the header file (make gives: (...) \ engine \ main \ src \ main.cc: 2: 17: fatal error: App.h: there is no such file or directory)?
Thanks for your time and help.