Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 16 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
cmake_minimum_required(VERSION 3.20)
cmake_policy(SET CMP0095 NEW)

if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(FATAL_ERROR "In-source builds are not allowed.
Please create a build directory and use `cmake ..` inside it.
NOTE: cmake will now create CMakeCache.txt and CMakeFiles/*.
You must delete them, or cmake will refuse to work.")
endif()

project(note_c)

# Automatically ignore CMake build directory.
Expand Down Expand Up @@ -47,37 +40,13 @@ target_sources(
${NOTE_C_SRC_DIR}/n_serial.c
${NOTE_C_SRC_DIR}/n_str.c
)
target_compile_options(
note_c
PRIVATE
-Wall
-Wextra
-Wpedantic
-Werror
-Og
-ggdb
PUBLIC
-m32
-mfpmath=sse
-msse2
)

target_include_directories(
note_c
PUBLIC ${NOTE_C_SRC_DIR}
)
target_link_directories(
note_c
PUBLIC
/lib32
/usr/lib32
/usr/lib/gcc/x86_64-linux-gnu/12/32
)
target_link_options(
note_c
PUBLIC
-m32
-Wl,-melf_i386
)

include(CompileOptions.cmake)

if(NOTE_C_LOW_MEM)
target_compile_definitions(
Expand Down Expand Up @@ -168,3 +137,16 @@ endif(NOTE_C_BUILD_TESTS)
if(NOTE_C_BUILD_DOCS)
add_subdirectory(docs)
endif(NOTE_C_BUILD_DOCS)

set_target_properties(note_c PROPERTIES PRIVATE_HEADER "${NOTE_C_SRC_DIR}/n_cjson.h")
set_target_properties(note_c PROPERTIES PUBLIC_HEADER "${NOTE_C_SRC_DIR}/note.h")

install(TARGETS note_c
EXPORT note_c
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/note-c
PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/note-c
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/note-c
)
24 changes: 24 additions & 0 deletions CompileOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

target_compile_options(
note_c
PRIVATE
-Wall
-Wextra
-Wpedantic
-Werror
-Wno-old-style-definition
)

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
target_compile_options(note_c PUBLIC -m32 -mfpmath=sse -msse2)
target_link_directories(note_c PUBLIC /lib32 /usr/lib32 /usr/lib/gcc/x86_64-linux-gnu/12/32)
target_link_options(note_c PUBLIC -m32 -Wl,-melf_i386)
endif()

if(CMAKE_BUILD_TYPE)
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TOLOWER)

if(CMAKE_BUILD_TYPE_TOLOWER STREQUAL "debug")
target_link_options(note_c PUBLIC -Og -ggdb)
endif()
endif()