rbmj/cmake_vxworks — pull request #1 by mcoffin (2012-10-17 20:45:41+00:00)
Title: Bugfixes and WPILib Find Module

I've fixed a couple bugs, one relating to whitespace in CMAKE_COMMAND. When you're using CMAKE_COMMAND like that, make sure to use and not ${CMAKE_COMMAND} or any whitespace in the path to cmake will mess it up. I added a configuration option that allows you to input the correct GCC version (allowing the toolchain to find libgcc correctly). Lastly, I moved the WPILib include and library paths into a cmake find module. This does add another line of code to the CMakeLists.txt file of the actual robot, but its the right way to do it since WPILib is really just an optional library. To use the WPILib find module, it would probably be smart to copy the "cmake" directory from the repository into the project's directory. Then, you have to tell CMake where to look for modules by doing a

set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}/cmake/Modules)

Then, later on, all one has to do is call

find_package(WPILib REQUIRED)

to ensure that WPILib is found and that the include directory and library variables are set. If it can't find WPILib, the required option will make it throw a cmake error.

Here is a simple CMakeLists.txt file that I've been using to test my toolchain with a very simple robot.
```cmake
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH "/Users/mcoffin/workspace/TestRobot/cmake/Modules")

# Project Setup
project(FRC)

# Find source files
include_directories(src)
file(GLOB_RECURSE FRC_SOURCES "src/*.cpp")

# Setup WPIlib
find_package(WPILib REQUIRED)
set(FRC_INCLUDES ${WPILib_INCLUDE_DIR})
set(FRC_LIBS ${WPILib_LIBRARY})

# Create Executable
add_executable(FRC_UserProgram ${FRC_SOURCES})
set_target_properties(FRC_UserProgram PROPERTIES
SUFFIX .out
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

# Link Libraries
target_link_libraries(FRC_UserProgram ${FRC_LIBS})
include_directories(${FRC_INCLUDES})
```