Repository: PistonDevelopers/glfw-rs (language: rust)

Issue:
Document linking instructions for building projects with glfw in the README
This would include:
- Manually or with Make, for Windows, Mac and Linux
- Using the FindGlfw.txt file with CMake (see #74)



Discussion / hints:

Fix patch:
diff --git a/.build.sh b/.build.sh
index bbd4082b..59618fd9 100755
--- a/.build.sh
+++ b/.build.sh
@@ -1,9 +1,5 @@
 #!/bin/sh
 
-mkdir build
-pushd build 1>&2
-cmake .. 1>&2
 make lib 1>&2 # cargo-lite wants stdout
-popd 1>&2
 echo "cargo-lite: artifacts"
 find build/lib -type f
diff --git a/.travis.yml b/.travis.yml
index 657e769b..479c5982 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -19,19 +19,12 @@ before_install:
 install:
   - sudo apt-get install rust-nightly
   - sudo apt-get install libXxf86vm-dev
-script:
-# Install glfw lib
   - git clone https://github.com/glfw/glfw.git
   - cd glfw
   - git checkout 3.0.3
-  - cmake -DBUILD_SHARED_LIBS=ON
+  - cmake -DBUILD_SHARED_LIBS=ON .
   - make
   - sudo make install
   - cd ..
-# Build glfw-rs
-  - mkdir build
-  - cd build
-  - cmake ..
+script:
   - make
-# Test glfw-rs install target
-  - sudo make install
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index 70b6313d..00000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,59 +0,0 @@
-# Copyright 2013 The GLFW-RS Developers. For a full listing of the authors,
-# refer to the AUTHORS file at the top-level directory of this distribution.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-cmake_minimum_required(VERSION 2.8)
-project(GLFW_RS NONE)
-
-option(GLFW_RS_BUILD_EXAMPLES "Build the example programs" ON)
-set(GLFW_RS_LIB_DIR ${PROJECT_BINARY_DIR}/lib
-    CACHE "Directory in which to build the library" PATH)
-set(GLFW_RS_EXAMPLE_DIR ${PROJECT_BINARY_DIR}/bin
-    CACHE "Directory in which to build the examples" PATH)
-
-find_program(RUSTC_COMPILER rustc)
-
-#-------------------------------------------------------------------------------
-# GLFW Linking
-#-------------------------------------------------------------------------------
-# See http://www.glfw.org/docs/latest/build.html#build_link_cmake_pkgconfig
-
-if(WIN32)
-    # Emulate pkg-config behaviour for windows
-    # set(GLFW_FOUND 1) - should check if the libs can actually be found
-    set(GLFW_LIBRARIES glfw3dll)
-    set(GLFW_LDFLAGS -lglfw3dll)
-    set(GLFW_STATIC_LIBRARIES glfw3)
-    set(GLFW_STATIC_LDFLAGS -lglfw3;-lopengl32;-lgdi32)
-else()
-    include(FindPkgConfig)
-    pkg_search_module(GLFW REQUIRED glfw3)
-endif()
-
-#-------------------------------------------------------------------------------
-# Add subdirectories
-#-------------------------------------------------------------------------------
-
-add_subdirectory(src)
-
-if(GLFW_RS_BUILD_EXAMPLES)
-    add_subdirectory(examples)
-endif()
-
-#-------------------------------------------------------------------------------
-# Add install target
-#-------------------------------------------------------------------------------
-
-file(GLOB GLFW_RS_INSTALL_FILES "${GLFW_RS_LIB_DIR}/*")
-install(FILES ${GLFW_RS_INSTALL_FILES} DESTINATION lib)
diff --git a/Makefile b/Makefile
new file mode 100644
index 00000000..9de081b3
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,39 @@
+# Copyright 2013 The GLFW-RS Developers. For a full listing of the authors,
+# refer to the AUTHORS file at the top-level directory of this distribution.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+all: examples
+
+tools:
+	mkdir -p build build/etc
+	rustc --out-dir=build/etc src/etc/link-args.rs
+
+lib: tools
+	mkdir -p build/lib
+	rustc --out-dir=build/lib --link-args="`./build/etc/link-args`" -O src/lib/lib.rs
+
+examples: lib
+	mkdir -p build/examples
+	rustc --out-dir=build/examples -L ./build/lib --link-args="`./build/etc/link-args`" src/examples/callbacks.rs
+	rustc --out-dir=build/examples -L ./build/lib --link-args="`./build/etc/link-args`" src/examples/clipboard.rs
+	rustc --out-dir=build/examples -L ./build/lib --link-args="`./build/etc/link-args`" src/examples/cursor.rs
+	rustc --out-dir=build/examples -L ./build/lib --link-args="`./build/etc/link-args`" src/examples/defaults.rs
+	rustc --out-dir=build/examples -L ./build/lib --link-args="`./build/etc/link-args`" src/examples/manual_init.rs
+	rustc --out-dir=build/examples -L ./build/lib --link-args="`./build/etc/link-args`" src/examples/modes.rs
+	rustc --out-dir=build/examples -L ./build/lib --link-args="`./build/etc/link-args`" src/examples/title.rs
+	rustc --out-dir=build/examples -L ./build/lib --link-args="`./build/etc/link-args`" src/examples/version.rs
+	rustc --out-dir=build/examples -L ./build/lib --link-args="`./build/etc/link-args`" src/examples/window.rs
+
+clean:
+	rm -rfv ./build
diff --git a/README.md b/README.md
index e1f61a70..719cadca 100644
--- a/README.md
+++ b/README.md
@@ -65,25 +65,6 @@ impl glfw::ErrorCallback for ErrorContext {
 
 ## Compilation
 
-You will need [CMake](http://www.cmake.org) to set up glfw-rs for building.
-
-You can use [cargo-lite](https://github.com/cmr/cargo-lite):
-
-~~~
-cargo-lite.py install
-~~~
-
-Or do it manually:
-
-~~~
-git clone https://github.com/bjz/glfw-rs.git
-cd glfw-rs
-mkdir build
-cd build
-cmake ..
-~~~
-
-
 ### Building everything
 
 ~~~
@@ -102,13 +83,6 @@ make lib
 make examples
 ~~~
 
-Or to build a single example:
-
-~~~
-make <example-name>
-~~~
-
-
 ## FAQ
 
 _I get lots of errors like: `undefined reference to 'glfwSetScrollCallback'`_
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
deleted file mode 100644
index 8c692728..00000000
--- a/examples/CMakeLists.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright 2013 The GLFW-RS Developers. For a full listing of the authors,
-# refer to the AUTHORS file at the top-level directory of this distribution.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-set(GLFW_RS_EXAMPLES
-    callbacks
-    clipboard
-    cursor
-    defaults
-    manual_init
-    modes
-    title
-    version
-    window
-)
-
-foreach(example ${GLFW_RS_EXAMPLES})
-    add_custom_target(
-        ${example} DEPENDS lib
-        COMMAND mkdir -p ${GLFW_RS_EXAMPLE_DIR} && ${RUSTC_COMPILER} -L ${GLFW_RS_LIB_DIR}
-            --link-args="${GLFW_STATIC_LDFLAGS}" --out-dir ${GLFW_RS_EXAMPLE_DIR}
-            ${CMAKE_CURRENT_SOURCE_DIR}/${example}.rs
-    )
-endforeach()
-
-add_custom_target(
-    examples ALL
-    DEPENDS lib ${GLFW_RS_EXAMPLES}
-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
deleted file mode 100644
index 18def47d..00000000
--- a/src/CMakeLists.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright 2013 The GLFW-RS Developers. For a full listing of the authors,
-# refer to the AUTHORS file at the top-level directory of this distribution.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-add_custom_target(
-    lib ALL 
-    COMMAND mkdir -p ${GLFW_RS_LIB_DIR} && ${RUSTC_COMPILER}
-        --link-args="${GLFW_STATIC_LDFLAGS}" --out-dir ${GLFW_RS_LIB_DIR}
-        ${CMAKE_CURRENT_SOURCE_DIR}/lib.rs
-)
diff --git a/src/etc/link-args.rs b/src/etc/link-args.rs
new file mode 100644
index 00000000..7e67a84e
--- /dev/null
+++ b/src/etc/link-args.rs
@@ -0,0 +1,47 @@
+// Copyright 2013 The GLFW-RS Developers. For a full listing of the authors,
+// refer to the AUTHORS file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//! Outputs the correct link args for the platform.
+//!
+//! Requires pkg-config on non-windows platforms
+//!
+//! See http://www.glfw.org/docs/latest/build.html
+
+#[cfg(target_os = "win32")]
+fn main() {
+    println!("-lglfw3 -lopengl32 -lgdi32");
+}
+
+#[cfg(target_os = "macos")]
+fn main() {
+    println!("-lglfw3 -framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation");
+}
+
+#[cfg(not(target_os = "win32"), not(target_os = "macos"))]
+fn main() {
+    use std::io::{IoError, FileNotFound, io_error};
+    use std::run::{Process, ProcessOptions};
+
+    io_error::cond.trap(|e| {
+        match e {
+            IoError { kind: FileNotFound, .. } => fail!("Failed to locate pkg-config in current environment."),
+            e => fail!("Unexpected error when locating locate pkg-config: {}", e.to_str()),
+        }
+    }).inside(|| {
+        println!("{}", Process::new("pkg-config", [~"--static", ~"--libs-only-l", ~"--libs-only-other", ~"glfw3"], ProcessOptions::new())
+            .expect("Failed to run pkg-config.")
+            .output().read_to_str());
+    });
+}
diff --git a/examples/callbacks.rs b/src/examples/callbacks.rs
similarity index 100%
rename from examples/callbacks.rs
rename to src/examples/callbacks.rs
diff --git a/examples/clipboard.rs b/src/examples/clipboard.rs
similarity index 100%
rename from examples/clipboard.rs
rename to src/examples/clipboard.rs
diff --git a/examples/cursor.rs b/src/examples/cursor.rs
similarity index 100%
rename from examples/cursor.rs
rename to src/examples/cursor.rs
diff --git a/examples/defaults.rs b/src/examples/defaults.rs
similarity index 100%
rename from examples/defaults.rs
rename to src/examples/defaults.rs
diff --git a/examples/manual_init.rs b/src/examples/manual_init.rs
similarity index 100%
rename from examples/manual_init.rs
rename to src/examples/manual_init.rs
diff --git a/examples/modes.rs b/src/examples/modes.rs
similarity index 100%
rename from examples/modes.rs
rename to src/examples/modes.rs
diff --git a/examples/title.rs b/src/examples/title.rs
similarity index 100%
rename from examples/title.rs
rename to src/examples/title.rs
diff --git a/examples/version.rs b/src/examples/version.rs
similarity index 100%
rename from examples/version.rs
rename to src/examples/version.rs
diff --git a/examples/window.rs b/src/examples/window.rs
similarity index 100%
rename from examples/window.rs
rename to src/examples/window.rs
diff --git a/src/callbacks.rs b/src/lib/callbacks.rs
similarity index 100%
rename from src/callbacks.rs
rename to src/lib/callbacks.rs
diff --git a/src/ffi.rs b/src/lib/ffi.rs
similarity index 100%
rename from src/ffi.rs
rename to src/lib/ffi.rs
diff --git a/src/lib.rs b/src/lib/lib.rs
similarity index 99%
rename from src/lib.rs
rename to src/lib/lib.rs
index df5ef923..19704e96 100644
--- a/src/lib.rs
+++ b/src/lib/lib.rs
@@ -13,9 +13,10 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#[crate_type = "lib"];
 #[crate_type = "rlib"];
 #[crate_type = "dylib"];
-#[crate_id = "github.com/bjz/glfw-rs#glfw:0.1"];
+#[crate_id = "github.com/bjz/glfw-rs#glfw-rs:0.1"];
 #[comment = "Bindings and wrapper functions for glfw3."];
 
 #[feature(globs)];


Test patch: