Install cmake config file in automake build
[openscop.git] / CMakeLists.txt
blobe4e1f12d3d3067700c64ec282cce3dbf4eedd409
1 cmake_minimum_required(VERSION 2.6)
4 set(PACKAGE_VERSION "0.8.4")
5 set(top_srcdir "${CMAKE_CURRENT_SOURCE_DIR}")
8 # User's settings - C Flags
10 #       set(release "TRUE")
11         set(release "FALSE")
13         # Release
14         if (release)
15                 set(CMAKE_C_FLAGS "-O3")
16         # Debug # valgrind --show-reachable=yes --leak-check=full -v exe
17         else()
18                 set(CMAKE_C_FLAGS "-O0 -g3")
19         endif()
21 # User's settings - General C Flags
22         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -std=c99 -pedantic")
25 # Build doxygen
26         find_package(Doxygen)
27         if(DOXYGEN_FOUND)
28                 configure_file("doc/Doxyfile.in" "Doxyfile")
29                 add_custom_target(
30                         doxygen
31                         ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
32                         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
33                         COMMENT "Generating API documentation with Doxygen" VERBATIM
34                 )
35         else()
36                 message (STATUS "Doxygen not found :( API documentation can not be built")
37         endif()
39 # Build documentation
40         find_program(texi2pdf_exe texi2pdf)
41         if(texi2pdf_exe)
42                 add_custom_target(
43                         doc
44                         ${texi2pdf_exe} ${CMAKE_CURRENT_SOURCE_DIR}/doc/openscop.texi --output=${CMAKE_CURRENT_BINARY_DIR}/openscop.pdf
45                         WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
46                         COMMENT "Generating documentation (pdf) (with texi2pdf)" VERBATIM
47                 )
48         else()
49                 message (STATUS "texi2pdf not found :( Documentation can not be built")
50         endif()
53 # GMP
54         message(STATUS "---")
55         find_library(gmp_LIB gmp)
56         if (gmp_LIB)
57                 message (STATUS "Library gmp found =) ${gmp_LIB}")
58                 add_definitions(-DOSL_GMP_IS_HERE)
59         else()
60                 message(STATUS "Library gmp not found :(")
61         endif()
63 # Include directories (to use #include <> instead of #include "")
65         # include/osl/scop.h
66         configure_file("include/osl/scop.h.in" "include/osl/scop.h")
67         include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
68         # osl
69         set(osl_INCLUDE "./include")
70         message(STATUS "Include osl = ${osl_INCLUDE}")
71         include_directories("${osl_INCLUDE}")
74 # Compiler log
75         message(STATUS "---")
76         message(STATUS "C compiler = ${CMAKE_C_COMPILER}")
77         if (release)
78                 message(STATUS "Mode Release")
79         else()
80                 message(STATUS "Mode Debug")
81         endif()
82         message(STATUS "C flags    = ${CMAKE_C_FLAGS}")
85 # files .c
86         file(
87                 GLOB_RECURSE
88                 sources
89                 source/*
90         )
91         
92 # Library
94         # Shared
95         add_library(
96                 osl
97                 SHARED
98                 ${sources}
99         )
100         if (gmp_LIB)
101                 target_link_libraries(osl ${gmp_LIB})
102         endif()
103         get_property(osl_lib_location TARGET osl PROPERTY LOCATION)
104         message(STATUS "Add osl library (shared) ${osl_lib_location}")
105         
106         # Static
107         add_library(
108                 osl_static
109                 STATIC
110                 ${sources}
111         )
112         set_target_properties(osl_static PROPERTIES OUTPUT_NAME osl)
113         if (gmp_LIB)
114                 target_link_libraries(osl_static ${gmp_LIB})
115         endif()
116         get_property(osl_static_lib_location TARGET osl_static PROPERTY LOCATION)
117         message(STATUS "Add osl library (static) ${osl_static_lib_location}")
120 # Executables & tests
122         enable_testing()
123         
124         file(
125                 GLOB_RECURSE
126                 scops
127                 tests/*.scop
128         )
129         
130         file(
131                 GLOB_RECURSE
132                 tests
133                 tests/*.c
134         )
136         message(STATUS "---")
137         
138         foreach(test_source ${tests})
139         
140                 string(REPLACE ".c" "" test_name ${test_source})
141                 string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/tests/" "test__" test_name ${test_name})
142                 
143                 message(STATUS "Add executable tests/${test_name}")
144                 add_executable(${test_name} "${test_source}")
145                 target_link_libraries(${test_name} osl_static)
146                 
147                 if (${test_name} STREQUAL "test__osl_test")
148                         foreach (scop ${scops})
149                                 string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/tests/" "" scop_name ${scop})
150                                 message(STATUS "- ${scop_name}")
151                                 add_test("${test_name}__${scop_name}" "${test_name}" "${scop}")
152                         endforeach()
153                 else()
154                         add_test("${test_name}" "${test_name}")
155                 endif()
156                 
157         endforeach()
158         
159         message(STATUS "---")
162 # Install
164         install(TARGETS osl LIBRARY DESTINATION lib)
165         install(TARGETS osl_static ARCHIVE DESTINATION lib)
166         install(DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.h")
167         install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/" DESTINATION include FILES_MATCHING PATTERN "*.h")
168         install(FILES osl-config.cmake DESTINATION lib/osl)
171 # Little help
173         message(STATUS "You can execute:")
174         message(STATUS "    make         # To compile osl library")
175         message(STATUS "    make test    # To execute tests")
176         message(STATUS "    make install # To install library, include and CMake module")
177         message(STATUS "                 # If you need root access:")
178         message(STATUS "                 #     sudo make install")
179         message(STATUS "                 #     su -c \"make install\"")
180         if(DOXYGEN_FOUND)
181                 message(STATUS "    make doxygen # To generate the Doxygen")
182         endif()
183         if(texi2pdf_exe)
184                 message(STATUS "    make doc     # To generate the documentation")
185         endif()
187         message(STATUS "---")