From 20ec8a0a35763d9dc466baa50333ebf6ebd46b3d Mon Sep 17 00:00:00 2001 From: Alexey Knyshev Date: Sun, 3 May 2015 12:01:17 +0300 Subject: [PATCH 1/2] [CMake] Support for reading env var KIUI_STATIC for building static lib At the first run on generation step cmake reads KIUI_STATIC env variable and if and only if KIUI_STATIC=1 enables static library build (sets KIUI_STATIC CMake variable enabled). After that user can manually set KIUI_STATIC variable from cmake-gui without overwriting it by following generation steps Signed-off-by: Alexey Knyshev --- src/CMakeLists.txt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d4d280..bb4598e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,9 +46,24 @@ if (MSVC) endif() endif () -option(${PROJECT_NAME}_STATIC "Build static lib instead dynamic one") +if (DEFINED ENV{${PROJECT_NAME}_STATIC}) + if ($ENV{${PROJECT_NAME}_STATIC}) + message(STATUS "env variable ${PROJECT_NAME}_STATIC is set") + if (NOT DEFINED ${PROJECT_NAME}_STATIC) + # enable static build from env only on first config start + option(${PROJECT_NAME}_STATIC "Build static lib instead dynamic one" ON) + endif () + endif () +endif() + +# if KIUI_STATIC env not set into 1 enable dynamic lib by default +if (NOT DEFINED ${PROJECT_NAME}_STATIC) + option(${PROJECT_NAME}_STATIC "Build static lib instead dynamic one") +endif () + set(LIB_TYPE SHARED) if (${PROJECT_NAME}_STATIC) + message(STATUS "Building kiui static lib") set(LIB_TYPE STATIC) if (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") #enable Position-independent code generation for static lib From 1855e0939ea2790ba4f77c09eaa3fc0dd25e7d55 Mon Sep 17 00:00:00 2001 From: Alexey Date: Sun, 3 May 2015 12:23:40 +0300 Subject: [PATCH 2/2] Travis static & dynamic lib builds --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e97628d..bd1899c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,11 @@ language: cpp compiler: - gcc - clang - + +env: + - KIUI_STATIC=0 + - KIUI_STATIC=1 + install: - sudo add-apt-repository ppa:smspillaz/cmake-2.8.12 -y - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y @@ -31,4 +35,4 @@ script: - sudo make install os: - - linux \ No newline at end of file + - linux