Skip to content

Build Copilot Windows

Bill Hamilton edited this page May 7, 2021 · 2 revisions

These instructions are for setting up your computer to build the Windows version of SolarPILOT's API (CoPILOT) from the C++ code repositories. The entire setup process should take between one and two hours. Once your computer is set up, it should take several minutes to build CoPILOT.

Note. If you are planning to build and use both SolarPILOT's GUI and API (CoPILOT), follow the SolarPILOT Windows build instructions, then skip to Step 6 on this page to build CoPILOT.

Overall Steps

  1. Follow steps 1 and 3 in the SolarPILOT Windows build instructions
  1. Download and install Visual Studio Community 2019.
  2. Download and install CMake 3.16.
  1. Clone CoPILOT code repositories.

  2. Set environment variables.

  3. Run CMake to generate SolarPILOT VS 2019 project files.

  4. Build SolarPILOT.dll.

  5. Test the build.

4. Clone SolarPILOT Code Repositories

The repositories required to build SolarPILOT's API are SSC and SolTrace:

The latest code is in the develop branch of each repository except for ssc, which uses the solarpilot-develop branch. Make sure you check out the solarpilot-develop branch after cloning ssc. If you are contributing code, you should work from the develop (or solarpilot-develop) branch. To build a specific version of SolarPILOT, you can check out a tag for that version.

  1. Create a parent folder to store the repositories, for example ...\solarpilot_dev.

  2. Clone each repository into the parent folder.

  3. Rename the 'ssc' folder to 'ssc-solarpilot'.

    ...\solarpilot_dev\ssc-solarpilot
    ...\solarpilot_dev\soltrace
    

5. Set Environment Variables

SolarPILOT's build tools use Windows environment variables to determine where the files it needs are stored on your computer.

Note. This step is only required the first time you build SolarPILOT, or if you move or rename repository folders.

  1. Close any open Command windows and Visual Studio if it is running.

  2. Open the Windows System Properties window, and on the Advanced tab, click Environment Variables.

  3. Under the user variables list, click New, and type values for the variable name and value for each item in the table below.

    For example, if you put the SSC repository in c:\solarpilot_dev\ssc-solarpilot, you would set the environment variable's name to "SSCDIR" and its value to "c:\solarpilot_dev\ssc-solarpilot" (you do not need to type the quotes).

    SSCDIR ...\solarpilot_dev\ssc-solarpilot
    CORETRACEDIR ...\solarpilot_dev\soltrace\coretrace
  4. Close the System Properties window.

7. Run CMake to Generate SolarPILOT VS 2019 Project Files

Note. This step is only required the first time you build SolarPILOT or if you have added or removed .cpp source files from the CMakeLists.txt file for SSC or coretrace.

  1. Use a text editor to create CMakeLists.txt in the SolarPILOT parent folder (...\solarpilot_dev\CMakeLists.txt in our example) with the following contents:

    cmake_minimum_required(VERSION 3.12)
    Project(solarpilot_api)
    
    add_subdirectory(ssc-solarpilot)
    add_subdirectory(soltrace/coretrace)
    

Note that there can only be one file with the name'CMakelists.txt' in the build directory, so if you have used this directory for another CMake build, you will need to temporarily rename or move the other existing 'CMakelists.txt' file.


Note. If you are planning to build both SolarPILOT GUI and API, you can create CMakeLists.txt with the following contents:

cmake_minimum_required(VERSION 3.12)

# Uncomment the project to build
#Project(solarpilot_ui)
Project(solarpilot_api)

if(${CMAKE_PROJECT_NAME} STREQUAL "solarpilot_ui")
    add_subdirectory(lk)
    add_subdirectory(wex)
endif()

add_subdirectory(ssc-solarpilot)
add_subdirectory(soltrace/coretrace)

if(${CMAKE_PROJECT_NAME} STREQUAL "solarpilot_ui")
    add_subdirectory(solarpilot)
endif()

  1. Create a folder named build-solarpilot in the SolarPILOT parent folder (...\solarpilot_dev\build-solarpilot). You should now have a directory structure for SolarPILOT that looks like this (for our example, this would be the contents of ...\solarpilot_dev):

    build-solarpilot
    soltrace
    ssc-solarpilot
    CMakeLists.txt
    
  2. Open a command window, and go to the build-solarpilot folder you created above.

  3. Run the following CMake command:

cmake -G "Visual Studio 16 2019" -DCMAKE_CONFIGURATION_TYPES="Debug;Release" -DCMAKE_SYSTEM_VERSION=10.0 -DCOPILOT_API=1 ..

When CMake finishes, you should see ...\build-solarpilot\solarpilot_api.sln file, with supporting files and a folder for each SolarPILOT repository in the build-solarpilot folder.

If you get build errors about missing files, check the environment variables to makes sure they are correctly named and point to the correct folders.

If you are running CMake to generate a new solution file after creating or removing .cpp files from the SSC or coretrace repositories, go to the ...\solarpilot_dev folder, and use the following commands from a command window or batch (.bat) file to clean up before running CMake:

rmdir /Q/S build-solarpilot
mkdir build-solarpilot
cd build-solarpilot
cmake -G "Visual Studio 16 2019" -DCMAKE_CONFIGURATION_TYPES="Debug;Release" -DCMAKE_SYSTEM_VERSION=10.0 -DCOPILOT_API=1 ..
  1. (Optional, but recommended): Add an .editorconfig file to the ...\solarpilot_dev folder to ensure your code is formatted consistently with project standards.

8. Build SolarPILOT.dll

  1. Start VS 2019 and open the ...\build-solarpilot\solarpilot_api.sln solution file.

  2. On the Build menu, click Batch Build and then Select All.

  3. Click Build.

Notes

  • As a post-build step, SolarPILOT's Dynamic-link library (.dll) will be copied here: ...solarpilot_dev', unless you have cloned the SolarPILOT's repository within the ...solarpilot_dev' directory, then the .dll will be copied here: ...solarpilot_dev\solarpilot\deploy\api.

  • The files for coretrace and SSC are in the ...solarpilot_dev\build-solarpilot folders for each repository, for example solarpilot_dev\build-solarpilot\ssc-solarpilot\Release.

  • SSC and coretrace each have their own repository in GitHub.com, so changes should be committed to each repository.

9. Test the build

  1. Download the SolarPILOT's repository directory: ...\solarpilot\deploy\api.

  2. Copy the solarpilot.dll into the api directory.

  3. Run test_script.py.