1 cmake_minimum_required(VERSION 2.4)
7 # Load and parse version
10 file(READ VERSION sol_version)
11 set(rx "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
12 string(REGEX MATCH ${rx} sol_version ${sol_version})
13 string(LENGTH ${sol_version} tmp)
15 set(sol_version "0.1.0")
17 string(REGEX REPLACE ${rx} "\\1" sol_version_major ${sol_version})
18 string(REGEX REPLACE ${rx} "\\2" sol_version_minor ${sol_version})
19 string(REGEX REPLACE ${rx} "\\3" sol_version_patch ${sol_version})
31 # set global compiler flags
32 if (CMAKE_COMPILER_IS_GNUCXX)
35 -Wall -Werror -Wextra -Wno-unused-parameter -Wno-long-long
36 -pedantic -pedantic-errors
38 else (CMAKE_COMPILER_IS_GNUCXX)
41 endif (CMAKE_COMPILER_IS_GNUCXX)
43 foreach (flag ${CXX_FLAGS})
44 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
47 # set default build type (Debug)
48 if (NOT CMAKE_BUILD_TYPE)
49 set(CMAKE_BUILD_TYPE Debug)
50 endif (NOT CMAKE_BUILD_TYPE)
57 # global; continuosly updated when traversing modules
61 # append each file from input_list to output_list (using prefix sol_module)
62 macro (find_and_append output_list input_list)
63 # iterate over input_list
64 foreach (i ${input_list})
65 set(f "${sol_module}/${i}")
66 list(APPEND ${output_list} "${f}")
68 endmacro (find_and_append)
71 # specify header files
72 set(sol_header_list "")
74 find_and_append(sol_header_list "${ARGV}")
75 endmacro (sol_headers)
78 # specify source files
79 set(sol_source_list "")
81 find_and_append(sol_source_list "${ARGV}")
82 endmacro (sol_sources)
88 find_and_append(sol_test_list "${ARGV}")
92 # include module.cmake from each subdirectory
93 file(GLOB_RECURSE sol_module_list RELATIVE ${CMAKE_SOURCE_DIR} module.cmake)
94 foreach (module ${sol_module_list})
95 get_filename_component(sol_module ${module} PATH)
104 include_directories(.)
108 add_library(sol_static STATIC ${sol_source_list})
109 add_custom_target(static)
110 add_dependencies(static sol_static)
114 add_library(sol_shared SHARED ${sol_source_list})
115 set_target_properties(sol_shared PROPERTIES
116 VERSION ${sol_version}
118 DEFINE_SYMBOL SOL_DLL_EXPORT
120 add_custom_target(shared)
121 add_dependencies(shared sol_shared)
125 add_custom_target(lib)
126 add_dependencies(lib static shared)
134 foreach (test ${sol_test_list})
136 get_filename_component(test_path ${test} PATH)
137 get_filename_component(test_file ${test} NAME_WE)
138 string(REPLACE "/" "_" test_name ${test_path}/${test_file})
141 add_executable(${test_name} ${test})
142 target_link_libraries(${test_name} sol_shared)
143 add_test(${test_name} ${test_name})
152 install(TARGETS sol_shared sol_static
157 # currently cmake doesn't know how to install hierarchy, so we specify
158 # destination for each header separately
159 foreach (f ${sol_header_list})
160 get_filename_component(header_path ${f} PATH)
162 DESTINATION include/${header_path}
172 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simple C++ objects library")
173 set(CPACK_PACKAGE_VERSION_MAJOR ${sol_version_major})
174 set(CPACK_PACKAGE_VERSION_MINOR ${sol_version_minor})
175 set(CPACK_PACKAGE_VERSION_PATCH ${sol_version_patch})
176 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
177 set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README")
180 set(CPACK_SOURCE_PACKAGE_FILE_NAME "sol-${sol_version}")
181 set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2;ZIP")
182 set(CPACK_SOURCE_IGNORE_FILES ".git*;.*.swp")
185 set(sol_bin_suffix "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
186 set(CPACK_PACKAGE_FILE_NAME
187 "${CPACK_SOURCE_PACKAGE_FILE_NAME}-${sol_bin_suffix}"
189 set(CPACK_GENERATOR ${CPACK_SOURCE_GENERATOR})