Insight into something.
CMAKE_MINIMUM_REQUIRED(VERSION 2.4) PROJECT(Math_Library)ADD_DEFINITIONS(-g)#used to force inclusion of math.h if(UNIX) link_libraries(m) endif(UNIX)SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/../../bin/) SET(SRC_DIR ${CMAKE_SOURCE_DIR}/../../src/) SET(INC_DIR ${CMAKE_SOURCE_DIR}/../../include/)INCLUDE_DIRECTORIES( ${INC_DIR} )FILE(GLOB MAIN_FILES ${SRC_DIR}/*.c)FOREACH(APPNAME ${MAIN_FILES}) GET_FILENAME_COMPONENT(BASENAME ${APPNAME} NAME_WE) ADD_EXECUTABLE(${BASENAME} ${APPNAME}) ENDFOREACH(APPNAME ${MAIN_FILES})MAKE_DIRECTORY(${EXECUTABLE_OUTPUT_PATH})
I've been working to develop a cross platform way to build code and develop projects. Here is the CMake file I created to do that. CMAKE_MINIMUM_REQUIRED(VERSION 2.4) PROJECT(Math_Library) ADD_DEFINITIONS(-g) #used to force inclusion of math.h if(UNIX) link_libraries(m) endif(UNIX) SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/../../bin/) SET(SRC_DIR ${CMAKE_SOURCE_DIR}/../../src/) SET(INC_DIR ${CMAKE_SOURCE_DIR}/../../include/) INCLUDE_DIRECTORIES( ${INC_DIR} ) FILE(GLOB MAIN_FILESÂ ${SRC_DIR}/*.c) FOREACH(APPNAME ${MAIN_FILES}) GET_FILENAME_COMPONENT(BASENAME ${APPNAME} NAME_WE) ADD_EXECUTABLE(${BASENAME} ${APPNAME}) ENDFOREACH(APPNAME ${MAIN_FILES}) MAKE_DIRECTORY(${EXECUTABLE_OUTPUT_PATH})
//////////////////////////////////////////////////////////////////////////////// /** * @file FILENAME.EXTENSION * @brief * * DETAILED DESCRIPTION * * @title FILENAME * @author AUTHORE_NAME * @email EMAIL_ADDRESS * @web WEBSITE * @created DATE * * Compile with: g++ -g -o ../../bin/FILENAME FILENAME.EXTENSION */ //////////////////////////////////////////////////////////////////////////////// //------------------------------------------------------------------ :Libraries: // _ _ _ _ // | | (_) |__ _ _ __ _ _ _(_)___ ___ // | |__| | '_ \ '_/ _` | '_| / -_|_-< // |____|_|_.__/_| \__,_|_| |_\___/__/ // // ----------------------------------------------------------------------------- // Input-Output #include /* input-output stream - necessary for cout */ //#include /* to use file stream */ using namespace std; /* to not need std:: on all io */ //Strings //#include /* to use strings */ //#include /* use strings like cout */ //#include /* for atoi */ //#include /* for atoi */ //#include //#include <map> //Math //#include <math> /* pow, sqrt and use compile flag -lm */ //#include /* use sort and find */ //--------------------------------------------------------------------- :Global: // ___ _ _ _ // / __| |___| |__ __ _| | // | (_ | / _ \ '_ \/ _` | | // \___|_\___/_.__/\__,_|_| // // ----------------------------------------------------------------------------- //const int EMPTY = -1; //----------------------------------------------------------------- :Prototypes: // ___ _ _ // | _ \_ _ ___| |_ ___| |_ _ _ _ __ ___ ___ // | _/ '_/ _ \ _/ _ \ _| || | '_ \/ -_|_-< // |_| |_| \___/\__\___/\__|\_, | .__/\___/__/ // |__/|_| // //----------------------------------------------------------------------------- int Example_Function(); //----------------------------------------------------------------------- :Main: // __ __ _ // | \/ |__ _(_)_ _ // | |\/| / _` | | ' \ // |_| |_\__,_|_|_||_| // // ----------------------------------------------------------------------------- int main ( int argc, char* argv[] ) { ////////////////////////////// // Variables ////////////////////////////// ////////////////////////////// // Input ////////////////////////////// ////////////////////////////// // Output ////////////////////////////// ////////////////////////////// // Exititing ////////////////////////////// return 0; } //------------------------------------------------------------------ :Functions: // ___ _ _ // | __| _ _ _ __| |_(_)___ _ _ ___ // | _| || | ' \/ _| _| / _ \ ' \(_-< // |_| \_,_|_||_\__|\__|_\___/_||_/__/ // // //----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /** * @brief * @warning * @param[in] * @return */ //////////////////////////////////////////////////////////////////////////////// int Example_Function() { return -1; } //---------------------------------------------------------------- :Depreciated: // ___ _ _ _ // | \ ___ _ __ _ _ ___ __(_)__ _| |_ ___ __| | // | |) / -_) '_ \ '_/ -_) _| / _` | _/ -_) _` | // |___/\___| .__/_| \___\__|_\__,_|\__\___\__,_| // |_| // //----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /** * @brief * @warning * @param[in] * @return */ ////////////////////////////////////////////////////////////////////////////////
#!/bin/bash ################################################################################ # # Title: create_project # ################################################################################ # # Author: Nicholas Guthrie # Creation Date: 2-16-2011 # # Purpose: Automatically create diretory hiearchies with templates for projects. # # Usage: Run this from the base directory of the project. # Example: run from ~/Desktop/ # sh ~/create_project.sh # # Arguments: # "project" ..Project Title (Required) # What you want the project to be called # "program" ..Project Title (Required) # What you want the program to be name # # "c" || "cpp || "java"......Project Type (Required) # What type of program it is. # # "cs1" || "oop".............School Project # makes a project frop cop3502 # makes a project frop cop3330 # # "open".....................Open Files # Opens files in freemind & emacs after creation. # # "nocmake"..................No CMake # Prevents cmake creation for C & C++ projects. # ################################################################################ # To-Do ################################################################################ # # 1. Make & configure Java Template # 2. GUI ? # ################################################################################ # Global Variables ################################################################################ DATE=$(date +%Y-%m-%d) MONTH=$(date +%m-%d) HOUR=$(date +%H:%M:%S) DIRASSIGNMENT="/home/slayer/Desktop/assignment" DIRSLIDES="/home/slayer/Desktop/slides"## Project Name BOOL_NEXT_NAME="FALSE" BOOL_PROJECT_NAME="FALSE"## Program Name BOOL_NEXT_PROGRAM="FALSE" PROGRAMNAME="FALSE"## Programming Language BOOL_C="FALSE" BOOL_JAVA="FALSE" BOOL_CPP="FALSE"#### School Project Flags BOOL_CS1="FALSE" BOOL_OOP="FALSE" BOOL_NMG="FALSE"#### Build Configuration BOOL_CMAKE="TRUE" FORCE_NO_CMAKE="FALSE"## Documentation Settings BOOL_DOXYGEN="TRUE" BOOL_TREE="TRUE" BOOL_FREEMIND="TRUE"#### General BOOL_COPY_SLIDES="FALSE" BOOL_COPY_ASSIGNMENT="FALSE" ################################################################################ # FUNCTIONS ################################################################################ ########################### # Computer Science I # ########################### CreateProgrammingProject() { mkdir -p $PROJECTNAME cd $PROJECTNAME #create hiearchy echo " -Creating folder hiearchy." mkdir -p src #mkdir -p include #rarely used mkdir -p build mkdir -p bin mkdir -p doc ## Header based on Project Type if [ "$BOOL_C" = "TRUE" ]; then echo " -Building a C Project" BOOL_CMAKE="TRUE" echo " -Making Project ""$PROJECTNAME""" cp /home/slayer/templates/main.c src/"$PROGRAMNAME"."$EXT" elif [ "$BOOL_JAVA" = "TRUE" ]; then echo " -Building a Java Project" cp /home/slayer/templates/main.c src/"$PROGRAMNAME"."$EXT" elif [ "$BOOL_CPP" = "TRUE" ]; then echo " -Building a C++ Project" BOOL_CMAKE="TRUE" cp /home/slayer/templates/main.c src/"$PROGRAMNAME"."$EXT" fi echo " -Setting custom template info" SetTemplateInfo if [ "$BOOL_DOXYGEN" = "TRUE" ]; then echo " -Adding Doxygen" AddDoxygen fi ## FreeMind if [ "$BOOL_FREEMIND" = "TRUE" ]; then echo " -Adding FreeMind" AddFreeMind fi ## Tree if [ "$BOOL_TREE" = "TRUE" ]; then if [ "$BOOL_CMAKE" = "TRUE" ] && [ "$FORCE_NO_CMAKE" = "FALSE" ]; then echo "Files Added, Current Directory Structure (cmake to be added):" else echo "Files Added, Current Directory Structure:" fi tree sleep 2 fi ## Build CMAKE if [ "$BOOL_CMAKE" = "TRUE" ] && [ "$FORCE_NO_CMAKE" = "FALSE" ]; then BuildCmake fi } ########################### # FreeMind # ########################### AddFreeMind() { cp /home/slayer/templates/notes.mm doc sed -i "s|defaultdate|"$DATE"|g" doc/notes.mm sed -i "s|defaulttitle|"$1"|g" doc/notes.mm } ########################### # Doxygen # ########################### AddDoxygen() { cp /home/slayer/templates/Doxyfile build sed -i "s|defaultprojectname|"$PROJECTNAME"|g" build/Doxyfile } ########################### # Template Customization # ########################### SetTemplateInfo(){ if [ "$BOOL_CSI" = "TRUE" ]; then sed -i "s|defaultcoursename|COP3502C\ Compute\ Science\ I|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaultclassnumber|16173|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaultemail|nickguthrie@knights.ucf.edu|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaultsectionnumber|0001|g" src/"$PROGRAMNAME"."$EXT" elif [ "$BOOL_OOP" = "TRUE" ]; then sed -i "s|defaultcoursename|COP3330\ Object\ Oriented\Programming|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaultclassnumber|15881|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaultemail|nickguthrie@knights.ucf.edu|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaultsectionnumber|0001|g" src/"$PROGRAMNAME"."$EXT" else sed -i "s|defaultcoursename|none|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaultclassnumber|none|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaultemail|nickg4317@gmail.com|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaultsectionnumber|none|g" src/"$PROGRAMNAME"."$EXT" fi #add info to source file sed -i "s|defaultdate|"$DATE"|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaulttitle|"$PROGRAMNAME"|g" src/"$PROGRAMNAME"."$EXT" sed -i "s|defaultfilename|"$PROGRAMNAME".c|g" src/"$PROGRAMNAME"."$EXT" } ########################### # Build Cmake # ########################### BuildCmake() { echo " -Building CMake:" mkdir -p build/cmake cp /home/slayer/templates/CMakeLists.txt build/cmake cd build; mkdir Make; cd Make; cmake ../cmake/; cd ../..; } ################################################################################ # Main ################################################################################ if [ -z "$1" ]; then echo c = make new c project echo java = make new java project echo name = project name else ##Title Block clear echo "----- Starting New Programming Project Program -----" echo " Date = $DATE" echo " Month = $MONTH" echo " Time = $HOUR" echo " -Reading in Program Arguments" ## Read in Program Arguments for var in "$@" do if [ "$var" = "c" ] || [ "$var" = "cs1" ]; then BOOL_C="TRUE" EXT="c" if [ "var" = "cs1" ]; then BOOL_CS1="TRUE" fi elif [ "$var" = "java" ] || [ "$var" = "oop" ]; then BOOL_JAVA="TRUE" EXT="java" BOOL_DOXYGEN="FALSE" FORCE_NO_CMAKE="TRUE" if [ "$var" = "oop" ]; then BOOL_OOP="TRUE" fi elif [ "$var" = "cpp" ] || [ "$var" = "nmg" ]; then BOOL_CPP="TRUE" EXT="cpp" if [ "$var" = "nmg" ]; then BOOL_NMG="TRUE" fi elif [ "$var" = "proj" ] || [ "$var" = "project" ]; then BOOL_NEXT_NAME="TRUE" elif [ "$BOOL_NEXT_NAME" = "TRUE" ]; then PROJECTNAME=$var BOOL_NEXT_NAME="FALSE" BOOL_PROJECT_NAME="TRUE" elif [ "$var" = "prog" ] || [ "$var" = "program" ]; then BOOL_NEXT_PROGRAM="TRUE" elif [ "$BOOL_NEXT_PROGRAM" = "TRUE" ]; then PROGRAMNAME=$var BOOL_NEXT_PROGRAM="FALSE" elif [ "$var" = "nocmake" ]; then FORCE_NO_CMAKE="TRUE" elif [ "$var" = "open" ]; then BOOL_OPEN="TRUE" else echo "Argument not found" fi done echo " -Setting Program Name" if [ "$PROGRAMNAME" = "FALSE" ]; then PROGRAMNAME=$PROJECTNAME fi # Create Project if [ "$BOOL_PROJECT_NAME" = "TRUE" ]; then CreateProgrammingProject else echo "Please name a project, use flag proj then project name." fi if [ "$BOOL_OPEN" = "TRUE" ]; then ## Open File with Emacs emacs src/*.* & ## Open Freemind if exists if [ -f doc/notes.mm ]; then freemind doc/"notes.mm" & fi fi fi #END MAIN echo "----- Ending New Programming Project Program -----" ################################################################################ ## Archived Functions (not in use) ################################################################################ ########################### # Lecture Slides # ########################### CopySlides() { if [ -d $DIRASLIDES ] && [ -f $DIRSLIDES/* ]; then echo "\tfound slides" # Check for doc folder if ![ -e $1/doc ]; then mkdir doc fi # Move lecture slides to dir for i in $DIRSLIDES/* do BASENAME=$(basename $i) EXTENSION=${BASENAME##*.} mv -i "$i" "lecture.$EXTENSION" done ##else ##echo "\tdid not find slides" fi } ########################### # Assignment # ########################### CopyAssignment() { if [ -d $DIRASSIGNMENT ] && [ -n "$(ls -A $DIRASSIGNMENT)" ]; then echo "\tfound assignment" # Check for doc folder if ![ -d $DIR/doc ]; then mkdir $DIR/doc fi # Move lecture slides to dir for i in $DIRASSIGNMENT/* do BASENAME=$(basename $i) EXTENSION=${BASENAME##*.} mv -i "$i" "assignment.$EXTENSION" done ##else ##echo "\tdid not find asignment" fi if [ -f doc/assignment.pdf ]; then xpdf /doc/assignment.pdf & fi }