[CMake] CMake and shared|static/release|debug?

Littlefield, Tyler tyler at tysdomain.com
Tue Feb 4 17:41:55 EST 2014


Hello all:
I've tried this a few different ways and ran into issues. If someone 
wouldn't mind pointing out where I'm going wrong, I would appreciate it. 
(for example if there's a better way to do what I'm trying).

Thanks,

cmake_minimum_required(VERSION 2.8)
project(BLOXWEB)

#include additional modules
set(CMAKE_MODULE_PATH ${BLOXWEB_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

#set up our versioning info.
include(bloxwebVersion)
blox_version(MAJOR 0 MINOR 1 PATCH 0)

message("Configuring Bloxweb ${BLOXWEB_VERSION}.")
#set options
option(BUILD_STATIC "build static library" ON)
option(BUILD_SHARED "build shared library" OFF)
option(BUILD_DEBUG "debug build" ON)
option(BUILD_RELEASE "build release" OFF)

#locate our binary directories.
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib cache)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib cache)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin cache)

#compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic 
-Weffc++" cache)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1 -ggdb" cache)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -s" cache)
set(BLOX_SOURCE_FILES "src/header.cpp")

#source/include paths
include_directories(${BLOXWEB_SOURCE_DIR}/include)

if (BUILD_DEBUG AND BUILD_RELEASE)
message("You may not build debug and release at the same time.")
return(1)
endif()
if (BUILD_STATIC AND BUILD_SHARED)
message("You may not build static and shared at the same time.")
return(1)
endif()

if (BUILD_RELEASE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
add_definitions(-DNDEBUG)
endif()
if (BUILD_DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
endif()
if (BUILD_SHARED)
set(BUILD_SHARED_LIBS TRUE)
endif()

add_library("bloxweb" ${BLOX_SOURCE_FILES})

-- 
Take care,
Ty
http://tds-solutions.net
He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave.



More information about the CMake mailing list